0

This is my code where METHODARGDATATYPE_VARRAY is a varray at 5th column in my table and first column has auto generated sequence concatenated with 't'.

 String arrayElements[] = { "Test3", "Test4" }; ArrayDescriptor desc = ArrayDescriptor.createDescriptor ("METHODARGDATATYPE_VARRAY", conn); ARRAY newArray = new ARRAY(desc, conn, arrayElements); String sql="insert into TestCaseIDDetails values (concat('t',TestCaseID_sequence.nextval),?,?,?,?)"; PreparedStatement ps = conn.prepareStatement (sql); ps.setString(2,testCaseIDandDetailsBean.getClass_name()) ; ps.setString(3,testCaseIDandDetailsBean.getMethod_name()) ; ps.setString(4,testCaseIDandDetailsBean.getMethodReplacement()) ; ((OraclePreparedStatement)ps).setARRAY (5, newArray); ps.execute (); 

Iam trying to execute this code but again Iam getting errors as follows:

 java.sql.SQLException: Invalid column index at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208) at oracle.jdbc.driver.OraclePreparedStatement.setARRAYInternal(OraclePreparedStatement.java:5906) at oracle.jdbc.driver.OraclePreparedStatement.setARRAY(OraclePreparedStatement.java:5898) at implementation.TestCaseIDandDetailsDAOImpl.addTestCaseIDandDetails(TestCaseIDandDetailsDAOImpl.java:54) at implementation.TestCaseIDandDetailsDAOImpl.main(TestCaseIDandDetailsDAOImpl.java:134) 

my tablescripts are:

 CREATE or replace TYPE METHODARGDATATYPE_VARRAY AS VARRAY(20) OF varchar2(30); create table TestCaseIDDetails( testcaseID varchar2(20) primary key, classname varchar2(20) not null, methodname varchar2(20) not null, MethodReplacement char(2) check(MethodReplacement in ('y','n')), MethodArgDataType METHODARGDATATYPE_VARRAY); Create sequence TestCaseID_sequence minvalue 1 start with 1 increment by 1 ; 
1
  • but after these modifications I am getting error as bellow: ORA-12899: value too large for column "ER706221"."TESTCASEIDDETAILS"."METHODREPLACEMENT" (actual: 10, maximum: 2) Commented Oct 30, 2015 at 7:58

2 Answers 2

3

The indexes should correspond to the indexes of the question mark placeholders in the prepared statement, not to the column numbers in the table. The index of the first question mark is 1, the second is 2, and so on. Your indexes are all off by one, should be 1 2 3 4 instead of 2 3 4 5.

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

2 Comments

but after these modifications I am getting error as bellow: ORA-12899: value too large for column "ER706221"."TESTCASEIDDETAILS"."METHODREPLACEMENT" (actual: 10, maximum: 2)
Verify the value of testCaseIDandDetailsBean.getMethodReplacement(). It seems the value is not what you expect: a string of length 10
1

Change the following

ps.setString(2,testCaseIDandDetailsBean.getClass_name()) ; ps.setString(3,testCaseIDandDetailsBean.getMethod_name()) ; ps.setString(4,testCaseIDandDetailsBean.getMethodReplacement()) ; ((OraclePreparedStatement)ps).setARRAY (5, newArray); 

to

ps.setString(1,testCaseIDandDetailsBean.getClass_name()) ; ps.setString(2,testCaseIDandDetailsBean.getMethod_name()) ; ps.setString(3,testCaseIDandDetailsBean.getMethodReplacement()) ; ((OraclePreparedStatement)ps).setARRAY (4, newArray); 

6 Comments

@NagaumadeviPalaparthy please dont change the question other wise my answer will be void. Keep the original question and post another question for your new problem.
sry I had put it back to original question
but after these modifications I am getting error as bellow: ORA-12899: value too large for column "ER706221"."TESTCASEIDDETAILS"."METHODREPLACEMENT" (actual: 10, maximum: 2)
@NagaumadeviPalaparthy earlier your error was different and this time your error is different. So this means this is a different question
yes its different question but i cant post until 3 hrs and i need to do it immediately can u help me please?/
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.