JDBC连接各种数据库的方法【绝对经典】   Leave a comment

一、JDBC连接DB2

Java代码

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)

Java代码

Class.forName( “com.microsoft.jdbc.sqlserver.SQLServerDriver” );
cn = DriverManager.getConnection( “jdbc:microsoft:sqlserver://DBServerIP:1433;databaseName=master”, sUsr, sPwd );

三、JDBC连接Sybase(jconn2.jar)

Java代码

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)

Java代码

Class.forName( “org.gjt.mm.mysql.Driver” );
cn = DriverManager.getConnection( “jdbc:mysql://DBServerIP:3306/myDatabaseName”, sUsr, sPwd );

五、JDBC连接PostgreSQL(pgjdbc2.jar)

Java代码

Class.forName( “org.postgresql.Driver” );
cn = DriverManager.getConnection( “jdbc:postgresql://DBServerIP/myDatabaseName”, sUsr, sPwd );

六、JDBC连接Oracle(classes12.jar)

Java代码

Class.forName( “oracle.jdbc.driver.OracleDriver” );
cn = DriverManager.getConnection( “jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL”, sUsr, sPwd );

七、JDBC连接ODBC

Java代码

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

http://xp9802.iteye.com/blog/1254703

Posted 2011年11月25日 by gw8310 in JDBC

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: