Insert INT into MySql table via label in Java - NumberFormatException -
i trying insert int table, via label. have 6 columns, starting name, lastname varchars, , number, points, assists , rebounds ints. query with:
string sql = ("insert `playertable`(`name`, `lastname`, `number`, `points`, `assists`, `rebounds`) values (?,?,?,?,?,?)"); preparedstatement ps = playerbase.get().preparestatement(sql); ps.setstring(1, playernamefld.gettext()); ps.setstring(2, playerlnfld.gettext());
works fine, when try parse:
try { ps.setint(3, integer.parseint(playernumberfld.gettext())); } catch (exception e) { e.printstacktrace(); }
i numberformatexception: input string: "" , sqlexception: no value specified parameter 3. how can fix this? thanks
try { ps.setint(3, integer.parseint(playernumberfld.gettext())); } catch (exception e) { ps.setint(3,0); e.printstacktrace(); }
playernumberfld empty. if try parse exception comes. incase of exception put 0 in catch block , try
Comments
Post a Comment