DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> 淺析JAVA常用JDBC連接數據庫的方法總結
淺析JAVA常用JDBC連接數據庫的方法總結
編輯:JavaScript綜合知識     

一、JDBC連接DB2

復制代碼 代碼如下:
Class.forName("Com.ibm.db2.jdbc.net.DB2Driver");  
String url="jdbc:db2://dburl:port/DBname"  
cn = DriverManager.getConnection( url, sUsr, sPwd ); 
Class.forName("Com.ibm.db2.jdbc.net.DB2Driver");
String url="jdbc:db2://dburl:port/DBname"
cn = DriverManager.getConnection( url, sUsr, sPwd );


二、JDBC連接Microsoft SQLServer(microsoft)

復制代碼 代碼如下:
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );  
cn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://DBServerIP:1433;databaseName=master", sUsr, sPwd );  
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
cn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://DBServerIP:1433;databaseName=master", sUsr, sPwd );


三、JDBC連接Sybase(jconn2.jar)

復制代碼 代碼如下:
Class.forName( "com.sybase.jdbc2.jdbc.SybDriver" );  
cn = DriverManager.getConnection( "jdbc:sybase:Tds:DBServerIP:2638", sUsr, sPwd );  
Class.forName( "com.sybase.jdbc2.jdbc.SybDriver" );
cn = DriverManager.getConnection( "jdbc:sybase:Tds:DBServerIP:2638", sUsr, sPwd );


四、JDBC連接MySQL(mm.mysql-3.0.2-bin.jar)

復制代碼 代碼如下:
Class.forName( "org.gjt.mm.mysql.Driver" );  
cn = DriverManager.getConnection( "jdbc:mysql://DBServerIP:3306/myDatabaseName", sUsr, sPwd );  
Class.forName( "org.gjt.mm.mysql.Driver" );
cn = DriverManager.getConnection( "jdbc:mysql://DBServerIP:3306/myDatabaseName", sUsr, sPwd );


五、JDBC連接PostgreSQL(pgjdbc2.jar)

復制代碼 代碼如下:
Class.forName( "org.postgresql.Driver" );  
cn = DriverManager.getConnection( "jdbc:postgresql://DBServerIP/myDatabaseName", sUsr, sPwd );  
Class.forName( "org.postgresql.Driver" );
cn = DriverManager.getConnection( "jdbc:postgresql://DBServerIP/myDatabaseName", sUsr, sPwd );


六、JDBC連接Oracle(classes12.jar)

復制代碼 代碼如下:
Class.forName( "oracle.jdbc.driver.OracleDriver" );  
cn = DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL", sUsr, sPwd );  
Class.forName( "oracle.jdbc.driver.OracleDriver" );
cn = DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL", sUsr, sPwd );


七、JDBC連接ODBC

復制代碼 代碼如下:


Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );  
Connection cn = DriverManager.getConnection( "jdbc:odbc:" + sDsn, sUsr, sPwd );  

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved