This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes resultset  or prepared stmt?. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "resultset  or prepared stmt?." Watch "resultset  or prepared stmt?." New topic

resultset or prepared stmt?.

Arun Martin
Ranch Hand

Joined: Dec 01, 2000
Posts: 64
this is one of the questions from the mock exams.
import java.sql.*;
Additional code here
Connection c; c=DriverManager.getConnection("jdbc:msql://host:12/dta");
String str = "update employee set salary=50000
where lname=\'jones\'";
What code would execute the SQL statement above?
Choice 1
Statement s = c.createStatement();
ResultSet rs = s.executeUpdate(str);
Choice 2
PreparedStatement s = c.prepareStatement(str);
ResultSet rs = s.executeUpdate();
Choice 3
ResultSet rs = c.execute();
Choice 4
ResultSet rs = c.executeUpdate(str);
Choice 5
CallableStatement s = c.createCall(str);
ResultSet rs = s.executeCall();
what would be the appropriate answer?.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
1 and 2 are wrong because executeUpdate does not return a ResultSet object.
3 is wrong because there is no such method as setSQL() for a Connection object.
4 is wrong because there is no method executeUpdate() for a Connection object.
5 is wrong because there is no such method as createCall in a Connection object and no such method as executeCall() in a CallableStatement object.
So the correct answer is none of the above.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
I agree. Here's the link:
subject: resultset or prepared stmt?.
It's not a secret anymore!