100分!!关于Oracle插入clob的问题,急!!在线等,解答立马结帐!
Oracle数据库中有个clob字段,事先执行了插入empty_clob()值,但是我在调用:
PreparedStatement st = conn.prepareStatement( "SELECT content FROM topic WHERE tid=? FOR UPDATE ");
st.setInt(1,tid);
ResultSet rs = st.executeQuery();
rs.next();
rs.next()返回的是一个false。。
但是我在sqlplus里执行上面的SELECT查询语句,能得到的结果啊!!
在线盼高人解答!
------解决方案--------------------那就把分给大家分了吧,免得影响lz的信誉。
------解决方案--------------------呵呵!我也来蹭分!今天运气这么好阿!
------解决方案--------------------哈哈 UP
------解决方案--------------------jf
------解决方案--------------------这是我写的一个例子,里面有关于clob的插入的解决方法
Statement stmt = this.getStatement();
if(stmt == null)return;
//先插入一个值到数据表中,其中IMPORTDATA是clob类型,先插入一个 //empty_clob()
int n = 0;
StringBuffer strSql = new StringBuffer();
strSql.append( "insert into TXTFILEIMPORT(IMPORTDATA,DATADATE,DATAFILENAME) values ")
.append( "( " + "empty_clob() " + ",To_Date( ' " + this.getFormat().format(date)+ " ', 'yyyy-mm-dd '), ' " + fileName + " ') ");
log.info(strSql.toString());
try {
n = stmt.executeUpdate(strSql.toString());
} catch (
SQLException e) {
log.error(e);
return;
}
if(n <= 0) {
log.error( "insert failed!!! ");
return;
}
//更新数据表中clob的值
strSql.delete(0, strSql.length());
strSql.append( "select importData from txtFileImport where id = " + n1 + " for update ");
try {
rs = stmt.executeQuery(strSql.toString());
if(rs.next()) {
oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob( "importData ");
Writer outStream = clob.setCharacterStream(0);
char[] c = str.toCharArray();
try {
outStream.write(c, 0, c.length);
outStream.flush();
outStream.close();
} catch (
IOException e) {
log.error( "The error is: " + e );
log.error( "import txt file data fail ");
return;
}
conn.commit();
rs.close();
stmt.close();
conn.close();
}
} catch (SQLException e) {
log.error( "The error is: " + e );
log.error( "import txt file data fail ");
return;
} finally {
rs = null;
stmt = null;
conn = null;
}
log.info( "Data import successful! ");
}
------解决方案--------------------上面的说没错哦。
------解决方案--------------------jf
------解决方案--------------------应该用:setAsciiStream(1,sbin,xxnr.length());
搂主用setString()试试插入60000个字节以上的内容看看