JDBC Connection Strings for Popular RDBMS

Source: Internet
Author: User
Tags db2 mysql connection string postgresql sybase

Connecting to an RDBMS

The following code snippet illustrates how the connection parameters is 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
port# 3306

PostgreSql Org.postgresql.Driver jdbc:postgresql://<hostname>:<portnumber>/ <databaseName>

Default host:127.0.0.1
port# 5432

Sql server Com.microsoft.sqlserver.jdbc.SQLServerDriver jdbc:sqlserver://<hostname>:<portnumber>; <databaseName>

Default host:127.0.0.1
port# 1433

Oracle Oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@<hostname>:<portnumber>:< DatabaseName>

Default host:127.0.0.1
port# 1521

DB2 COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver
(DB2 JDBC Type 4 Driver)
jdbc:db2://<hostname>:<portnumber>/< DatabaseName>

Default host:127.0.0.1
port# 50000

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>

src:http://examples.javacodegeeks.com/enterprise-java/sql-enterprise-java/jdbc-connection-strings-popular-rdbms/

JDBC Connection Strings for Popular RDBMS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.