我正在尝试将 Java 数组传递给 PLSQL 存储过程,但是当我尝试执行时,出现以下异常
java.sql.SQLException: Inconsistent java and sql object types
我的 DAO 类代码片段
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);
我该如何解决这个问题?
编辑 1
如果我这样做
Object[] project1 = new Object[]{project.getProjectId(), project.getProjectTitle()};
然后没有错误和记录被插入到表中。
但是,如果我这样做
Object[] project1 = projectList.toArray();
然后抛出异常Inconsistent java and sql object types