/*
* @author : Shrinivas Bhat
* @Version : 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the File : Tracing.java
* Creation/Modification History :
*
* Shrinivas Bhat 22-Mar-2003 Created
*
*/
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jdbc.driver.OracleDriver;
/**
* A simple java class which connects to the database and prints the
* employee names from the EMP table. This class will be published as
* Java Stored Procedure and used to demonstrate the server side tracing
* in Java Stored Procedure.
*
*/
public class Tracing {
/**
* This method prints all the employee names to the output stream.
*/
public static void getEmployees() {
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Get the default database connection
Connection conn = new OracleDriver().defaultConnection();
// Create the statement
Statement stmt = conn.createStatement();
ResultSet rset = null;
//Execute the query
rset = stmt.executeQuery("SELECT ENAME FROM EMP");
System.out.println("Employee names in the EMP table ...");
while (rset.next()) {
// Print all the employee names
System.out.println(rset.getString("ENAME")) ;
}
} catch (SQLException sqlEx) {
sqlEx.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}