Link to home
Start Free TrialLog in
Avatar of applekanna
applekanna

asked on

prepared statements

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
Avatar of jimmack
jimmack

You seem to be missing:

PreparedStatement pstmt = conn.prepareStatement(query);
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 ;-)
All statement instances know how to send sql to server.