我遇到了在oracle中插入一个clob字段,插入不进去?能跟我说说要怎么去做嘛?我用Ibatis做的?
2个回答
2011-09-29
展开全部
jdbc我会,hibernate我也会,但ibatis还真不会,写个jdbc的给你参考参考吧
Connection conn = jdbcTemplate.getDataSource().getConnection();
conn.setAutoCommit(false);
PreparedStatement pstm = conn.prepareStatement(sql.toString());
pstm.executeUpdate();
ResultSet rs = pstm.executeQuery("select t.file from files t where t.name='aa'");
while(rs.next()) {
CLOB clob = (CLOB) rs.getClob("file");
BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());
byte[] bytes = fileString.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
InputStreamReader input = new InputStreamReader(bais);
BufferedReader bf = new BufferedReader(input);
String temp = null;
while((temp=bf.readLine())!=null) {
out.write(temp);
out.flush();
}
bf.close();
out.close();
}
conn.commit();
其中file字段是files表中一个clob类型的字段,这里存的是字符串
Connection conn = jdbcTemplate.getDataSource().getConnection();
conn.setAutoCommit(false);
PreparedStatement pstm = conn.prepareStatement(sql.toString());
pstm.executeUpdate();
ResultSet rs = pstm.executeQuery("select t.file from files t where t.name='aa'");
while(rs.next()) {
CLOB clob = (CLOB) rs.getClob("file");
BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());
byte[] bytes = fileString.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
InputStreamReader input = new InputStreamReader(bais);
BufferedReader bf = new BufferedReader(input);
String temp = null;
while((temp=bf.readLine())!=null) {
out.write(temp);
out.flush();
}
bf.close();
out.close();
}
conn.commit();
其中file字段是files表中一个clob类型的字段,这里存的是字符串
来自:求助得到的回答
展开全部
插补进去,报什么错?
至少把错贴上来啊。
至少把错贴上来啊。
追问
我的数据是插进去了,但是数据小的话就OK,数据长度长的话就报错
Caused by: java.sql.SQLException: 数据大小超出此类型的最大值: 59348at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)at (字数过多以下省略...)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询