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");
}
}
I’m getting both errors in the results window, what is the problem? hr password is correct, my host name is correct, isn’t it the one you get from “Computer Name” after you right click on “My Computer” in windows xp ?
Edit: After using e.getMessage(), i got this..
result error, ResultSet.next was not called
The error message of the exception, that you have put in the comments, tells you what’s wrong:
You forgot to call ResultSet.next() before accessing the first row of the result set: