Connection conn = null;
Statement stmt=null;
ResultSet rset=null;
String jdbc_url="jdbc:oracle:thin:hr/hr@bassam-desktop:1521:XE";
String query="";
try
{
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    conn=DriverManager.getConnection(jdbc_url);
    stmt=(Statement) conn.createStatement();
    query="select first_name" +"from employees"+"where employeed_id=100";
    rset=stmt.executeQuery(query);
    System.out.println(rset.getString(1));


}
catch(SQLException | NumberFormatException e)
        {
            System.out.println("result error");
        }
finally{
    try{
        rset.close();
        stmt.close();
        conn.close();

    }
    catch(Exception e)
    {
        System.out.println("Error in closing");
    }
}


我在结果窗口中遇到两个错误,这是什么问题? hr密码正确,我的主机名正确,这不是在Windows XP中右键单击“我的电脑”后从“计算机名”获得的密码吗?

编辑:使用e.getMessage()后,我得到了..

result error, ResultSet.next was not called

最佳答案

您已在注释中添加了异常的错误消息,告诉您出了什么问题:


  结果错误,未调用ResultSet.next


您忘记了在访问结果集的第一行之前调用ResultSet.next():

if (rset.next()) {
    System.out.println(rset.getString(1));
}

10-05 18:53