To connect Oracle using JDBC ojdbc{version}.jar should be in your classpath. You could Google and download this jar and include in your class path.
Connect Oracle using JDBC sample java program:
package com.javahonk; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class GetDatabaseConnection { public static void main(String[] args) { Connection connection = null; try { // Register JDBC Driver Class.forName("oracle.jdbc.driver.OracleDriver"); // Open connection connection = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:" + "javahonk", "scott","tiger"); if (null != connection) { System.out.println("Sucessfully " + "connected to Oracle database!!!"); } else { System.out.println("Connection " + "to Oracle database failed!!!"); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { e.printStackTrace(); } } } }
Output:
That’s it for connect Oracle using JDBC