• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
86 views

Problem:

I am getting below error while running JDBC code

java.sql.sqlexception: parameter index out of range (1 > number of parameters, which is 0).

The issue is caused because of below code

code:
---------------------------------------------------------------
String query="INSERT INTO opr_rt_info VALUES ('"+"?"+"','"+
"?"+"','"+"?"+"','"+"?"+"','"+"?"+"')";

by (300 points)  
edited by

1 Answer

0 votes

Possible Cause:

It seems the issue is related to PreparedStatement while using setxx() method.

Solution:

If you are using PreparedStatement while using setxx() method then please get rid of the quotes round the question marks. 

You should write the code as below:

String query="INSERT INTO User VALUES (?,?,?,?,?)";

pstmt = conn.prepareStatement(query);

pstmt.setString(1,opr_name1); 

pstmt.setString(2,opr_mode1);

pstmt.setString(3,rt_name1);

pstmt.setString(4,rt_ch_no1);

pstmt.setString(5,rt_ch_freq1);

int res1=pstmt.executeUpdate(query);

Conclusion:

While using PreparedStatement with setxx() method then please get rid of the quotes round the question marks.

Further Reading:

https://github.com/ioos/sos-injector-db/issues/11

by (36.1k points)  
edited by
...