求一个ASP连接到ORACLE数据库的样本程序(200分)

2020-09-14 科技 125阅读
1、连入SQL*Plus
以system/manager用户登录,
SQL> conn system/manager

创建新的用户:如user1/pass1,赋予connect,resource权限。
SQL> grant connect,resource to user1 identified by pass1;

SQL> conn user1/pass1
SQL> create table test(a date);
Oracle数据库的实例名,本例:oradb
Oracle用户名,本例:user1
Oracle主机字符串:oradb

tnsnames.ora文件中

ORADB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.1.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = oradb)
)
)
2、在IIS默认WWW目录下创建test.asp,用notebook编辑,输入以下代码
<%
set conn=server.createobject("adodb.connection")
dns="Provider=OraOLEDB.Oracle.1;Persist Security Info=True;User ID=user1;Password=pass1;Data Source=oradb"
conn.Open dns

SQL="insert into test(a) values(sysdate)"
set rs=conn.execute(SQL)

set rs=nothing
conn.close
set conn=nothing
%>

<%
set conn=server.createobject("adodb.connection")
dns="Provider=OraOLEDB.Oracle.1;Persist Security Info=True;User ID=user1;Password=pass1;Data Source=oradb"
conn.Open dns

SQL="select to_char(a,'hh24:mi:ss') from test"
set rs=conn.execute(SQL)

do while (not rs.eof)
%>

<%=rs.fields(0).value%></font></td>
</tr>
<%
rs.movenext
loop

rs.close
set rs=nothing
conn.close
set conn=nothing
%>
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com