Top Previ
ous Next Roadmap Index

Sample Program


The following program lists the contents of the ENAME column of the EMP table. It loads the Oracle JDBC/OCI driver, connects to the database, submits a query, receives a result set, and prints its contents.

import java.sql.*; 
import java.io.*;
import java.util.Date;

class JdbcTest
{
public static void main (String args [])
throws SQLException, IOException
{
System.out.println ("Loading Oracle JDBC OCI driver");

try
{
Class.forName ("oracle.jdbc.OracleDriver");
}

catch (ClassNotFoundException e)
{
System.out.println ("Could not load the driver");
e.printStackTrace ();
}

System.out.println ("Connecting to the local database");
Connection conn =
DriverManager.getConnection ("jdbc:oracle:scott/tiger");

Statement stmt = conn.createStatement ();

// Query the employee names
ResultSet rset = stmt.executeQuery ("select ename from emp");

while (rset.next ())
{
// Print the name out
System.out.println (rset.getString (1));
}
}
}


Click Here
 to Go to the top of the section

Click
 Here to Go to the previous topic

Click Her
e to Go to the next topic

Click Here to Go to the Roadmap

Click Here to Go to the Index


To report any problems or comments, email email jsqlpm@us.oracle.com .