Monday 23 September 2013

How to Connect to Oracle and retrieve data using ActiveX object in Javascript

<html>
<head>
<script>
function myFunction()
{
var con = new ActiveXObject('ADODB.Connection');
var rs = new ActiveXObject('ADODB.Recordset');
con.ConnectionString="Provider=MSDAORA.1;User ID=hr_man;Password=hr_man;Data Source=ORCL;Persist Security Info=False";
con.Open();
rs.Open(document.getElementById("sqlTxt").value,con);
var s="<table><tr>";
for(var i=0;i<rs.Fields.count;i++)
s+="<td>" + rs.Fields(i).Name + "</td>";
s+="</tr> <tr>";
while(!rs.EOF)
{
for(var i=0;i<rs.Fields.count;i++)
s+="<td>" + rs.Fields(i).Value + "</td>";
rs.MoveNext();
}
s+-"</tr></table>";
rs.Close();
con.close;
document.getElementById("outputSection").innerHTML=s;
}
</script>
</head>
<body>
<div id="inputSection">
<textArea id="sqlTxt"></textArea>
<input type="Button" id="btn" value="Execute" onclick="myFunction();"/>
</div>
<div id="outputSection">
</div>
</body>
 </html>

No comments: