ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

oracle

2019-03-22 17:41:02  阅读:284  来源: 互联网

标签:java get listData sql oracle import SoInLineVO


一、
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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有