Solved

prepared statements

Posted on 2003-12-10
5
334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

739 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