java - JSP simple insertion cannot run in class -
I'm trying to do a simple entry like
string sql = "user Include in the bank (firstname, lastname, gender, mobile, email) value "(,,,,, ????); Int rows = 0; Try {PreparedStatement stmt = con.prepareStatement (SQL); Stmt.setString (1, "ABC"); Stmt.setString (2, "ABC"); Stmt.setString (3, "ABC"); Stmt.setString (4, "ABC"); Stmt.setString (5, "ABC"); Affect rows = stmt.executeUpdate (); } Hold (SQLException e) {e.printstaxtrace (); } and its works and able to insert . But when I'm trying this approach in the top like below
public class user {...} public class banker user {... public int store (connection con) {string} SQL = "Include the UserBanker (first name, last name, gender, mobile, email) Price (?,?,?,?,??)"; Int rows = 0; Try {PreparedStatement stmt = con.prepareStatement (SQL); Stmt.setString (1, super.getFirstName ()); Stmt.setString (2, super.getLlastName ()); Stmt.setString (3, super.getGender ()); Stmt.setString (4, this.getMobile ()); Stmt.setString (5, this.getEmail ()); Affect rows = stmt.executeUpdate (); } Hold (SQLException e) {e.printstaxtrace (); } Affecting the return lines; } ...} End of and I call it like this below
banker B1 = new banker (); ... Set all values ... b1.store (con);
Upper script above always returns unexpected results which is 0. The OOP script above gives always unexpected results which is 0.
This is because your try is blocked and you are swallowing it in the hold block, thus affecting the rows retains its initial value.
The exception being thrown is due to a syntax error in your insert statement parameter markers ? Single quotes '?' From Remove and let JDBC do so that you like it.
Comments
Post a Comment