系統環境:
1、操作系統:Windows xp
2、數據庫: Oracle 8i R2 (8.1.6) for NT 企業版
3、安裝路徑:C:\ORACLE
訪問方法:
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)
%>
<table border=1>
<tr><td><%=rs.fields(0).value%></font></td>
</tr>
<%
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
3、打開一個浏覽器窗口,輸入以下地址來查看運行結果,可以通過不斷的按F5鍵來刷新顯示結果
http://localhost/test.asp
總結:
利用以上代碼,可以省去創建ODBC的麻煩,並提高效率。