|
各种数据库的jdbc驱动下载网址(如果还有其他数据库的最新驱动下载网址,欢迎跟帖)
Mysql的JDBC驱动
http://www.mysql.com/products/connector/
Oracle的JDBC驱动
http://www.oracle.com/technetwork/database/application-development/index-099369.html
SQL Server
https://docs.microsoft.com/zh-cn/sql/connect/jdbc/microsoft-jdbc-driver-for-sql-server
SyBase
https://sourceforge.net/projects/jtds/files/
连接各种数据库的Java代码:
//以下sUsr变量表示登录数据库的用户名,sPwd为密码
//1. MySQL
Class.forName( "org.gjt.mm.mysql.Driver" );
Connection cn = DriverManager.getConnection( "jdbc:mysql://MyDbComputerNameOrIP:3306/myDatabaseName", sUsr, sPwd );
//2. Oracle
Class.forName( "oracle.jdbc.driver.OracleDriver" );
Connection cn = DriverManager.getConnection( "jdbc:oracle:thin:MyDbComputerNameOrIP:1521:ORCL", sUsr, sPwd );
//3. Sybase
Class.forName( "com.sybase.jdbc2.jdbc.SybDriver" );
Connection cn = DriverManager.getConnection( "jdbc:sybase:Tds:MyDbComputerNameOrIP:2638", sUsr, sPwd );
//(Default-Username/Password: "dba"/"sql")
//4. Microsoft SQLServer(http://jtds.sourceforge.net) ;
Class.forName( "net.sourceforge.jtds.jdbc.Driver" );
Connection cn = DriverManager.getConnection( "jdbc:jtds:sqlserver://MyDbComputerNameOrIP:1433/master", sUsr, sPwd );
//5. Microsoft SQLServer(http://www.microsoft.com) ;
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
Connection cn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://MyDbComputerNameOrIP:1433;databaseName=master", sUsr, sPwd );
//6. ODBC
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
Connection cn = DriverManager.getConnection( "jdbc:dbc:" + sDsn, sUsr, sPwd );
//7.DB2 Class.forName("com.ibm.db2.jdbc.net.DB2Driver");
String url="jdbc:db2://192.9.200.108:6789/SAMPLE";
Connection cn = DriverManager.getConnection( url, sUsr, sPwd );
程序猿的技术大观园:www.javathinker.net
|
|