Solved

prepared statements

Posted on 2003-12-10
5
323 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
Comment Utility
You seem to be missing:

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

Accepted Solution

by:
objects earned 50 total points
Comment Utility
> pstmt.executeUpdate(query);

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

Expert Comment

by:jimmack
Comment Utility
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
Comment Utility
All statement instances know how to send sql to server.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

771 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

16 Experts available now in Live!

Get 1:1 Help Now