import java.sql.*;
public class DBConnection {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection conn=null;
ResultSet rs=null;
Statement stmt=null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@127.0.0.1:1521:orcl",
"scott",
"tiger"
);
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from emp WHERE empno=7499");
while(rs.next()) {
String s1=rs.getString("deptno");
String s2=rs.getString("ename");
System.out.println("deptno: "+s1+" ,ename: "+s2);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if(rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if(conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
java连接到oracle
最新推荐文章于 2022-12-09 10:48:10 发布