1 Replies - 2133 Views - Last Post: 03 April 2012 - 07:15 PM Rate Topic: -----

#1 Shahpoup_JBOSS  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-December 10

Parameter index out of range (2 > number of parameters, which is 1

Posted 03 April 2012 - 07:02 PM

hello, Developers

when i make this connection to database and execute SQL statement with PreparedStatement
as :
            String sql_update_Esal = "UPDATE esal SET student_id=(SELECT student.student_id from student where student.student_name='?' )"
                    + "course_id=(select course.course_id from course where course.course_name='?' )  "
                    + "where esal_id=? ";

            PreparedStatement pstmt_update_esal = conn.prepareStatement(sql_update_Esal);

            pstmt_update_esal.setString(1, st_name);
            pstmt_update_esal.setString(2, tf_Main_CourseName.getText().trim());
            pstmt_update_esal.setInt(3, Integer.parseInt(tf_Main_isalID.getText().trim()));
            pstmt_update_esal.executeUpdate(sql_update_Esal);
            JOptionPane.showMessageDialog(null, "Esal Updated All Finished");


throw this exception

ava.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3288)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3272)
at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:4108)

i use : server: mySQL
IDE : Netbeans 7.1
platform : Windows

Is This A Good Question/Topic? 0
  • +

Replies To: Parameter index out of range (2 > number of parameters, which is 1

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Parameter index out of range (2 > number of parameters, which is 1

Posted 03 April 2012 - 07:15 PM

Not a SQL specialist, never did cross table, but I feel your SQL statement has "AND" missings
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1