import java.sql.*;public class Base {
public static void main(String[] args) {
}
static void test()throws SQLException{
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from emp");
while(rs.next()){
System.out.println(rs);
}
rs.close();
st.close();
con.close();

}}

解决方案 »

  1.   


    import java.sql.*; public class Base { 
    public static void main(String[] args) { 

    static void test()throws SQLException{ 
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); 
    Connection con = null;
    Statement st = null;
    ResultSet  rs = null;
    try{
    con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger"); 
    st = con.createStatement(); 
    rs = st.executeQuery("select * from emp"); 
    while(rs.next){
      //此处就要看LZ的表了,调用相对于的获取方法即可
    }
    }catch(Exception ex){
    ex.printStackTrace();
    }finally{
    if(rs!=null){
    rs.close();
    }
    if(st!=null){
    st.close(); 
    }
    if(con!=null){
    con.close(); 
    }
    }


      

  2.   


    import java.sql.*; public class Base { 
    public static void main(String[] args) throws SQLException {
                            //调用业务方法
    test();
    }


    static void test()throws SQLException{ 
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); 
    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger"); 
    Statement st = con.createStatement(); 
    ResultSet rs = st.executeQuery("select * from emp"); 
    while(rs.next()){ 
    System.out.println(rs); 

    rs.close(); 
    st.close(); 
    con.close();
    }
    }代码的异常处理有问题。