JavaScript operates on the Oracle database example
- 2020-05-12 02:12:27
- OfStack
I am still a newbie in the IT world. I have not been working for a long time. However, with my eager to learn and my never-ending learning pace, I have also gained a lot in programming
JavaScript has to call the server-side code (C# or JAVA) via AJAX to interact with the database, but it was only recently discovered that JavaScript can interact directly with the database... The following is a simple example of loading data from the database into the interface (about JS operation data knowledge if you have any good advice I hope you can stay, we learn from each other, progress together)~~
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript">
function getData()
{
// define SQL statements
var sql = "select obj_id,obj_caption from mw_sys.mwt_om_obj where rownum<5000";
// Create a new database connection object and a data set access object
var ConnDB = new ActiveXObject("ADODB.Connection");
ConnDB.open("Provider=MSDAORA.1;Password=app;User ID=mw_app;Data Source=pms;Persist Security Info=True");
var rs = new ActiveXObject("ADODB.Recordset");
rs.ActiveConnection = ConnDB;
rs.Open(sql);
// traverse
var s;
var rownum=0;
var shtml="<table cellpadding=0; cellspacing=0; style='border:solid 1px gray;'><thead><td style='border:solid 1px gray; text-align:center;'> The line Numbers </td><td style='border:solid 1px gray; text-align:center;'> The text ID No. </td><td style='border:solid 1px gray;'> Professional code </td><tbody>";
while(!rs.EOF)
{
shtml+="<tr><td style='border:solid 1px gray; text-align:center;'>";
shtml+=rownum+1;
shtml+="</td>";
for(i = 0;i<rs.Fields.Count;++i)
{
shtml+="<td style='border:solid 1px gray; background-color:yellow;'>";
shtml+=rs.Fields(i).value==null?" ":rs.Fields(i).value;
shtml+="</td>";
}
shtml+="</tr>";
rownum++;
if(rownum==1000)
break;
rs.MoveNext();
}
shtml+="</tbody></table>";
rs.close();
ConnDB.close();
document.getElementById("data").innerHTML=shtml;
}
</script>
</HEAD>
<BODY>
<input type="button" value="Table" onclick="getData()"/>
<div id="data">
</div>
</BODY>
</HTML>