/**
* You need the oracle’s driver jar (classes12.jar)
*/
public static void main(String args[]) {
try {
//Attempts to establish a connection to the given database URL.
//The DriverManager attempts to select an appropriate driver from
//the set of registered JDBC drivers.
Class.forName(“oracle.jdbc.driver.OracleDriver”);
Connection myConn = DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:MYDATABASE”, “user”, “password”);
//Creates a Statement object for sending
//SQL statements to the database.
Statement myStatement = myConn.createStatement();
//Executes the given SQL statement, which returns a single ResultSet object.
ResultSet myResultSet = myStatement.executeQuery(“SELECT * FROM table”);
//Iterates the resultSet so you can get the info
while (myResultSet.next()) {
System.out.println(myResultSet.getString(“column_table1”));
}
//close the ResultSet object
myResultSet.close();
//Releases this Connection object’s database and JDBC resources
//immediately instead of waiting for them to be automatically released.
myConn.close();
}
catch (ClassNotFoundException cnfex) {
System.err.println(“Can’t load JDBC”);
cnfex.printStackTrace();
System.exit(1);
}
catch (SQLException sqlex) {
System.err.println(“No connection”);
sqlex.printStackTrace();
}
}