- Oracle JDBC Connection


How to create a JDBC connection to Oracle database using the ojdbc Oracle Driver? I want to see a Java program example.



If you have Oracle Database 11g XE running on your local computer, you can use the following example to learn how to create a JDBC connection:

// Copyright (c)
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.DatabaseMetaData;

// Example of ojdbc JDBC connection to Oracle server
public class OracleJdbcConnection {
   public static void main(String [] args) throws Exception {

      // Use the basic ojdbc JDBC connection URL
      String url = "jdbc:oracle:thin:SYS AS SYSDBA/fyicenter@//localhost/XE";
      Connection con = DriverManager.getConnection(url);
      System.out.println("JDBC connection and database server information:"); 
      DatabaseMetaData meta = con.getMetaData();
      System.out.println("Database Product Name: "
        + meta.getDatabaseProductName());
      System.out.println("Database Product Version: "
        + meta.getDatabaseProductVersion());
      System.out.println("Driver Name: "
        + meta.getDriverName());
      System.out.println("Driver Version: "
        + meta.getDriverVersion());
      System.out.println("JDBC Major Version: "
        + meta.getJDBCMajorVersion());
      System.out.println("JDBC Minor Version: "
        + meta.getJDBCMinorVersion());

      // Close the connection

You can compile and run the above example in a command window as shown below:


   -cp .;\fyicenter\Oracle-\ojdbc6.jar 

JDBC connection and database server information:
Database Product Name: Oracle
Database Product Version: Oracle Database 11g Express Edition Release
   - 64bit Production
Driver Name: Oracle JDBC driver
Driver Version:
JDBC Major Version: 11
JDBC Minor Version: 2

The output shows that:

  • The database server is Oracle Database 11g.
  • The JDBC driver is Oracle JDBC driver
  • The JDBC API supported is JDBC 11.2. This seems to be a bug. It should be JDBC 4.0 - Oracle JDBC Create Table

Start Oracle Database 11g XE on Windows

Examples for ojdbc.jar - JDBC Driver for Oracle

⇑⇑ FAQ for ojdbc.jar - JDBC Driver for Oracle

2018-03-28, 2033🔥, 0💬