zoit
zoit

Reputation: 667

java.lang.Exception: Parameter index out of range (2 > number of parameters, which is 1)

I would love to know why I have this mistake: java.lang.Exception: Parameter index out of range (2 > number of parameters, which is 1).

Yes, I use PreparedStatement

 SQL="SELECT pcsv("+servidor_virtual_nuestro+","+nivel_cuenta_receptora+","+codigo_sku[id_componente]+","+t_precio[tipo_precio]+",0) as p_unitario FROM servidores_virtuales t1"+
 "WHERE t1.id_servidor_virtual= ? ";


PreparedStatement pstm100 = this.conexion.prepareStatement(SQL);

pstm100.setInt(1, servidor_virtual_nuestro);

ResultSet rs66 =  pstm100.executeQuery();

pcsv is a procedure which I have created, so I don't know why I have this mistake, could you help me?. Thanks so much

Upvotes: 0

Views: 874

Answers (2)

ABEJ RIJWI
ABEJ RIJWI

Reputation: 1

public void ReturnUpdate() {
        String sql = "insert into returnbook (`Student Id`,`Student Name`,`Father Name`,Course,Branch,Year,Semester,`Book Id`,`Book Name`,Edition,Publisher,Price,Pages,`Date of Issue`,`Date of Return`) values ";
        try{
         pst = conn.prepareStatement(sql);
         pst.setString (1,  jTextField1.getText());
         pst.setString (2,  jTextField2.getText());
         pst.setString (3,  jTextField3.getText());
         pst.setString (4,  jTextField4.getText());
         pst.setString (5,  jTextField5.getText());
         pst.setString (6,  jTextField6.getText());
         pst.setString (7,  jTextField7.getText());
         pst.setString (8,  jTextField8.getText());
         pst.setString (9,  jTextField9.getText());
         pst.setString (10, jTextField10.getText());
         pst.setString (11, jTextField11.getText());
         pst.setString (12, jTextField12.getText());
         pst.setString (13, jTextField13.getText());
         pst.setString(15, ((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText());
         pst.execute();
           JOptionPane.showMessageDialog(null,"Book Returned");
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
    }

Upvotes: -2

gageorge
gageorge

Reputation: 257

I don't see what would cause the exception as thrown, but I suppose it could be a side effect of the fact that you're creating improper SQL. Your SQL string needs a space between t1 and WHERE.

Or it could be some extra question marks that are in some of your variables. Try printing out the SQL string to a log or stdout before executing it.

Upvotes: 3

Related Questions