RedRichard
asked on
JDBC INSERT problems
I have tested the following:
int update = statement1.executeUpdate(
"INSERT INTO tablename " +
"VALUES ('1', 10.25)");
and it works.
However if I want the values to be the result of method calls and not literally inserted, what syntax do i need?
int update = statement1.executeUpdate(
"INSERT INTO tablename " +
"VALUES ('currentKey', 'z.getPrice()')");
this wont work even though currnetKey is an int and z.getName() returns a double. I get a 'criteria mismatch problem'. Do i need to wrap? currentKey holds number in the db and z.getName() is for a column that holds decimal in the db.
confused.
int update = statement1.executeUpdate(
"INSERT INTO tablename " +
"VALUES ('1', 10.25)");
and it works.
However if I want the values to be the result of method calls and not literally inserted, what syntax do i need?
int update = statement1.executeUpdate(
"INSERT INTO tablename " +
"VALUES ('currentKey', 'z.getPrice()')");
this wont work even though currnetKey is an int and z.getName() returns a double. I get a 'criteria mismatch problem'. Do i need to wrap? currentKey holds number in the db and z.getName() is for a column that holds decimal in the db.
confused.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks CEHJ,
Prepared statements might help me cut down on the headaches my
style of sql was giving me!
Prepared statements might help me cut down on the headaches my
style of sql was giving me!
:-)
Bear in mind that theoretically you may take a performance hit from a PS as they are designed to optimise queries in loops and that comes at an DBMS price. However, this should not be noticeable. If, for some reason, it is. Let us know.
String sql = "INSERT INTO tablename (col1, col2) VALUES (?, ?)";