Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic