1、xxxTableTypeHandler.java
2、xxxDTO.java
3、DbSchema.java
package xxx.util;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;
import org.apache.log4j.Logger;
import weblogic.jdbc.extensions.WLConnection;
import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
import com.xx.xxxDTO;
public class xxxTableTypeHandler implements TypeHandlerCallback {
Logger logger = Logger.getLogger(this.getClass());
public void setParameter(ParameterSetter setter, Object obj)
throws SQLException {
if(obj == null){
setter.setNull(Types.ARRAY);
}else{
Connection conn = ((WLConnection)setter.getPreparedStatement().getConnection()).getVendorConnection();
StructDescriptor structDesc = StructDescriptor.createDescriptor(DbSchema.getInstance().getDbUser()+".xxx_RECORD_TYPE", conn);
ArrayDescriptor arrayDesc = ArrayDescriptor.createDescriptor(DbSchema.getInstance().getDbUser()+".xxx_TABLE_TYPE", conn);
List bjList = (List)obj;
Object[] arrayElements = new Object[objList.size()];
for (int i=0; i
Object[] structAttributes = new Object[]{xxxDTO.getHOST_RET_CODE(),
xxxDTO.getCURR_TYPE(),
xxxDTO.getCURR_NAME(),
new Integer(xxxDTO.getUSD_RATE()),
new Integer(xxxDTO.getRMB_RATE()),
new Integer(xxxDTO.getBASE_PRICE()),
new Integer(xxxDTO.getBUY_PRICE()),
new Integer(xxxDTO.getSELL_PRICE()),
new Integer(xxxDTO.getCASH_BUY_PRICE()),
new Integer(xxxDTO.getMOVE_PRICE()),
new Integer(xxxDTO.getPAY_PRICE()),
xxxDTO.getEXCHANGE_DATE()};
STRUCT struct = new STRUCT(structDesc, conn, structAttributes);
arrayElements[i] = struct;
}
ARRAY array = new ARRAY(arrayDesc, conn, arrayElements);
setter.setArray(array);
}
}
public Object getResult(ResultGetter arg0) throws SQLException {
return null;
}
public Object valueOf(String arg0) {
return null;
}
}
===ibatis sql map=======
{ call xxx_pkg.INSERT_xxx_PROC(?,?,?) }
=======biz===
=====dao====
condition.put("IN_xxx",list);
getSqlMapClient().startTransaction();
logger.debug("begin2:"+System.currentTimeMillis());
long t1 = System.currentTimeMillis();
getSqlMapClientTemplate().queryForObject("a3",condition);
getSqlMapClient().commitTransaction();
===============blob====
PROCEDURE xxx1(in_image IN BLOB,
out_retcode OUT VARCHAR2,
out_message OUT VARCHAR2) IS
BEGIN
insert into blob_test(id,image) values (5,in_image);
commit;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
out_retcode := '-1';
out_message := to_char(sqlcode)||'-'||substr(sqlerrm,1,200);
RETURN;
END xxx1;
PROCEDURE xxx2(out_image OUT BLOB,
out_retcode OUT VARCHAR2,
out_message OUT VARCHAR2) IS
BEGIN
out_retcode := '0';
select image into out_image from blob_test where id = 5;
EXCEPTION
WHEN OTHERS THEN
out_retcode := '-1';
out_message := to_char(sqlcode)||'-'||substr(sqlerrm,1,200);
RETURN;
END xxx2;
<!-- insert blob -->
{ call xx_pkg.bcoms_xx(?,?,?) }
Map condition = new HashMap();
File file = new File("d:\\11.jpg");
FileInputStream fis;
try {
fis = new FileInputStream(file);
byte[] image = new byte[fis.available()];
fis.read(image);
fis.close();
condition.put("in_image", image);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
getSqlMapClientTemplate().queryForObject("aa1",condition);
String retCode = (String) condition.get("out_retcode");
<!-- read blob -->
{ call xx_pkg.xx(?,?,?) }
getSqlMapClientTemplate().queryForObject("aa2",condition);
logger.debug("blob length:"+((byte[])condition.get("out_image")).length);
File file = new File("c:\\22.jpg");
try {
FileOutputStream fos = new FileOutputStream(file);
fos.write((byte[])condition.get("out_image"));
fos.flush();
fos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/95429/viewspace-432965/ ,如需转载,请注明出处,否则将追究法律责任。