IT Community - Software Programming, Web Development and Technical Support

Connecting Database using Javascript

This is a discussion on Connecting Database using Javascript within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi, I want to connect a database from javascript code and to get the records from a table. Can anyone ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 12-25-2007, 09:53 PM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Connecting Database using Javascript

Hi,

I want to connect a database from javascript code and to get the records from a table. Can anyone give me an idea?
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-25-2007, 09:56 PM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 182
Balasubramanian.S is on a distinguished road
Default Re: Connecting Database using Javascript

Hi,

Hope this helps..

<html>
<head>
<SCRIPT LANGUAGE=javascript>

function ConDB()
{
var conn = new ActiveXObject("ADODB.Connection") ;
alert(conn);
var connectionstring="Data Source=localhost;Initial Catalog=Database1;User ID=ab;Password=123456;Provider=SQLOLEDB";
alert(connectionstring);
conn.Open(connectionstring);
alert(conn);
var rs = new ActiveXObject("ADODB.Recordset");
alert(rs);
rs.Open("SELECT * FROM users ", conn);
rs.MoveFirst
while(!rs.eof)
{
document.write(rs.fields(1));
rs.movenext;
}

rs.close;
conn.close;
}
</SCRIPT>
</head>
<body OnLoad="javascript:ConDB()">
</body>
</html>
__________________
S.Balasubramanian
Nothing is impossible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-04-2008, 01:17 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: Connecting Database using Javascript

<html>
<head>
<script type="text/javascript">
var conn = new ActiveXObject("ADODB.Connection")
var conn_str = ""
var dbHost = ""
var dbUser = ""
var dbPassword = ""
var dbProvider = ""
var dbDefault = ""
function getData()
{
dbHost = "localhost";
dbUser = "sa";
dbPassword = "";
dbProvider = "SQLOLEDB";
dbDefault = "master";
conn_str = "Provider="+dbProvider+";Data Source="+dbHost+"; User Id="+dbUser+"; password="+dbPassword+"; Initial Catalog="+dbDefault;
getDatabase();
}
function getDatabase()
{
try
{
conn.Open(conn_str)
alert(conn)
}
catch(e)
{
alert("Error creating Connection")
}
}
</script>
</head>
<body onload="getData()">
</body>
</html>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
types of object while connecting with mysql venkatbi PHP Programming 0 11-22-2007 05:51 AM
Connecting Database using PERL Murali Perl 1 08-17-2007 12:08 AM
Explain Connecting External Hardware to J2ME applications itbarota J2ME 2 08-06-2007 09:11 AM
Any idea about Connecting Windows Mobile to Wireless HID devices? itbarota Windows Mobile 0 07-23-2007 07:12 AM
connecting database nssukumar Flash Actionscript Programming 1 04-24-2007 11:14 PM


All times are GMT -7. The time now is 08:47 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0