How to connect Oracle with JAVA (Netbeen)

Опубликовано: 09 Апрель 2026
на канале: King of Techniques
261
9

Connect Oracle Database in Java Using NetBeans
Download the Oracle JDBC driver (ojdbc7.jar) from Oracle.com
Learn how to add a JAR file to the NetBeans Project
After completing the above two steps, you would be able to connect to the Oracle Database. The following is the example Java program:


xample Java program:
//ConnectOracle.java

import java.sql.*;

class ConnectOracle {

public static void main(String args[]) {
try {

// Load the JDBC Driver
Class.forName("oracle.jdbc.driver.OracleDriver");

// Create a connection
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");

// Create a statement for SQL query
Statement stmt = con.createStatement();

// Execute the query
ResultSet rs = stmt.executeQuery("select sysdate from dual");
while (rs.next()) {
System.out.println("Oracle Database current date is " + rs.getString(1));
}

// Close the connection object
con.close();

} catch (Exception e) {
System.out.println(e);
}

}
}