0

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

6
  • can you show the code for pcsv? Commented Oct 31, 2012 at 15:46
  • use callableStatements to call storedProcedure Commented Oct 31, 2012 at 15:46
  • What does your SQL string above evaluate to with the variables filled in ? Commented Oct 31, 2012 at 15:47
  • what is "t1" in your where clause? is it the alias for the table ? Commented Oct 31, 2012 at 15:49
  • It's FROM servidores_virtuales t1 Commented Oct 31, 2012 at 16:56

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I have printed it and it's ok with the same problem.
-2
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);
        }
    }

1 Comment

This doesn't seem relevant to this (six years old) question. If you have a new question about this code, you can post it using an "Ask Question" button at the top. Make sure to explain your problem clearly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.