Specifically if I have three queries should I do
PreparedStatement singleQuery ...
and “share” the one object. Or should I do
PreparedStatement query1 ...
PreparedStatement query2 ...
PreparedStatement query3 ...
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends on how different the three queries are. If they are the same query but with different arguments then use a single
PreparedStatementand set the arguments each time. If they are essentially three different queries (e.g. a select followed by an update) then you’ll need three differentPreparedStatements.For example, if the SQL for all three is of the form
SELECT * FROM table WHERE id = somethingthen a single statement is fine.If the first query is
SELECT name FROM customers WHERE id = ?and the second isSELECT price FROM products WHERE id = ?then you’re gonna need different objects.