Solved

prepared statements

Posted on 2003-12-10
5
329 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -ano | find "8000" and taskkill /f /pid 2984 3 56
replace a word with other 1 44
jboss wildfly 10.1 10 80
Java: anonymous class 4 17
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.

786 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