Class.forName("oracle.jdbc.driver.OracleDriver"); // 加载驱动器的类
String url = "jdbc:oracle:thin:@localhost:dbname";
String user = "test";
String password = "test";
conn = DriverManager.getConnection(url, user, password);
String sql = "select * from test_tb";
try {
PreparedStatement ps = con.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}