java - How do I call a getter from JDBC? -
i executing update , want insert value returned getter table.
statement.executeupdate("insert my_table " + "values(myclass.getvalue(), 'abcd',now())"); i have tried debugging through , found string value , datetime executes correctly. gives me exception when calling getter. detail message shows function myclass.getvalue not exist.
my imports in order. ideas?
statement.executeupdate("insert my_table " + "values("+myclass.getvalue() + ", 'abcd',now())");
your get-call interpreted string because of missing ' " '. take @ prepared statements, easy read , utilize , don't have struggle these problems.
prepared statement version (also lot more secure because preventing sql injection):
preparedstatement pst = yourconnection.preparestatement("insert my_table values(?,?,now())"; pst.setstring(1,myclass.getvalue()); pst.setstring(2,"abcd"); pst.executeupdate(); java jdbc
No comments:
Post a Comment