admin管理员组文章数量:1435859
I want to connect to Oracle database through JavaScript code.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Connecting to Oracle using JavaScript</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
var conObj = new ActiveXObject('ADODB.Connection');
var connectionString = "Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.119.132.175)(PORT=1521)))(CONNECT_DATA=(SID=orcl)(SERVER=DEDICATED)));User Id=mdm;Password=admin;"
conObj.Open(connectionString);
var rs = new ActiveXObject("ADODB.Recordset");
sql = "SELECT SYSDATE FROM DUAL"
rs.Open(sql, conObj);
alert(rs(0));
rs.close;
conObj.close;
//-->
</script>
</body>
</html>
I am getting ActiveXObject is not defined error ActiveXObject doesn't work for chrome browser it seems!
I want to connect to Oracle database through JavaScript code.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Connecting to Oracle using JavaScript</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
var conObj = new ActiveXObject('ADODB.Connection');
var connectionString = "Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.119.132.175)(PORT=1521)))(CONNECT_DATA=(SID=orcl)(SERVER=DEDICATED)));User Id=mdm;Password=admin;"
conObj.Open(connectionString);
var rs = new ActiveXObject("ADODB.Recordset");
sql = "SELECT SYSDATE FROM DUAL"
rs.Open(sql, conObj);
alert(rs(0));
rs.close;
conObj.close;
//-->
</script>
</body>
</html>
I am getting ActiveXObject is not defined error ActiveXObject doesn't work for chrome browser it seems!
Share Improve this question edited Aug 17, 2019 at 19:58 Dharman♦ 33.5k27 gold badges101 silver badges149 bronze badges asked Jul 18, 2018 at 12:37 Sairam YadavSairam Yadav 111 silver badge5 bronze badges 7- ActiveXObjects are basically deprecated. Those won't work (reliably) any more on modern browsers. – Cerbrus Commented Jul 18, 2018 at 12:40
- Yeah, i came to know that. is there any solution to connect with database through javascript? – Sairam Yadav Commented Jul 18, 2018 at 12:56
- With only JavaScript? I doubt it. – Cerbrus Commented Jul 18, 2018 at 12:57
- 2 Set up Oracle REST data services and connect to that. – MT0 Commented Jul 18, 2018 at 13:08
- 1 Are you really putting an full connection details including username and password into a script that is going to be sent your users? – MT0 Commented Jul 18, 2018 at 13:09
2 Answers
Reset to default 2There are several issues to take into account
- You need a driver in the client to deal with a database
- Since you want to connect from client your credentials must be present in client side.
- Your database port and url must be accessible from a browser
All of those issues implies that your database will be pletely exposed to anyone.
To avoid some of the risks, in my opinion the best approach (if you still want to avoid server code) is using web services provided by oracle. There are several examples in oracle docs using SOAP and REST, here an example using REST. Once you have the resource created, you call that resource using ajax. To prevent the restriction made by browser when you attempt to perform a cross origin ajax, you should set a Access-Control-Allow-Origin header in the database server. In this way you could access to the database without server code.
You can't connect directly from the browser, but you can connect using javascript in NodeJS, using the npm module "oracledb". I have been using it in production for about 3 years now -- it works really well.
本文标签: Connecting to Oracle database with JavaScriptStack Overflow
版权声明:本文标题:Connecting to Oracle database with JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745675092a2669802.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论