java sql insert preparedstatment error -
string sql = " insert `tblservice` (`serviceid`,`accountid`, `kind`, `description`, `price`, " + "`quantity`, `total`, `dateandtime`) values (null, ?, ?, ?, ?, ?, ?, ?)"; preparedstatement pstm = conn.preparestatement(sql); pstm.setint(1, this.accountid); pstm.setstring(2, "" + selectionbox.getselecteditem()); pstm.setstring(3, desc); pstm.setfloat(4, float.parsefloat(pricetf.gettext())); pstm.setfloat(5, float.parsefloat(quantitytf.gettext())); pstm.setfloat(6, this.gettotal()); pstm.setdate(7, dateadded); pstm.executeupdate();
error
com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: have error in sql syntax; check manual corresponds mariadb server version right syntax use near '?, ?, ?, ?, ?, ?, ?)' @ line 1
instead of make null in query values (null, ...)
use setnull
example :
pstm.setnull(1, java.sql.types.integer);
it take type, of field, in example consider java.sql.types.integer
can java.sql.types.varchar
or sql type
so query should :
string sql = "insert tblservice (serviceid, accountid, kind, description, price, quantity, total, dateandtime) values (?, ?, ?, ?, ?, ?, ?, ?)"; preparedstatement pstm = conn.preparestatement(sql); pstm.setnull(1, java.sql.types.integer); pstm.setint(2, this.accountid); ....
Comments
Post a Comment