JDBC Driver Connection URL strings

(Last Updated On: February 14, 2018)

Introduction

Ever wanted to connect to a relational database using Java and didn’t know the URL connection string?

Then, this article is surely going to help you from now on.

Oracle

The JDBC connection properties look as follows:

JDBC Driver oracle.jdbc.OracleDriver
JDBC Url jdbc:oracle:thin:@localhost:1521/orclpdb1
Hibernate Dialect org.hibernate.dialect.Oracle12cDialect

And, if you want to connect using a JDBC DataSource, this is what you need to use:

OracleDataSource dataSource = new OracleDataSource();
dataSource.setDatabaseName("high_performance_java_persistence");
dataSource.setURL("jdbc:oracle:thin:@localhost:1521/orclpdb1");
dataSource.setUser("oracle");
dataSource.setPassword("admin");

MySQL

The JDBC connection properties look as follows:

JDBC Driver com.mysql.jdbc.Driver
JDBC Url jdbc:mysql://localhost/high_performance_java_persistence
Hibernate Dialect org.hibernate.dialect.MySQL57Dialect

And, if you want to connect using a JDBC DataSource, this is what you need to use:

MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setURL( 
    "jdbc:mysql://localhost/high_performance_java_persistence"
);
dataSource.setUser("mysql");
dataSource.setPassword("admin");

PostgreSQL

The JDBC connection properties look as follows:

JDBC Driver org.postgresql.Driver
JDBC Url jdbc:postgresql://localhost/high_performance_java_persistence
Hibernate Dialect org.hibernate.dialect.PostgreSQL95Dialect

And, if you want to connect using a JDBC DataSource, this is what you need to use:

PGSimpleDataSource dataSource = new PGSimpleDataSource();
dataSource.setDatabaseName("high_performance_java_persistence");
dataSource.setServerName("localhost");
dataSource.setUser("postgres");
dataSource.setPassword("admin");

SQL Server

The JDBC connection properties look as follows:

JDBC Driver com.microsoft.sqlserver.jdbc.SQLServerDriver
JDBC Url jdbc:sqlserver://localhost;instance=SQLEXPRESS;
databaseName=high_performance_java_persistence
Hibernate Dialect org.hibernate.dialect.SQLServer2012Dialect

And, if you want to connect using a JDBC DataSource, this is what you need to use:

SQLServerDataSource dataSource = new SQLServerDataSource();
dataSource.setURL(
    "jdbc:sqlserver://localhost;instance=SQLEXPRESS;" +
    "databaseName=high_performance_java_persistence;" 
);
dataSource.setUser("sa");
dataSource.setPassword("adm1n");

MariaDB

The JDBC connection properties look as follows:

JDBC Driver org.mariadb.jdbc.Driver
JDBC Url jdbc:mariadb://127.0.0.1/high_performance_java_persistence
Hibernate Dialect org.hibernate.dialect.MariaDB53Dialect

Db2 Express-C

The JDBC connection properties look as follows:

JDBC Driver com.ibm.db2.jcc.DB2Driver
JDBC Url jdbc:db2://127.0.0.1:50000/hpjp
Hibernate Dialect org.hibernate.dialect.DB2Dialect

SAP HANA

The JDBC connection properties look as follows:

JDBC Driver com.sap.db.jdbc.Driver
JDBC Url jdbc:sap://localhost:30015/
Hibernate Dialect org.hibernate.dialect.HANAColumnStoreDialect

Informix

The JDBC connection properties look as follows:

JDBC Driver com.informix.jdbc.IfxDriver
JDBC Url jdbc:informix-sqli://127.0.0.1:9088/sysuser:INFORMIXSERVER=hpjp
Hibernate Dialect org.hibernate.dialect.InformixDialect

HSQLDB

The JDBC connection properties look as follows:

JDBC Driver org.hsqldb.jdbc.JDBCDriver
JDBC Url jdbc:hsqldb:mem:test
Hibernate Dialect org.hibernate.dialect.HSQLDialect

And, if you want to connect using a JDBC DataSource, this is what you need to use:

JDBCDataSource dataSource = new JDBCDataSource();
dataSource.setUrl("jdbc:hsqldb:mem:test");
dataSource.setUser("sa");
dataSource.setPassword("");

H2

The JDBC connection properties look as follows:

JDBC Driver org.h2.Driver
JDBC Url jdbc:h2:mem:high_performance_java_persistence
Hibernate Dialect org.hibernate.dialect.H2Dialect

Derby

The JDBC connection properties look as follows:

JDBC Driver org.apache.derby.jdbc.EmbeddedDriver
JDBC Url jdbc:derby:target/tmp/derby/hpjp;databaseName=test;create=true
Hibernate Dialect org.hibernate.dialect.DerbyTenSevenDialect

That’s it!

If you enjoyed this article, I bet you are going to love my Book and Video Courses as well.

Conclusion

Knowing the JDBC Driver Connection URL strings is mandatory if you want to connect to a relational database system from a Java application.

If there is a database system that I forgot to add, add a comment and I’ll update the article.

Subscribe to our Newsletter

* indicates required
10 000 readers have found this blog worth following!

If you subscribe to my newsletter, you'll get:
  • A free sample of my Video Course about running Integration tests at warp-speed using Docker and tmpfs
  • 3 chapters from my book, High-Performance Java Persistence, 
  • a 10% discount coupon for my book. 
Get the most out of your persistence layer!

Advertisements

6 thoughts on “JDBC Driver Connection URL strings

  1. Any news when dialects for SQL Server will map String to NVARCHAR instead of VARCHAR? VARCHAR has no unicode support and that hit me today.

      1. That’s a 5-year-old article and the SQL Server Dialect was fixed to include those mappings. If you need to extend a Hibernate Dialect, it’s worth sending a Pull Request as well. After all, Hibernate is an open-source project. We can all make it better.

Leave a Reply

Your email address will not be published. Required fields are marked *