answersLogoWhite

0


Best 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
}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

you can use jquery to make a Async, or Sync call to a page method [web method] (in the code behind) which has access to a database.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Do can connect database with javascript?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you connect oracle database in javascript?

By using ODBC


How do you link css to a database?

CSS, Cascading Style Sheet, is a formatting tool. It can not connect to a database. You need to use a programming language like C#, JavaScript, or PHP.


How do you connect to a database and table using ADODB?

How do you connect to a database and table using ADODB?


How do you connection database in HTML using javascript?

Connection Database can be established using language such as Java. For that you need to create an object of Connection type.


Java projects which does not use database?

JavaScript is a computer language that is mostly used in web browsers. An example of JavaScript project without a database is called a login session, this requires a lot of hard coding and requires a lot of multiple ID comparison.


How do you connect to a database using unix command?

There isn't a generic Unix command to connect to a database. The actual commands are based on the database package you are using, such as Oracle, SyBase, etc. They each have their own commands for gaining access to the database.


Can you create a database with only a form?

Yes , you can create a database using a form . But you have to do two things First make a form in html or jsp whatever you like. Then Connect the form to database using java database connectivity.Yes, we can create database with a form. First create a form using html or jsp then we can connect it to database using JDBC.


How do you connect databases?

TO connect database two things are require: 1) JDBC driver 2) ognl.jar Using these two we can create a database connection.


How do you create a form in database?

To create an online form and database, you could learn PHP, MYSQL, HTML and Javascript or alternatively try something like www.recs4free.com. This will do most of the work for you.


Difference between JSP and JAVA Script?

Hi, 1. JSP is a server side scripting while Javascript is as client side scripting language. 2. JSP also connects with database to fetch up the records from the database while javascript can be used for validate the code on client side.


How do you connect oracle to java?

Connecting to Java from within a Oracle database is not possible. However, if you want to connect to an Oracle database from Java, you can use JDBC for the same. JDBC stands for Java DataBase Connectivity which is the framework that helps Java applications connect to databases like Oracle


How do you connect an postgress sql database in C?

Carefully.