java在weblogic下读写clob的问题??? http://blog.csdn.net/sanuxd/archive/2004/09/09/blob.aspx 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一、 CLOB对象的存取1、往数据库中插入一个新的CLOB对象public static void clobInsert(String infile) throws Exception{/* 设定不自动提交 */boolean defaultCommit = conn.getAutoCommit();conn.setAutoCommit(false);try {/* 插入一个空的CLOB对象 */stmt.executeUpdate("INSERT INTO TEST_CLOB VALUES ('111', EMPTY_CLOB())");/* 查询此CLOB对象并锁定 */ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");while (rs.next()) {/* 取出此CLOB对象 */oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");/* 向CLOB对象中写入数据 */BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());BufferedReader in = new BufferedReader(new FileReader(infile));int c;while ((c=in.read())!=-1) {out.write(c);}in.close();out.close();}/* 正式提交 */conn.commit();} catch (Exception ex) {/* 出错回滚 */conn.rollback();throw ex;}/* 恢复原提交状态 */conn.setAutoCommit(defaultCommit);}2、修改CLOB对象(是在原CLOB对象基础上进行覆盖式的修改)public static void clobModify(String infile) throws Exception{/* 设定不自动提交 */boolean defaultCommit = conn.getAutoCommit();conn.setAutoCommit(false);try {/* 查询CLOB对象并锁定 */ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");while (rs.next()) {/* 获取此CLOB对象 */oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");/* 进行覆盖式修改 */BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());BufferedReader in = new BufferedReader(new FileReader(infile));int c;while ((c=in.read())!=-1) {out.write(c);}in.close();out.close();}/* 正式提交 */conn.commit();} catch (Exception ex) {/* 出错回滚 */conn.rollback();throw ex;}/* 恢复原提交状态 */conn.setAutoCommit(defaultCommit);} 3、替换CLOB对象(将原CLOB对象清除,换成一个全新的CLOB对象)public static void clobReplace(String infile) throws Exception{/* 设定不自动提交 */boolean defaultCommit = conn.getAutoCommit();conn.setAutoCommit(false);try {/* 清空原CLOB对象 */stmt.executeUpdate("UPDATE TEST_CLOB SET CLOBCOL=EMPTY_CLOB() WHERE ID='111'");/* 查询CLOB对象并锁定 */ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");while (rs.next()) {/* 获取此CLOB对象 */oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");/* 更新数据 */BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());BufferedReader in = new BufferedReader(new FileReader(infile));int c;while ((c=in.read())!=-1) {out.write(c);}in.close();out.close();}/* 正式提交 */conn.commit();} catch (Exception ex) {/* 出错回滚 */conn.rollback();throw ex;}/* 恢复原提交状态 */conn.setAutoCommit(defaultCommit);}4、CLOB对象读取public static void clobRead(String outfile) throws Exception{/* 设定不自动提交 */boolean defaultCommit = conn.getAutoCommit();conn.setAutoCommit(false);try {/* 查询CLOB对象 */ResultSet rs = stmt.executeQuery("SELECT * FROM TEST_CLOB WHERE ID='111'");while (rs.next()) {/* 获取CLOB对象 */oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");/* 以字符形式输出 */BufferedReader in = new BufferedReader(clob.getCharacterStream());BufferedWriter out = new BufferedWriter(new FileWriter(outfile));int c;while ((c=in.read())!=-1) {out.write(c);}out.close();in.close();}} catch (Exception ex) {conn.rollback();throw ex;}/* 恢复原提交状态 */conn.setAutoCommit(defaultCommit);} public String clobsubread(String table,String wherestr,String field){ String instr=""; // DbConn dbCon = new DbConn(); try { //conn= dbCon.getConnection(); /* 查询此CLOB对象并锁定 */ stm=conn.createStatement(); sql="SELECT "+field+" FROM "+table+" "+wherestr+" FOR UPDATE"; System.out.println("clobsql:"+sql); rs = stm.executeQuery(sql); //stm.executeUpdate(this.sql); while (rs.next()) { /* 取出此CLOB对象 */ //weblogic.jdbc.vendor.oracle.OracleThinClob clob = (weblogic.jdbc.vendor.oracle.OracleThinClob)rs.getClob(1); java.sql.Clob clob = (java.sql.Clob)rs.getClob(1); StringWriter strw= new StringWriter(); /* 以字符形式输出 */ BufferedReader in = new BufferedReader(clob.getCharacterStream()); BufferedWriter out = new BufferedWriter(strw); int c; while ((c=in.read())!=-1) { out.write(c); } out.write(instr); out.close(); in.close(); } /* 正式提交 */ conn.commit(); } catch (Exception ex) { /* 出错回滚 */ try{ conn.rollback(); }catch(Exception e){} System.out.println(ex.getMessage()); ex.printStackTrace(); } System.out.println("instr:"+instr.toString()); return instr; }看看我的这段代码为什么不行????instr总是为"" ORACLE JOB 装完10g,无法在web访问enterprise manager 如何提取数据库更改的元操作?(可能与日志有关) Oracle在触发器语句中如何取得当前用户???100分,在线等!!!! imp导入出错:不是有效的导出文件,标题验证失败 请教如何在.net程序里实现远程备份还原ORACLE数据库 关于大数据量的插入性能问题 Oracle里没有top的?那么能什么来代替? 如何从归档日志中恢复某张表的数据? 问个ORACLE客户端的问题 动态sql初级问题! 我如果在本地没有oracle客户端的情况下,如何通过服务器的ip连接到数据库呢?开发语言c#,盼高手解答,在线等待
{
/* 设定不自动提交 */
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);try {
/* 插入一个空的CLOB对象 */
stmt.executeUpdate("INSERT INTO TEST_CLOB VALUES ('111', EMPTY_CLOB())");
/* 查询此CLOB对象并锁定 */
ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");
while (rs.next()) {
/* 取出此CLOB对象 */
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");
/* 向CLOB对象中写入数据 */
BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());
BufferedReader in = new BufferedReader(new FileReader(infile));
int c;
while ((c=in.read())!=-1) {
out.write(c);
}
in.close();
out.close();
}
/* 正式提交 */
conn.commit();
} catch (Exception ex) {
/* 出错回滚 */
conn.rollback();
throw ex;
}/* 恢复原提交状态 */
conn.setAutoCommit(defaultCommit);
}2、修改CLOB对象(是在原CLOB对象基础上进行覆盖式的修改)public static void clobModify(String infile) throws Exception
{
/* 设定不自动提交 */
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);try {
/* 查询CLOB对象并锁定 */
ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");
while (rs.next()) {
/* 获取此CLOB对象 */
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");
/* 进行覆盖式修改 */
BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());
BufferedReader in = new BufferedReader(new FileReader(infile));
int c;
while ((c=in.read())!=-1) {
out.write(c);
}
in.close();
out.close();
}
/* 正式提交 */
conn.commit();
} catch (Exception ex) {
/* 出错回滚 */
conn.rollback();
throw ex;
}/* 恢复原提交状态 */
conn.setAutoCommit(defaultCommit);
} 3、替换CLOB对象(将原CLOB对象清除,换成一个全新的CLOB对象)public static void clobReplace(String infile) throws Exception
{
/* 设定不自动提交 */
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);try {
/* 清空原CLOB对象 */
stmt.executeUpdate("UPDATE TEST_CLOB SET CLOBCOL=EMPTY_CLOB() WHERE ID='111'");
/* 查询CLOB对象并锁定 */
ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");
while (rs.next()) {
/* 获取此CLOB对象 */
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");
/* 更新数据 */
BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());
BufferedReader in = new BufferedReader(new FileReader(infile));
int c;
while ((c=in.read())!=-1) {
out.write(c);
}
in.close();
out.close();
}
/* 正式提交 */
conn.commit();
} catch (Exception ex) {
/* 出错回滚 */
conn.rollback();
throw ex;
}/* 恢复原提交状态 */
conn.setAutoCommit(defaultCommit);
}4、CLOB对象读取public static void clobRead(String outfile) throws Exception
{
/* 设定不自动提交 */
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);try {
/* 查询CLOB对象 */
ResultSet rs = stmt.executeQuery("SELECT * FROM TEST_CLOB WHERE ID='111'");
while (rs.next()) {
/* 获取CLOB对象 */
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");
/* 以字符形式输出 */
BufferedReader in = new BufferedReader(clob.getCharacterStream());
BufferedWriter out = new BufferedWriter(new FileWriter(outfile));
int c;
while ((c=in.read())!=-1) {
out.write(c);
}
out.close();
in.close();
}
} catch (Exception ex) {
conn.rollback();
throw ex;
}/* 恢复原提交状态 */
conn.setAutoCommit(defaultCommit);
}
String instr="";
// DbConn dbCon = new DbConn();
try { //conn= dbCon.getConnection();
/* 查询此CLOB对象并锁定 */
stm=conn.createStatement();
sql="SELECT "+field+" FROM "+table+" "+wherestr+" FOR UPDATE";
System.out.println("clobsql:"+sql);
rs = stm.executeQuery(sql);
//stm.executeUpdate(this.sql); while (rs.next()) { /* 取出此CLOB对象 */
//weblogic.jdbc.vendor.oracle.OracleThinClob clob = (weblogic.jdbc.vendor.oracle.OracleThinClob)rs.getClob(1);
java.sql.Clob clob = (java.sql.Clob)rs.getClob(1);
StringWriter strw= new StringWriter();
/* 以字符形式输出 */
BufferedReader in = new BufferedReader(clob.getCharacterStream());
BufferedWriter out = new BufferedWriter(strw);
int c;
while ((c=in.read())!=-1) {
out.write(c);
}
out.write(instr);
out.close();
in.close();
} /* 正式提交 */ conn.commit(); } catch (Exception ex) { /* 出错回滚 */
try{
conn.rollback();
}catch(Exception e){}
System.out.println(ex.getMessage());
ex.printStackTrace();
}
System.out.println("instr:"+instr.toString());
return instr; }看看我的这段代码为什么不行????instr总是为""