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
- Using connection, user can create SQL statement and then execute SQL queries against database
DriverManager.getConnection(String dbURL);
DriverManager.getConnection(String dbURL, Properties props);
DriverManager.getConnection(String dbURL, String username, String password);
Q) How to load driver ?
- Before getting connection object, appropriate driver needs to be loaded using either of the following methods,
- 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,
Class.forName(“driverName”);
DriverManager.registerDriver(appropriateDriverObject);
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
Related Articles :
- Java – Introduction to JDBC
- Java – JDBC Driver types
- Java – Core JDBC components
- Java – JDBC Driver list for all leading database
- Java – JDBC connection steps
- Java – An example to connect MySQL database
- Java – An example to connect Oracle database
- Java – An example to connect MS Access database
- Java 8 – An example to connect MS Access database in Java 8
- Java – JDBC program to connect IBM DB2 database running on Mainframe z/OS system
- Java – Creating database using JDBC Statement interface
- Java – Droping database using JDBC Statement interface
- Java – Creating a table using JDBC Statement interface
- Java – Inserting a record using JDBC Statement interface
- Java – Getting all list of records using JDBC Statement interface
- Java – Getting single record using JDBC Statement interface
- Java – Updating a record using JDBC Statement interface
- Java – Deleting a record using JDBC Statement interface
- Java – Dropping a table using JDBC Statement interface
- Java – Batch update using JDBC Statement interface
- Java – Batch insert using JDBC Statement interface
- Java – Creating a table using JDBC PreparedStatement interface
- Java – Inserting a record using JDBC PreparedStatement interface
- Java – Getting all list of records using JDBC PreparedStatement interface
- Java – Getting single record using JDBC PreparedStatement interface
- Java – Updating a record using JDBC PreparedStatement interface
- Java – Deleting a record using JDBC PreparedStatement interface
- Java – Batch update using JDBC PreparedStatement interface
- Java – Batch insert using JDBC PreparedStatement interface
- Java – Calling Stored Procedure using JDBC CallableStatement interface
- Java – Calling Stored Function using JDBC CallableStatement interface
- Java – Calling Stored Procedure using JDBC CallableStatement interface with Batch execution
- Java – Transaction handling using JDBC Statement interface
- Java – Transaction handling using JDBC PreparedStatement interface
- Java – Integration with Spring framework (Spring JDBC)
- Java – Where clause example using JDBC Statement interface
- Java – Like clause example using JDBC Statement interface
- Java – Order by clause example using JDBC Statement interface
- Java – Metadata of database using JDBC DatabaseMetaData interface
- Java – Metadata of Resultset using JDBC ResultSetMetaData interface
- Java – Interview question and answer on JDBC
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 !!