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

Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
karan
  • 482
  • 1
  • 8
  • 30

3 Answers3

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.

samanime
  • 25,408
  • 15
  • 90
  • 139
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.

Pv-Viana
  • 632
  • 7
  • 25
0

Simply you can use AJAX. To perform any action.

Onkar
  • 2,409
  • 2
  • 11
  • 14