Solved

prepared statements

Posted on 2003-12-10
5
331 Views
Last Modified: 2010-05-18
Hi,
I am using prepared statements and i have my code as

String query = "Insert into test (id , phone) values (?, ?)"
pstmt.setInt( 1, 19);
pstmt.setInt( 2, 12345567);
pstmt.executeUpdate(query);

This throws an exception

but if use
pstmt.executeUpdate(); it works.

y?

Thx
0
Comment
Question by:applekanna
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:jimmack
ID: 9917491
You seem to be missing:

PreparedStatement pstmt = conn.prepareStatement(query);
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 9917493
> pstmt.executeUpdate(query);

you cannot use placeholders if using this method, hence the exception.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9917496
The PreparedStatement has an implicit statment to execute, so passing it a query as well doesn't make much sense.  I'm not even sure why it's available, apart from the fact that PreparedStatement inherits from Statement ;-)
0
 
LVL 92

Expert Comment

by:objects
ID: 9917513
All statement instances know how to send sql to server.
0
 
LVL 92

Expert Comment

by:objects
ID: 9918002
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
javap not working 8 57
expectj telnet failing 5 45
hibernate example issues from command prompt 10 50
login form jsp example 2 35
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question