When using this method, you need to add the Oracle jar package to the classpath variable. This package can be found in $ ORACLE_HOME/jdbc/lib/classes12.jar of the oralce client program.
Import java. SQL .*;
Public class jdbcthin {
// Dburl database connection string information, where "1521" is the port and "ora9" is the SID
String dburl = "JDBC: oracle: thin: @ 10.10.20.15: 1521: ora9 ";
// Theuser is the Database User Name
String theuser = "sman ";
// Thepw indicates the Database Password.
String thepw = "sman ";
// Several database variables
Connection c = NULL;
Statement conn;
Resultset rs = NULL;
// Initialize the connection
Public jdbcthin (){
Try {
Class. forname ("oracle. JDBC. Driver. oracledriver"). newinstance ();
// Establish a connection with the data source specified by the URL
C = drivermanager. getconnection (dburl, theuser, thepw );
// Use statement for query
Conn = C. createstatement ();
} Catch (exception e ){
E. printstacktrace ();
}
}
// Execute the query
Public resultset executequery (string SQL ){
Rs = NULL;
Try {
Rs = conn.exe cutequery (SQL );
} Catch (sqlexception e ){
E. printstacktrace ();
}
Return Rs;
}
Public void close (){
Try {
Conn. Close ();
C. Close ();
} Catch (exception e ){
E. printstacktrace ();
}
}
Public static void main (string [] ARGs ){
Resultset newrs;
Jdbcthin newjdbc = new jdbcthin ();
Newrs = newjdbc.exe cutequery ("select * From eventtype ");
Try {
While (newrs. Next ()){
System. Out. Print (newrs. getstring ("event_type "));
System. Out. println (":" + newrs. getstring ("content "));
}
} Catch (exception e ){
E. printstacktrace ();
}
Newjdbc. Close ();
}
}