在java问题中连接到数据库

时间:2014-10-10 08:08:44

标签: java

我的oracle数据库中有一个表Employee,我用java连接它。当我在其中添加信息时,但是当我尝试获取信息时,它也会提供旧信息(我已经删除了)。我确信我连接了正确的数据库和关闭的连接。我认为ResultSet存储数据。可能吗?谢谢

    public static Connection getConnection(){

    Connection connection = null;

    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
     }

    catch (ClassNotFoundException e) {
                System.err.println (e) ;
                System.exit (-1) ;
    }

    try {
           connection = DriverManager.getConnection(
           "jdbc:oracle:thin:@127.0.0.1:1521:orcl",
           "mamur",
           "mamur"
         );
    }

    catch (java.sql.SQLException e) {
        System.err.println (e) ;
        System.exit (-1) ;
    }

    return connection;    
}

         public String [] getStudents(String query) throws SQLException{

    ConnectionClass con = new ConnectionClass();
    connection = con.getConnection();       

            statement = connection.createStatement();
            ResultSet rs = statement.executeQuery(query);   

            while(rs.next()){
                list.add(rs.getString(1) + " " + rs.getString(2));
            }                       

            rs.close();

    String [] arr = new String [list.size()];

    list.toArray(arr);      
    return arr;
}   

我设置了结果Jlist

0 个答案:

没有答案