java读取oracle大文本
来源:互联网 发布:最火的网络歌曲2016 编辑:程序博客网 时间:2024/06/06 05:51
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();
}
}
}
- java读取oracle大文本
- java读取oracle大文本
- JAVA读取大文本
- java保存读取文本oracle
- Java 大文本多线程高效读取
- android 大文本读取
- Java JDBC读取大文本类型数据(CLOB)
- java读取txt文本
- java读取 excel 文本
- java读取文本文档
- Java读取文本配置文件
- java读取文本
- java文本读取写入
- java读取文本
- Java读取文本内容
- Java查询大文本
- Java查询大文本
- PHP大数据文本读取与写入
- JAVA完全控制Oracle中BLOB CLOB说明 (JDBC,JNDI )
- 好好工作
- ResultSetMete用法实例
- Lesson 3 Sorry,Sir
- java下载的servlet
- java读取oracle大文本
- SQL TOP N 分组统计
- javascript入门系列演示·三种弹出对话框的用法实例
- native2ascii用法
- Lesson 1 Excuse me
- C# .Net中的类型转换
- Ajax简介
- 今天执行进入状态
- properties例子