JDBC Connection Strings for Popular RDBMS
Connecting to an RDBMS
The following code snippet illustrates how the connection parameters are used to retrieve a database connection.
1 |
try { |
2 |
Class.forName( "com.mysql.jdbc.Driver" ).newInstance(); //using MySQL JDBC Driver |
3 |
String url = "jdbc:mysql://hostname:port/database" ; //format of MySQL connection string |
4 |
conn = DriverManager.getConnection(url, "username" , "password" ); |
5 |
|
6 |
} catch (Exception e){...} |
7 |
finally { |
8 |
conn.close(); |
9 |
} |
JDBC Connection Strings
The following table lists the Connection Strings of some of the popular RDBMS.
DataBase Type | DriverClassName | Connection String |
---|---|---|
MySQL | com.mysql.jdbc.Driver | jdbc:mysql://<hostname>:<portNumber>/<databaseName>
Default host: 127.0.0.1 |
PostgreSql | org.postgresql.Driver | jdbc:postgresql://<hostname>:<portNumber>/<databaseName>
Default host: 127.0.0.1 |
SQLServer | com.microsoft.sqlserver.jdbc.SQLServerDriver | jdbc:sqlserver://<hostname>:<portNumber>;<databaseName>
Default host: 127.0.0.1 |
Oracle | oracle.jdbc.driver.OracleDriver | jdbc:oracle:thin:@<hostname>:<portNumber>:<databaseName>
Default host: 127.0.0.1 |
DB2 | COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver (DB2 JDBC Type 4 Driver) |
jdbc:db2://<hostname>:<portNumber>/<databaseName>
Default host: 127.0.0.1 |
DB2 (on As/400) |
com.ibm.as400.access.AS400JDBCDriver | jdbc:as400://<hostname>:<portNumber>/<databaseName>; |
Sybase | com.sybase.jdbc.SybDriver | jdbc:Sybase:Tds:<hostname>:<portNumber>/<databaseName> |
Sybase | net.sourceforge.jtds.jdbc.Driver (jTDS driver) |
jdbc:jtds:Sybase://<hostname>:<portNumber>/<databaseName> |
Sybase | com.sybase.jdbc2.jdbc.SybDriver (jdbc2 driver version) |
jdbc:Sybase:Tds:<hostname>:<port>?ServiceName=<databaseName> |
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。