I am trying to pass Java array to PLSQL stored procedure, however when I am trying to execute, I am getting the following exception
java.sql.SQLException: Inconsistent java and sql object types
My DAO class code snippet
List projectList = new ArrayList();
public void saveRecord(List<Project> project)
throws DatabaseException,SQLException {
for (Project items: project) {
insertRecord(items);
}
}
private void insertRecord(Project project) throws SQLException {
projectList.add(project);
callablestatement =
(OracleCallableStatement)connection.prepareCall("{call my_proc(?)}");
Object[] project1 = projectList.toArray();
StructDescriptor projectTypeDesc = StructDescriptor.createDescriptor("MY_TYPE",
conn);
STRUCT structProject1 = new STRUCT(projectTypeDesc,
connection, project);
STRUCT[] structArrayOfProjects = {structProject1};
ArrayDescriptor projectTypeArrayDesc = ArrayDescriptor.createDescriptor
("MY_ARRAY", connection);
ARRAY arrayOfProjects = new ARRAY(projectTypeArrayDesc, connection,
structArrayOfProjects);// error in this line
callablestatement.setArray(1, arrayOfProjects);
How can I resolve this issue?
Edit 1
If I do as
Object[] project1 = new Object[]{project.getProjectId(), project.getProjectTitle()};
then no errors and records are inserted into table.
However if I would do as
Object[] project1 = projectList.toArray();
then exception is thrown Inconsistent java and sql object types