java连接oracle 入门odbc

来源:互联网 发布:一吻定情知乎 编辑:程序博客网 时间:2024/05/18 00:49

 

 

public void testOracle() {try {Class.forName("oracle.jdbc.driver.OracleDriver");Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "system", "admin");System.out.println("连接成功!");Statement stmt = conn.createStatement();ResultSet rs = stmt.executeQuery("select * from stu_info_tab");while (rs.next()) {System.out.println("ok");System.out.println(rs.getInt("student_id"));}rs.close();stmt.close();conn.close();} catch (ClassNotFoundException e) {System.out.println("ClassNotFoundException");} catch (SQLException e) {System.out.println("SQLException");}}

 

备注:默认的用户名是system,密码是自己设定的,不能用sys或者是sysdba,这个只是角色