salim salim - 7 months ago 7
SQL Question

i want to search values from mysql data on java using search action performed but its giving me errors parameter index out of range

enter image description here

Search button is not working properly it says parameter index is out of range

Answer

A PreparedStatement may use placeholders ? , that enables you to pass values that will be escaped .

Your query has no placeholder, so calling a replacement method like :

pstmt.setString(1,EmployeeName)

throws an Exception, because there isn't a placeholder's of index 1 in your query.

If what you want, is to search for a particular Employee based on the values you have (name and surname), you may execute a parameterized query with two placeholders :

pstmt=conn.prepareStatement("select * from empdetails where EmployeeName = ? AND EmployeeSurname = ?");
pstmt.setString(1,EmployeeName);
pstmt.setString(2,EmployeeSurName);
Comments