• Post Reply Bookmark Topic Watch Topic
  • New Topic

JDBC Question

 
Saikiran Tedla
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was looking at this question online and was surprised to see the answer was A. I thought it was C. Please let me know why it is not C and why it is A.

Given the records from the Employee table
eid    ename
111    Tom
112    Jerry
113    Donald
and given the code fragment:

Java

try {
    Connection conn = DriverManager.getConnection(URL, userName, passWord);
    Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    st.execute("SELECT * FROM Employee");
    ResultSet rs = st.getResultSet();
    while (rs.next()) {
        if (rs.getInt(1) == 112) {
            rs.updateString(2, "Jack");
        }
    }
    rs.absolute(2);
    System.out.println(rs.getInt(1) + " " + rs.getString(2));
} catch (SQLException ex) {
    System.out.println("Exception is raised");
}
try {
    Connection conn = DriverManager.getConnection(URL, userName, passWord);
    Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    st.execute("SELECT * FROM Employee");
    ResultSet rs = st.getResultSet();
    while (rs.next()) {
        if (rs.getInt(1) == 112) {
            rs.updateString(2, "Jack");
        }
    }
    rs.absolute(2);
    System.out.println(rs.getInt(1) + " " + rs.getString(2));
} catch (SQLException ex) {
    System.out.println("Exception is raised");
}
Assume that:

The required database driver is configured in the classpath.
The appropriate database accessible with the URL, userName, and passWord exists.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!