Import java. SQL .*;
Public class testjdbc {
Public static void main (string [] ARGs ){
Resultset rs = NULL;
Statement stmt = NULL;
Connection conn = NULL;
Try {
Class. forname ("oracle. JDBC. Driver. oracledriver ");
// New Oracle. JDBC. Driver. oracledriver ();
Conn = drivermanager. getconnection ("JDBC: oracle: thin: @ 192.168.0.1: 1521: www", "Scott", "Tiger ");
Stmt = conn. createstatement ();
Rs = stmt.exe cutequery ("select * from Dept ");
While (Rs. Next ()){
System. Out. println (Rs. getstring ("deptno "));
System. Out. println (Rs. getint ("deptno "));
}
} Catch (classnotfoundexception e ){
E. printstacktrace ();
} Catch (sqlexception e ){
E. printstacktrace ();
} Finally {
Try {
If (RS! = NULL ){
Rs. Close ();
Rs = NULL;
}
If (stmt! = NULL ){
Stmt. Close ();
Stmt = NULL;
}
If (Conn! = NULL ){
Conn. Close ();
Conn = NULL;
}
} Catch (sqlexception e ){
E. printstacktrace ();
}
}
}
}