没有使用ConnDBa辅助类 package two; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class SingleOracleJDBC { public static void main(String[] args) { Connection conn=null; Statement sm=null; ResultSet rs=null; try { //1.注册驱动 Class.forName("oracle.jdbc.driver.OracleDriver"); //2.建立数据库链接 conn = DriverManager.getConnection(url, username, password); conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","hello"); //3.创建JDBC Statement对象 sm=conn.createStatement(); //4.读取数据库 rs=sm.executeQuery("select * from dept"); while(rs.next()){ System.out.println("deptno==" + rs.getInt(1)); System.out.println("dname==" + rs.getString(2)); System.out.println("loc==" + rs.getString(3)); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); }finally{ try { if(rs!=null){ rs.close(); } if(sm!=null){ sm.close(); } if(conn!=null){ conn.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }