In this article, we will list down all drivers and URL formation for all leading databases
Q) How to get Connection object for interacting with Database ?
- DriverManager class helps to get connection object using one of the overloaded static getConnection() methods i.e.;
getConnection(String dbURL); getConnection(String dbURL, Properties props); getConnection(String dbURL, String username, String password);
- Using connection, user can create SQL statement and then execute SQL queries against database
Q) How to load driver ?
- Before getting connection object, appropriate driver needs to be loaded using either of the following methods,
forName(“driverName”); registerDriver(appropriateDriverObject);
- There are 3 ways to create connection objects from overloaded static getConnection() methods available in the DriverManager class and all 3 requires database URL
- Therefore, we will look into driver class name and their corresponding database URL formation in tabular form,
Database, driver and URL with example :
Relational Database |
Driver Name (qualified class name) |
Database URL & Example |
MySQL | com.mysql.jdbc.Driver | jdbc:mysql://<server> :<port>/<databaseName> Eg: jdbc:mysql://localhost |
Oracle | oracle.jdbc.driver.OracleDriver | jdbc:oracle:thin:@<server> :<port>:<databaseName> Eg: jdbc:oracle:thin:@localhost |
IBM DB2 App | com.ibm.db2.jdbc.app.DB2Driver | jdbc:db2:<databaseName>
Eg: jdbc:db2:myDBName |
IBM DB2 Net | com.ibm.db2.jdbc.net.DB2Driver | jdbc:db2//<server> :<port>/<databasebName> Eg: jdbc:db2://localhost:6789/myDBName |
Sybase | com.sybase.jdbc.SybDriver | jdbc:sybase:Tds:<server> :<port>/<databaseName> Eg: jdbc:sybase:Tds:localhost |
Teradata | com.teradata.jdbc.TeraDriver | jdbc:teradata://<server> /database=<databaseName> ,tmode=ANSI,charset=UTF8 Eg: jdbc:teradata://localhost |
Microsoft SQL Server | com.microsoft.sqlserver .jdbc.SQLServerDriver |
jdbc:sqlserver://<server> :<port>;databaseName=<databaseName> Eg: jdbc:sqlserver://localhost |
Postgre | org.postgresql.Driver | jdbc:postgresql://<server> :<port>/<databaseName> Eg: jdbc:postgresql://localhost |
MS Access (JDBC-ODBC Bridge) | sun.jdbc.odbc.JdbcOdbcDriver | jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=<myDBName.mdb>; Eg: jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; |
Above things are mandatory for establishing connection with corresponding databases before actually creating/executing any SQL queries
Read Also:
- JDBC Tutorial index
- Introduction to JDBC
- Different types of JDBC drivers
- Basic components of JDBC
- JDBC connection steps
- MySQL database connection steps
- Oracle database connection steps
- MS Access database connection steps
- JDBC Interview question and answers
References:
- http://www.devx.com/tips/Tip/28818
- https://docs.oracle.com/javase/tutorial/jdbc/basics/gettingstarted.html
- https://docs.oracle.com/cd/E11882_01/java.112/e16548/overvw.htm#JJDBC28025
- http://docs.oracle.com/javase/tutorial/jdbc/basics/index.html
- https://en.wikipedia.org/wiki/JDBC_driver
- https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#forName(java.lang.String)
Happy Coding !!
Happy Learning !!