long转string mybatis_Spring+Mybatis类型转换的问题,oracle数据库中有一个clob类型,怎样在查询以后转换为String类型?...

本文介绍了一种在Java中处理大型CLOB对象的方法,通过将其转换为byte[]数组进行操作,有效解决了大对象读取的问题。此外,还提供了一种直接在网页上展示大对象内容的技术方案。
摘要由CSDN通过智能技术生成

展开全部

首先你的思路就错的,不可能转换成string把大对象读进byte[]

public byte[] function(Connection connection,所需参数) throws EMPException{

PreparedStatement ps = null;

ResultSet rs = null;

byte[] data = null;

try {

.....省略

while (rs.next()) {

oracle.sql.CLOB  clob= (oracle.sql.CLOB) rs.getClob("大对象的32313133353236313431303231363533e78988e69d8331333332623330字段名");

InputStream inStream =clob.getBinaryStream();

long nLen = clob.length();

int nSize = (int) nLen;

data = new byte[nSize];

inStream.read(data);

inStream.close();

connection.commit();

}

} catch (SQLException e) {

EMPLog.log(this.getClass().getName(), EMPLog.INFO, 0, e.toString());

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

try {

if (rs != null) {

rs.close();

rs = null;

}

if (ps != null) {

ps.close();

ps = null;

}

} catch (SQLException e) {

EMPLog.log(this.getClass().getName(), EMPLog.INFO, 0, e

.toString());

}

}

return data;

}

2.直接在页面上将对象读到页面上

response.setContentType("image/jpg");

response.setHeader("Content-Transfer-Encoding","base64");

ServletOutputStream toClient = response.getOutputStream();

out.clear();

out = pageContext.pushBody();

ByteArrayInputStream in = new ByteArrayInputStream(data);

int len;

byte[] buf = new byte[1024];

while ((len = in.read(buf, 0, 1024)) != -1) {

toClient.write(buf, 0, len);

}

toClient.flush();

toClient.close();

%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值