How to connect to a Pervasive Database using javascript?

How can you connect database using javascript in HTML page?

  • Answer:

    You can't connect directly from a browser to the database, as the browser doesn't have access. Even if you could, you shouldn't: If your Javascript sends SQL statements to the database, there is nothing stopping a random visitor from having fun by changing your SQL to "drop table", and your entire database is gone. What you do is setting up a server side web service (using PHP, Java servlets, Ruby on Rails or whatever) that accepts a URL, converts it to a DB query and returns the result as JSON. The primary thing from a security standpoint is that you never insert a string from the web into the SQL without validating it first. As an example, you could have something like this: --- browser javascript (using jQuery) --- $.getJSON("/productDetail.json?productId=123", function (data) { // do something with the data }); --- server (using Java servlet) --- void doProductDetail(HttpServletRequest req, HttpServletResponse res) { int productId = Integer.parseInt(...); // get product ID from query param String sql = ...; // generate the SQL String json = ...; // execute query, convert result to JSON res.write(json); // send to browser }

wiki.answers.com Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.