java jdbc url 不一樣數據庫



1.Oracle數據庫

Class.forName("oracle.jdbc.driver.OracleDriver" ).newInstance() ;

String url = "jdbc : oracle :thin: @ localhost:1521:rcle " ;

String user = "test " ;

String password = "test " ;

Connection conn = DriverManager.getConnection(url, user, password ) ;html

注:java

這麼寫是服務名:mysql

jdbc:oracle:thin:@192.168.0.10:1521/eduCode2013DB
web

這麼寫是SIDsql

jdbc:oracle:thin:@192.168.0.10:1521:eduCode2013DB數據庫



2.DB2數據庫

Class.forName("com.ibm.db2.jdbc.app.DB2Driver" ).newInstance();

String url = "jdbc:db2://localhost:5000/testDB";

String user = "admin";

String password = "test";

Connection conn = DriverManager.getConnection ( url, user, password ) ;



3.SQL Server數據庫

Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" ) .newInstance() ;

String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDB ";

String user = "sa";

String password = "test";

Connection conn = DriverManager.getConnection(url, user, password ) ;



4. Sybase數據庫

Class.forName( "com.sybase.jdbc.SybDriver" ).newInstance();

String url = "jdbc:sybase:Tds:localhost:5007/testDB";

Properties sysProps = System.getProperties() ;

sysProps.put("user", "userid";

sysProps.put("password", "user_password" );

Connection conn = DriverManager.getConnection(url, sysProps ) ;



5.Informix數據庫

Class.forName("com.infoxmix.jdbc.IfxDriver".newInstance();

String url = "jdbc:infoxmix-sqli://localhost:1533/testDB:INFORMIXSERVER=myserver;user=testuser;password=testpassword";

Connection conn = DriverManager.getConnection(url);

6.MySQL數據庫



Class.forName("org.gjt.mm.mysql.Driver").newInstance();

String url = "jdbc:mysql://localhost/testDB?user=testuser&password=testpassword&useUnicode=true&characterEncoding=GB2312";

Connection conn = DriverManager.getConnection(url);



7.PostgreSQL數據庫

Class.forName("org.postgresql.Driver").newInstance();

String url = "jdbc:postgresql://localhost/testDB";

String user = "myuser";

String password = "test";

Connection conn = DriverManager.getConnection(url, user, password ) ;


下載文件 

你須要Java SDK、 Hibernate包、Ant包、和JDBC Driver。

一、Hibernate包下載地址:
http://prdownloads.sourceforge.n ... =date&sort=desc 

二、Ant包下載地址:
http://apache.130th.net/ant/binaries/apache-ant-1.6.1-bin.zip 

三、 JDBC Driver要根據你用的database來定,通常database官方網站上都會有。Hibernate支持經常使用的database,好比 MySQL, Oracle, PostgreSQL, 和MS-SQL Server。這些數據庫都有JDBC Driver: 

Oracle JDBC Driver下載地址(下載前必須贊成Oracle協議書)
http://otn.oracle.com/software/h ... tdocs/jdbc9201.html 

MySQL JDBC Driver下載地址
http://dev.mysql.com/downloads/connector/j/3.0.html 

PostgreSQL JDBC Driver下載地址
http://jdbc.postgresql.org/download.html 

MS-SQL Server JDBC Driver下載地址
http://www.microsoft.com/downloa ... &displaylang=enapache

相關文章
相關標籤/搜索