import java.sql.*;
public class TestJDBC {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
//new oracle.jdbc.driver.OracleDriver();
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ORA", "scott", "tiger");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from emp");
while(rs.next()){
System.out.println(rs.getString(1)+", "+rs.getString(2));
}
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace(); //此处用logo4J记录一下。
}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();
}
}
}
}
java连接oracle数据库
最新推荐文章于 2023-04-20 10:14:06 发布