I am using the following code to insert values in to a table.
String sql = "INSERT INTO APPLICATION VALUES (?,?,?,?,?,?,TO_DATE(?,'DD/MMYYYY'),?,TO_DATE(?,'DD/MM/YYYY'),?,?,?,?,?,SYSDATE,'X',?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1,Integer.parseInt(sr));
pstmt.setString(2,nm);
pstmt.setString(3,(String)session.getValue("ITSGTYP"));
pstmt.setString(4,pst);
pstmt.setString(5,dox);
pstmt.setString(6,zo);
pstmt.setString(7,dob);
pstmt.setString(8,cdr);
pstmt.setString(9,cdrdt);
pstmt.setString(10,qual);
pstmt.setString(11,mail);
pstmt.setString(12,bond);
pstmt.setInt(13,Integer.parseInt((String)session.getValue("USER")));
pstmt.setString(14,request.getRemoteAddr());
pstmt.setString(17,place);
The description of the table into which the values are inserted is as follows
EMP_ID NOT NULL NUMBER(6)
NAME VARCHAR2(25)
APPLN_TYP VARCHAR2(10)
POST VARCHAR2(100)
DIV VARCHAR2(25)
ZONE VARCHAR2(5)
DOB DATE
CADRE VARCHAR2(5)
CADRE_DATE DATE
QUALIFICATION VARCHAR2(100)
EMAIL_ID VARCHAR2(70)
BOND VARCHAR2(3)
SUBMITTED_BY NUMBER(6)
SUBMIT_IP VARCHAR2(30)
SUBMIT_DATE DATE
FLAG VARCHAR2(1)
PLACE VARCHAR2(20)
While executing the above code I am getting the following error
Error: java.sql.SQLException: Invalid column index
This query was working fine before.
My previous table didn’t have the PLACE column. I had to insert it at a later point.
Replace
pstmt.setString(17,place);with
pstmt.setString(15,place);The reason for error you get is :
You don’t have 17
?symbols in your query for prepared statement, you only have 15?symbols that means you can only set 15 values (for 15 columns) for that prepared statement.Now what you were doing is you were setting a parameter at 17 th index and you don’t have any column specified at index 17 in your query, you only have 15 columns and 15
?symbols for the values to be inserted at respective 15 columns.So replace it with what I mentioned above and it will work.