create or replace
TYPE Employee AS OBJECT
(
ID NUMBER,
NAME VARCHAR2(100 BYTE)
)
create or replace
TYPE Employee_TABLE
AS TABLE OF Employee;
有存储过程如下:
create or replace
PROCEDURE Employee_Process
(
FK_LIST IN Employee_TABLE
) AS
BEGIN
FOR I IN 1..FK_LIST.COUNT LOOP
--操作
END LOOP;
COMMIT;
END Employee_Process;
自定义handler
import ...
//这个jdbcType对应mapper文件中对应的jdbcType
//如果此处不做配置也可以在mybatis-config.xml中配置
@MappedJdbcTypes(JdbcType.ARRAY)
public class MyHandler implements TypeHandler {
public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException {
//获取OracleConnection
C3P0NativeJdbcExtractor cp30NativeJdbcExtractor = (C3P0NativeJdbcExtractor) new C3P0NativeJdbcExtractor();
OracleConnection oracleConn=(OracleConnection)cp30NativeJdbcExtractor.getNativeConnection(ps.getConnection());
//这个parameter就是我们自己在mapper中传入的参数
List<Object> dto = (ArrayList<Object>) parameter;
StructDescriptor sd = new StructDescriptor("Employee",oracleConn);
STRUCT[] result = new STRUCT[dto.size()];
for(int index = 0; index < dto.size(); index++){
AccountCommissionDetailDto d = dto.get(index);
Object[] o = new Object[3];
o[0] = new Long("1"); //id
o[1] = new String("aaa"); //name
result[index] = new STRUCT(sd,oracleConn,o);
}
ArrayDescriptor des_Employee_TABLE = ArrayDescriptor.createDescriptor("Employee_TABLE",oracleConn);
ARRAY oracle_array = new ARRAY(des_Employee_TABLE,oracleConn,result);
ps.setArray(i, oracle_array);
}
public Object getResult(ResultSet rs, String columnName) throws SQLException {
log.error("no result!");
return null;
}
public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
log.error("no result!");
return null;
}
}