Solved

prepared statements

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse package explorer vs project explorer view 2 84
java.io.BufferedReader   readLine()  //returns the entire file ? 4 60
tomcat not starting 6 32
MySQL  on Tomcat 8 30
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

862 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now