JDBC銜接數據庫的辦法匯總。本站提示廣大學習愛好者:(JDBC銜接數據庫的辦法匯總)文章只能為提供參考,不一定能成為您想要的結果。以下是JDBC銜接數據庫的辦法匯總正文
本文實例總結了JDBC銜接數據庫的辦法。分享給年夜家供年夜家參考,詳細以下:
1. MySQL(http://www.mysql.com)
Class.forName( "org.gjt.mm.mysql.Driver" ); cn = DriverManager.getConnection( "jdbc:mysql://MyDbComputerNameOrIP:3306/myDatabaseName", sUsr, sPwd );
2. PostgreSQL(http://www.de.postgresql.org)pgjdbc2.jar
Class.forName( "org.postgresql.Driver" ); cn = DriverManager.getConnection( "jdbc:postgresql://MyDbComputerNameOrIP/myDatabaseName", sUsr, sPwd );
3. Oracle(http://www.oracle.com/ip/deploy/database/oracle9i/)classes12.zip
Class.forName( "oracle.jdbc.driver.OracleDriver" ); cn = DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL", sUsr, sPwd );
4. Sybase(http://jtds.sourceforge.net)jconn2.jar
Class.forName( "com.sybase.jdbc2.jdbc.SybDriver" ); cn = DriverManager.getConnection( "jdbc:sybase:Tds:MyDbComputerNameOrIP:2638", sUsr, sPwd ); //(Default-Username/Password: "dba"/"sql")
5. Microsoft SQLServer(http://jtds.sourceforge.net)
Class.forName( "net.sourceforge.jtds.jdbc.Driver" ); cn = DriverManager.getConnection( "jdbc:jtds:sqlserver://MyDbComputerNameOrIP:1433/master", sUsr, sPwd );
6. Microsoft SQLServer(http://www.microsoft.com)
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" ); cn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://MyDbComputerNameOrIP:1433;databaseName=master", sUsr, sPwd );
7.JDBC-ODBC(非數據源方法)
new sun.jdbc.odbc.JdbcOdbcDriver(); Connection conn = DriverManager.getConnection("jdbc:odbc:driver={sql server};server=.;database=pubs;user=sa;pwd=");
8. ODBC (通俗數據源方法)
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ); Connection cn = DriverManager.getConnection( "jdbc:odbc:" + sDsn, sUsr, sPwd );
9.DB2
Class.forName("com.ibm.db2.jdbc.net.DB2Driver"); String url="jdbc:db2://192.9.200.108:6789/SAMPLE" cn = DriverManager.getConnection( url, sUsr, sPwd );
願望本文所述對年夜家java法式設計有所贊助。