熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

各種數據庫連接代碼

2022-06-13   來源: Java核心技術 

  MS Access數據庫連接
  用DSN連接並且沒有用戶名和密碼
  
  <%
  set conn = ServerCreateObject(ADODBConnection)
  connopen YourDSNName
  %>
  
  用DSN連接並且有用戶名和密碼
  
  <%
  set conn = ServerCreateObject(ADODBConnection)
  connopen YourDSNNameusernamepassword
  %>
  
  用實際的數據庫絕對路徑連接
  
  <%
  Set conn = ServerCreateObject(ADODBConnection)
  Strconn=DRIVER={Microsoft Access Driver (*mdb)};
  Strconn=Strconn & DBQ=e:\yanhang\databasemdb
  connOpen Strconn
  %>
  
  用實際的數據庫相對路徑連接
  
  <%
  Set conn = ServerCreateObject(ADODBConnection)
  Strconn=DRIVER={Microsoft Access Driver (*mdb)};
  Strconn=Strconn & DBQ= & ServerMapPath(/database/yanhangmdb)
  connOpen Strconn
  %>
  
  MS SQL Server數據庫連接
  
  用DSN連接
  
  <%
  set conn = ServerCreateObject(ADODBConnection)
  connopen DSN=MyDSN;UID=user;PWD=password;DATABASE=databasename
  %>
  
  不用DSN連接
  
  <%
  Set conn = ServerCreateObject(ADODBConnection)
  DSNtemp=DRIVER={SQL Server};SERVER=ServerName;UID=USER;PWD=password;DATABASE=databasename
  connopen DSNtemp
  %>
  
  FoxPro數據庫連接
  
  <%
  Set Conn = ServerCreateObject(nnection)
  ConnStr= Driver=Microsoft Visual Foxpro Driver; UID=userID;SourceType=DBC;SourceDB=C:\yanhang\databasedbc
  ConnOpen ConnStr
  %>
  
  Oracle數據庫連接
  
  <%
  set conn=servercreateobject(nnection)
  conncursorlocation=adUseClient
  DSNTemp=Provider=MSDAORA;Password=xxxxx;User ID=yanhang;Data Source=xxxworld
  connopen DSNtemp
  %>

From:http://tw.wingwit.com/Article/program/Java/hx/201311/26239.html
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.