I’ve started using prepared statement for my sql updates, but I seem to be getting a snag when I’m updating. The logic seems sound but I get an error whenever it goes into the update segment. I can delete or insert fine. Anywho…
Connection con = getDBConnection();
PreparedStatement pstmt = null;
String query = "update table set int = ?, String= ? where int= ? and date= ?";
pstmt = con.prepareStatement(query);
pstmt.setInt(1, var);
pstmt.setDate(2, sqlDate);
pstmt.setInt(3, intVar);
pstmt.setString(4, stringVar);
pstmt.executeUpdate();
Am I doing something wrong here? I’ve done all the troubleshooting I can and everything seems fine except for this, potentially.
Error = "A non-numeric character was found where a numeric was expected"
You’ve got your string and date the wrong way round – you’re calling
setDate(2, ...)when the second parameter is in the context of “String = ?” andsetString(4, ...)when the fourth parameter is in the context of “date = ?”.Admittedly the error you’re getting is somewhat odd for that, but it’s all I can see…