java - MsAccess SQL Exception Too few parameters -
currently making java program grabs data off of msaccess database , of these errors extremely frustrating. keep getting sql.exception : few parameters. expected 1 error on last remaining bugs in program.
little background on db: has 3 tables (a player table (11 columns), team table (3 columns), , opponent table (6 columns).
these both of functions , problem lies in here somewhere
conn = connect.connectdb(); string sql = "insert player ("+"playerlastname,"+"playerfirstname,"+"position)"+ "values("+txtid.gettext()+ ",'"+txtname.gettext()+"','"+txtaddress.gettext()+"')" ; try{ pst = conn.preparestatement(sql); pst.executequery(); pst.setstring(1, txtid.gettext()); pst.setstring(2, txtname.gettext()); pst.setstring(3, txtaddress.gettext()); joptionpane.showmessagedialog(null, txtid.gettext() + " saved"); updatejtable(); //conn.close(); } catch(exception e){ joptionpane.showmessagedialog(null, e); }
or function
string sql = "select * player playerlastname = " +txtid.gettext()+ ""; string pine = null; try{ pst = conn.preparestatement(sql); resultset res; res = pst.executequery(); pine.equalsignorecase(jtable1.getmodel().getvalueat(rowsu, 10).tostring()); while(res.next()){ joptionpane.showmessagedialog(null, txtname + " " + txtid.gettext() + " has total of " +"4");//+ pine);//res.getint("penalties") ); } updatejtable(); } catch(exception e){ joptionpane.showmessagedialog(null, e); }
for 1 thing, looks you're missing single quotes around last name in insert statement.
there may other errors well, that's first thing noticed.
this should pretty easy debug if log sql string before executing it.
edit
i think calls setstring() problem. here how should this:
conn = connect.connectdb(); string sql = "insert player (playerlastname, playerfirstname, position) values(?, ?, ?)"; try{ pst = conn.preparestatement(sql); pst.setstring(1, txtid.gettext()); pst.setstring(2, txtname.gettext()); pst.setstring(3, txtaddress.gettext()); pst.execute(); joptionpane.showmessagedialog(null, txtid.gettext() + " saved"); updatejtable(); //conn.close(); } catch(exception e){ joptionpane.showmessagedialog(null, e); }