熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

淺析JAVA常用JDBC連接數據庫的方法總結

2022-06-13   來源: JSP教程 

  JDBC連接DB

復制代碼 代碼如下:
ClassforName("ComibmdbjdbcnetDBDriver");  
String url="jdbc:db://dburl:port/DBname"  
cn = DriverManagergetConnection( url sUsr sPwd ); 
ClassforName("ComibmdbjdbcnetDBDriver");
String url="jdbc:db://dburl:port/DBname"
cn = DriverManagergetConnection( url sUsr sPwd );

  
JDBC連接Microsoft SQLServer(microsoft)

復制代碼 代碼如下:
ClassforName( "commicrosoftjdbcsqlserverSQLServerDriver" );  
cn = DriverManagergetConnection( "jdbc:microsoft:sqlserver://DBServerIP:;databaseName=master" sUsr sPwd );  
ClassforName( "commicrosoftjdbcsqlserverSQLServerDriver" );
cn = DriverManagergetConnection( "jdbc:microsoft:sqlserver://DBServerIP:;databaseName=master" sUsr sPwd );

  
JDBC連接Sybase(jconnjar)

復制代碼 代碼如下:
ClassforName( "comsybasejdbcjdbcSybDriver" );  
cn = DriverManagergetConnection( "jdbc:sybase:Tds:DBServerIP:" sUsr sPwd );  
ClassforName( "comsybasejdbcjdbcSybDriver" );
cn = DriverManagergetConnection( "jdbc:sybase:Tds:DBServerIP:" sUsr sPwd );

  
JDBC連接MySQL(mmmysqlbinjar)

復制代碼 代碼如下:
ClassforName( "orggjtmmmysqlDriver" );  
cn = DriverManagergetConnection( "jdbc:mysql://DBServerIP:/myDatabaseName" sUsr sPwd );  
ClassforName( "orggjtmmmysqlDriver" );
cn = DriverManagergetConnection( "jdbc:mysql://DBServerIP:/myDatabaseName" sUsr sPwd );

  
JDBC連接PostgreSQL(pgjdbcjar)

復制代碼 代碼如下:
ClassforName( "orgpostgresqlDriver" );  
cn = DriverManagergetConnection( "jdbc:postgresql://DBServerIP/myDatabaseName" sUsr sPwd );  
ClassforName( "orgpostgresqlDriver" );
cn = DriverManagergetConnection( "jdbc:postgresql://DBServerIP/myDatabaseName" sUsr sPwd );

  
JDBC連接Oracle(classesjar)

復制代碼 代碼如下:
ClassforName( "oraclejdbcdriverOracleDriver" );  
cn = DriverManagergetConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP::ORCL" sUsr sPwd );  
ClassforName( "oraclejdbcdriverOracleDriver" );
cn = DriverManagergetConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP::ORCL" sUsr sPwd );

  
JDBC連接ODBC

復制代碼 代碼如下:

  
ClassforName( "sunjdbcodbcJdbcOdbcDriver" );  
Connection cn = DriverManagergetConnection( "jdbc:odbc:" + sDsn sUsr sPwd );  


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19892.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.