Please send questions to
st10@humboldt.edu .
//
// modified from [CIS 318] Lab6.java, written by Ann Burroughs
//
// NOTE: this WILL NOT WORK unless you add
// /home/univ/oracle/products/jdbc/lib/classes12.zip
// ...to your CLASSPATH!!!
//
// modified by: Sharon Tuttle
// last modified: 4-16-01
// must import this for JDBC...
import java.sql.*;
public class TryJDBC1
{
public static void main(String args[])
{
Statement myStmt;
ResultSet myResultSet;
String myQuery, rowToPrint;
try
{
// load JDBC driver
Class.forName("oracle.jdbc.driver.OracleDriver");
// create a connection to Oracle student database
// on redwood, using account java/java
Connection con = DriverManager.getConnection
("jdbc:oracle:thin:@redwood:1521:student",
"java", "java");
// declare and create a statement object, using
// a Connection method createStatement()
myStmt = con.createStatement();
// this String contains the text of
// my SQL query
myQuery = "select ename, job from emp";
// this executes my query using the statement
// instance, returning the result as a
// resultset object
myResultSet = myStmt.executeQuery(myQuery);
while (myResultSet.next() != false)
{
// get job column value for this row
rowToPrint = myResultSet.getString("job");
// concatenate ename column value for this
// row, too
rowToPrint = rowToPrint + " "
+ myResultSet.getString("ename");
System.out.println(rowToPrint);
}
// CLOSE BOTH statement AND connection instances!!!
// IMPORTANT!!!
myStmt.close();
con.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}