java 高效读取oracle,java读取oracle大文本

public class getColb{

public void getclob(){

try{

DataSource dao=(DataSource)ComponentFactory.getBean("dataSource");

Connection con=dao.getConnection();

con.setAutoCommit(false);

PreparedStatement ps=con.prepareStatement("update yc_news set news_title=?,news_content=?,news_secondtitle=?,news_summary=?,news_author=?,news_source=?," +

"news_annex=?,news_time=?,news_open=?,news_keywords=?,news_approve=?,istop=?,browsenum=?,news_comment=?,news_refuse=?,news_auditor=? where news_id=?");

ps.setString(1,news.getNewstitle());

ps.setClob(2,CLOB.empty_lob());

ps.setString(3,news.getNewssecondtitle());

ps.setString(4,news.getNewssummary());

ps.setString(5,news.getNewsauthor());

ps.setString(6,news.getNewssource());

ps.setString(7,news.getNewsannex());

if(news.getNewstime()==null||"".equals(news.getNewstime())) {

Timestamp ctim=new Timestamp((new java.util.Date()).getTime());

news.setNewstime(ctim);

}

ps.setTimestamp(8,news.getNewstime());

ps.setString(9,news.getNewsopen());

ps.setString(10,news.getNewskeywords());

ps.setString(11,news.getNewsapprove());

ps.setInt(12,news.getIstop());

ps.setInt(13,news.getBrowsenum());

ps.setString(14,news.getNewscomment());

ps.setString(15,news.getNewsrefuse());

ps.setString(16,news.getNewsauditor());

ps.setInt(17,news.getNewsid());

ps.executeUpdate();

ps.close();

ps=con.prepareStatement("select news_content from yc_news where news_id=? for update");

ps.setInt(1,news.getNewsid());

ResultSet rs=ps.executeQuery();

if(rs.next()){

LobPros.modifyClob(rs,1,news.getNewscontent());

}

rs.close();

ps.close();

con.commit();

con.close();

}

catch(Exception e){

e.printStackTrace();

}

}

}

public class LobPros { public static String readClob(ResultSet rs,String fname)throws SQLException{  try{   if(rs==null) throw new SQLException("ResultSet Don't Be Ready!");   if(fname==null||fname.length()==0)throw new SQLException("fname couldn't be null");   oracle.sql.CLOB clob=(oracle.sql.CLOB)rs.getClob(fname);   BufferedReader in=new BufferedReader(clob.getCharacterStream());   StringBuffer sbRet=new StringBuffer(4096);   int c;   while((c=in.read())!=-1){    sbRet.append((char)c);   }   in.close();   return sbRet.toString();  }  catch(Exception e){   e.printStackTrace();   return null;  } } public static String readClob(ResultSet rs,int i)throws SQLException{  try{   if(rs==null) throw new SQLException("ResultSet Don't Be Ready!");   oracle.sql.CLOB clob=(oracle.sql.CLOB)rs.getClob(i);   BufferedReader in=new BufferedReader(clob.getCharacterStream());   StringBuffer sbRet=new StringBuffer(4096);   int c;   while((c=in.read())!=-1){    sbRet.append((char)c);   }   in.close();   return sbRet.toString();  }  catch(Exception e){   e.printStackTrace();   return null;  } } public static void insertClob(ResultSet rs,String fname,String sValue)throws SQLException{  try{   if(rs==null) throw new SQLException("ResultSet Don't Be Ready!");   if(fname==null||fname.length()==0)throw new SQLException("fname couldn't be null");   CLOB clob=(CLOB)rs.getClob(fname);   BufferedWriter out=new BufferedWriter(clob.getCharacterOutputStream());   BufferedReader in=new BufferedReader(new StringReader(sValue));   int c;   while((c=in.read())!=-1){    out.write(c);   }   in.close();   out.close();  }  catch(Exception e){   e.printStackTrace();  } } public static void insertClob(ResultSet rs,int i,String sValue)throws SQLException{  try{   if(rs==null) throw new SQLException("ResultSet Don't Be Ready!");   CLOB clob=(CLOB)rs.getClob(i);   java.io.Writer pw=clob.getCharacterOutputStream();   pw.write(sValue);   pw.flush();   pw.close();  }  catch(Exception e){   e.printStackTrace();  } } public static void modifyClob(ResultSet rs,String fname,String sValue)throws SQLException{  try{   if(rs==null) throw new SQLException("ResultSet Don't Be Ready!");   if(fname==null||fname.length()==0)throw new SQLException("fname couldn't be null");   CLOB clob=(CLOB)rs.getClob(fname);   BufferedWriter out=new BufferedWriter(clob.getCharacterOutputStream());   BufferedReader in=new BufferedReader(new StringReader(sValue));   int c;   while((c=in.read())!=-1){    out.write(c);   }   in.close();   out.close();  }  catch(Exception e){   e.printStackTrace();  } } public static void modifyClob(ResultSet rs,int i,String sValue)throws SQLException{  try{   if(rs==null) throw new SQLException("ResultSet Don't Be Ready!");   CLOB clob=(CLOB)rs.getClob(i);   java.io.Writer pw=clob.getCharacterOutputStream();   pw.write(sValue);   pw.flush();   pw.close();  }  catch(Exception e){   e.printStackTrace();  } }}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值