This post lists JDBC database URLs for common databases so you can refer when programming database in Jjava.

You know, when working with a database system via JDBC, the following information is required for making connection to the database:

For reference, this article provides a summary of JDBC’s database connection URLs for the most common databases including MySQL, SQL Server, Oracle, PostgreSQL, Apache Derby (Java DB), SQLite and H2.

 

1. JDBC Database URL for MySQL 

           jdbc:mysql://[host][,failoverhost...][:port]/[database]

           [?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...

 

See more information about MySQL connection properties.

  

2. JDBC Database URL for SQL Server

 jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]

jdbc:sqlserver://localhost;integratedSecurity=true;

jdbc:sqlserver://localhost\\sqlexpress;integratedSecurity=true

jdbc:sqlserver://localhost\\sqlexpress;user=sa;password=secret

  

3. JDBC Database URL for Oracle

jdbc:oracle:<drivertype>:@<database>

jdbc:oracle:<drivertype>:<user>/<password>@<database>

where drivertype can be thin, oci or kprb.

jdbc:oracle:thin:@localhost:1521:testdb

jdbc:oracle:thin:root/secret@localhost:1521:testdb

jdbc:oracle:oci:@hoststring

jdbc:oracle:oci:@localhost:1521:testdb

jdbc:oracle:oci:root/secret@hoststring>

Jdbc:oracle:oci:root/secret@localhost:1521:testdb

 

4. JDBC Database URL for PostgreSQL

jdbc:postgresql:database

jdbc:postgresql://host/database

jdbc:postgresql://host:port/database

jdbc:postgresql:testdb

jdbc:postgresql://localhost/testdb

jdbc:postgresql://localhost:5432/testdb

 

 

5. JDBC Database URL for JavaDB (Apache Derby)

         jdbc:derby:[subsubprotocol:][databaseName][;attribute=value]*

where subsubprotocol can take one of the following values: directory (default), memory, classpath, and jar.

 

6. JDBC Database URL for SQLite

Because there is no official JDBC driver for SQLite from www.sqlite.org, the following information is applied for a SQLite JDBC driver provided by www.xerial.org.

jdbc:sqlite:database_file_path

 

Where database_file_path points to relative path or absolute path of a SQLite database file.

Syntax for in-memory SQLite database:

 

jdbc:sqlite::memory:

jdbc:sqlite:

 



 

NOTE: From JDBC 4.0, loading the driver class explicitly is no longer needed, so you don’t need to care about the driver class name.

 

7. JDBC Database URL for H2

Driver class name: org.h2.Driver

Database URLs for Embedded Mode:

 

Database URLs for In-Memory Mode:

 

Database URLs for Server Mode:

 

Related JDBC Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.