JDBC Driver Connection URL strings
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
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.
Connect to a relational database using #Java with JDBC Driver Connection URL strings - @vlad_mihalcea https://t.co/vdCpoWvrIE pic.twitter.com/hy2OuQrYkC
— Java (@java) February 15, 2018
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.MySQL8Dialect |
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://localhost/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://localhost/high_performance_java_persistence |
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/high_performance_java_persistence |
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://localhost: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:high_performance_java_persistence |
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=high_performance_java_persistence;create=true |
Hibernate Dialect | org.hibernate.dialect.DerbyTenSevenDialect |
That’s it!
I'm running an online workshop on the 11th of October about High-Performance SQL.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.
