0

Is there any possible way to excute the select sql query using javascript or jquery.

for ex : i want to run the query like

select * from abc

So, can I excute this query using javascript or jquery.

If yes then please guide me. If no then please give me the reason.

ThankYou

2
  • see this Commented Jun 22, 2017 at 13:59
  • Simple answer, nope Commented Jun 22, 2017 at 14:01

3 Answers 3

1

From browser-side JavaScript, no, not really.

You can use server-side Node.js JavaScript, but you'll want to do the query directly from the server with some language (literally any server-side language).

Running queries from the client is not only technically difficult, but it's also a huge security risk as your users could run any query.

Sign up to request clarification or add additional context in comments.

Comments

0

You shouldn´t use client javascript to access databases, mostly because security.

but a example: ( from How to connect to SQL Server database from JavaScript in the browser?)

var connection = new ActiveXObject("ADODB.Connection") ;

var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";

connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");

rs.Open("SELECT * FROM table", connection);
rs.MoveFirst
while(!rs.eof)
{
   document.write(rs.fields(1));
   rs.movenext;
}

rs.close;
connection.close; 

Better way is call ajax function to a code behind method and query from there.

1 Comment

Note that ActiveXObject is IE only. Even IE's successor, Edge, doesn't support it any more.
0

Simply you can use AJAX. To perform any action.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.