java - SQLException Parameter index out of range -


What am I doing wrong in this code? This gives a SQLException that a parameter is out of range, while I think I have given the parameter. Type the item type as

  try {string sql = "item type", in the form of 'med by' by MD_, as a 'model' model, 'selling price As' Purchase Price ',' + "purchase_date as' purchase date ',' voucher no 'to' vouchers' as' sale_price, 'as purchase. As, "+" the voucher date as the voucher date, as record_no 'record number'. "+" Where to buy vouch_no =? "; Ps.setInt (1, integer. PRIIST (txt_vouchno_p.getText ()); Ps = con.prepareStatement (SQL); Rs = ps.executeQuery (); Table_p.setModel (DbUtils.resultSetToTableModel (RS));} Hold (pre-SQLException) {JOptionPane.showMessageDialog (empty, "error:" + east);} hold (exception before) {JOptionPane.showMessageDialog (zero, "error:" + east);}   Your order for calling methods is wrong First of all, you prepare the statement, then you set the bound variable value. Change  
  ps.setInt (1, Full .piIINt (txt_vouchno_p.getText ()); Ps = con.prepareStatement (SQL); From   

to

  ps = con.prepareStatement (sql) ; Ps.setInt (1, integer. PRIIST (txt_vouchno_p.getText ());    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -