Reputation: 482
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
Upvotes: 0
Views: 3436
Reputation: 642
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.
Upvotes: 0
Reputation: 26547
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.
Upvotes: 1