数据库
首页 > 数据库> > oracle

oracle

作者:互联网

一、
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import com.sekorm.warehouse.common.config.Global;
import com.sekorm.warehouse.modules.entity.SoInLineVO;

@SuppressWarnings("rawtypes")
public class SoListHandler extends BaseTypeHandler {

private static final String url = Global.getConfig("jdbc.url");

private static final String username = Global.getConfig("jdbc.username");

private static final String password = Global.getConfig("jdbc.password");

@SuppressWarnings("unchecked")
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Object o, JdbcType jdbcType)
throws SQLException {
// TODO Auto-generated method stub
Connection conn = null;
try {
if (null != o) {
List<SoInLineVO> list = (ArrayList<SoInLineVO>) o;
conn = DriverManager.getConnection(url, username, password);
// 这里必须得用大写,而且必须要引入一个包,如果不引入这个包的话字符串无法正常转换,包是:orai18n.jar
ARRAY array = getArray(conn, "SECOM_CBSCS_SO_PICK_TYPE",
"SECOM_CBSCS_SO_PICK_TYPE_T", list);
ps.setArray(i, array);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != conn) {
conn.close();
}
}
}

private ARRAY getArray(Connection con, String OracleObj, String Oraclelist, List listData)
throws Exception {
ARRAY array = null;
ArrayDescriptor desc = ArrayDescriptor.createDescriptor(Oraclelist, con);
STRUCT[] structs = new STRUCT[listData.size()];

if (listData != null && listData.size() > 0) {
StructDescriptor structdesc = new StructDescriptor(OracleObj, con);
for (int i = 0; i < listData.size(); i++) {
Object[] result = { ((SoInLineVO) listData.get(i)).getPickId(),
((SoInLineVO) listData.get(i)).getStoreOutNo(),
((SoInLineVO) listData.get(i)).getDetailId(),
((SoInLineVO) listData.get(i)).getOutType(),
((SoInLineVO) listData.get(i)).getIsPrint(),
((SoInLineVO) listData.get(i)).getPrintRemark(),
((SoInLineVO) listData.get(i)).getCustomerId(),
((SoInLineVO) listData.get(i)).getWarehouseCode(),
((SoInLineVO) listData.get(i)).getConsignee(),
((SoInLineVO) listData.get(i)).getDeliveryAddress(),
((SoInLineVO) listData.get(i)).getDeliveryDate(),
((SoInLineVO) listData.get(i)).getOutDate(),
((SoInLineVO) listData.get(i)).getCustomerOrderNo(),
((SoInLineVO) listData.get(i)).getCustomerPartNo(),
((SoInLineVO) listData.get(i)).getProPartNo(),
((SoInLineVO) listData.get(i)).getBrand(),
((SoInLineVO) listData.get(i)).getQty(),
((SoInLineVO) listData.get(i)).getSubInventory(),
((SoInLineVO) listData.get(i)).getDateCode(),
((SoInLineVO) listData.get(i)).getOriginDateCode(),
((SoInLineVO) listData.get(i)).getArea(),
((SoInLineVO) listData.get(i)).getBoxNum(),
((SoInLineVO) listData.get(i)).getNetWeight(),
((SoInLineVO) listData.get(i)).getGrossWeight(),
((SoInLineVO) listData.get(i)).getBoxSize(),
((SoInLineVO) listData.get(i)).getLineRemark(),
((SoInLineVO) listData.get(i)).getReceiveDate(),
((SoInLineVO) listData.get(i)).getStatus() };
structs[i] = new STRUCT(structdesc, con, result);
}
array = new ARRAY(desc, con, structs);
} else {
array = new ARRAY(desc, con, structs);
}

return array;
}

@Override
public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {
return null;
}

@Override
public Object getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
// TODO Auto-generated method stub
return null;
}

@Override
public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
// TODO Auto-generated method stub
return null;
}

}
二、xml
<parameterMap type="java.util.Map" id="soMap">
<parameter property="p_so_pick" jdbcType="ARRAY"
javaType="java.util.List" mode="IN" typeHandler="xx.xxx.SoListHandler"/>
<parameter property="x_flag" jdbcType="VARCHAR"
javaType="java.lang.String" mode="OUT" />
<parameter property="x_msg" jdbcType="VARCHAR"
javaType="java.lang.String" mode="OUT" />
</parameterMap>

<select id="checkInInfo" statementType="CALLABLE" parameterMap="soMap" resultType="java.util.Map">
<![CDATA[
{call xxx_edi_pkg.ins_cbscs_so_pick(?,?,?)}
]]>
</select>

CREATE OR REPLACE TYPE SECOM_CBSCS_PO_in_D_TYPE AS OBJECT
(
detail_id NUMBER,
way_bill VARCHAR2(100),
header_id NUMBER,
warehouse_code VARCHAR2(100),
sub_inventory VARCHAR2(100),
item_code VARCHAR2(240),
brand VARCHAR2(240),
date_code VARCHAR2(100),
origin_date_code VARCHAR2(100),
quantity NUMBER
)

CREATE OR REPLACE TYPE SECOM_CBSCS_PO_IN_D_TYPE_T AS TABLE OF SECOM_CBSCS_PO_IN_D_TYPE

标签:java,get,listData,sql,oracle,import,SoInLineVO
来源: https://www.cnblogs.com/albert-think/p/10579728.html