/**
* 单独的java程序连接oracle数据库
* authorJavaAlpha
* date ::
*/
import javasql*;
public class Test {
public static void main(String[] args){
String driver = "oraclejdbcdriverOracleDriver";
String url = "jdbc:oracle:thin:@::orcl";
String user = "root";
String password = "";
try {
ClassforName(driver);
Connection conn = DriverManagergetConnection(url user password);
if(!connisClosed())
Systemoutprintln("Succeeded connecting to the Database!");
Statement statement = conncreateStatement();
String sql = "SELECT PASSWORD from USER WHERE id=test";
ResultSet rs = statementexecuteQuery(sql);
while(rsnext())
{
Systemoutprintln(rsgetString("PASSWORD"));
}
rsclose();
connclose();
} catch(ClassNotFoundException e) {
Systemoutprintln("Sorrycan`t find the Driver!");
eprintStackTrace();
} catch(SQLException e) {
eprintStackTrace();
} catch(Exception e) {
eprintStackTrace();
}
}
}