Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Database connection with javaScript

How to connect to database with java script
0
maximyshka
Asked:
maximyshka
  • 2
  • 2
1 Solution
 
reginabCommented:
here are a couple of examples for you.

var DBConn = Server.CreateObject ('ADODB.Connection');
DBConn.Provider = "Microsoft.Jet.OLEDB.4.0"
DBConn.Open(Server.MapPath("PASS.mdb"))
if (DBConn.Errors.Count > 0)
         Response.Write("Error")

example:
=========================
<script>
     var conn = new ActiveXObject("ADODB.Connection") ;
     var connectionstring = "Provider=sqloledb; Data Source=itdev; Initial Catalog=pubs; User ID=sa;Password=yourpassword"
     conn.Open(connectionstring)
     var rs = new ActiveXObject("ADODB.Recordset")
     rs.Open("SELECT gif, description, page, location FROM menu1", conn)
     // Be aware that I am selecting from this table, but you need to pick your own table
     while(!rs.eof)
     {
              alert(rs(0));
              rs.movenext
    }
         
        rs.close
    conn.close      
</script>
0
 
maximyshkaAuthor Commented:
is it javascript. It looks like vb?
0
 
reginabCommented:
yes,
here maybe this is more clear

<script language=vbscript>
sub fnTest()

     set con = createobject("ADODB.connection")
     con.open "Provider=msdaora;user id=user;password=user;Data Source=Test"
     set rs =  createobject("ADODB.recordset")
     rs.Open "select sysdate from dual",con
     msgbox rs.Fields(0)
     
end sub
</script>
<BODY>
<input type=button value="Test" onclick="fnTest()">
</BODY>
</HTML>

0
 
maximyshkaAuthor Commented:
is there anyway to connect to database through odbc?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now