This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes resultset  or prepared stmt?. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "resultset  or prepared stmt?." Watch "resultset  or prepared stmt?." New topic
Author

resultset or prepared stmt?.

Arun Martin
Ranch Hand

Joined: Dec 01, 2000
Posts: 64
hi,
this is one of the questions from the mock exams.
question:
---------
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?
options:
-------
Choice 1
Statement s = c.createStatement();
ResultSet rs = s.executeUpdate(str);
Choice 2
PreparedStatement s = c.prepareStatement(str);
ResultSet rs = s.executeUpdate();
Choice 3
c.setSQL(str);
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?.
arun.
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: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: resultset or prepared stmt?.
 
Similar Threads
error while entering the data into oracle database
executeUpdate() ?
Problem with SQL select
rmi and resultset
exception