社区
Java EE
帖子详情
散分200,顺带问个问题。
duye
2006-10-31 09:14:50
主要是散分。
问题为:
j2ee应用中如何读写oracle数据库中的clob或者blob字段,要求是自己写过的例子,网上例子我找过,我们的开发人员都说不成,谢谢。
...全文
980
101
打赏
收藏
散分200,顺带问个问题。
主要是散分。 问题为: j2ee应用中如何读写oracle数据库中的clob或者blob字段,要求是自己写过的例子,网上例子我找过,我们的开发人员都说不成,谢谢。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
101 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
abc1223
2006-11-09
打赏
举报
回复
顶
Rodney815
2006-11-09
打赏
举报
回复
顶!
技术开发到天荒地老
2006-11-09
打赏
举报
回复
主要是散分。
=============================================
何时结贴?
cqm2099
2006-11-08
打赏
举报
回复
up
CpRcF
2006-11-08
打赏
举报
回复
接分。
《深入浅出 hibernate》 这书上有个例子,是关于向oracle中插入blob/clob字段的例子。
allright_flash
2006-11-08
打赏
举报
回复
94
allright_flash
2006-11-08
打赏
举报
回复
⊙⌒⊙
∨
allright_flash
2006-11-08
打赏
举报
回复
┌──┐
│好贴│ ╭───────╮
└──┘ ┏━━━━━━━┓ │ 既然有分, │
┏┓ ┏┫ |||┣┓∠ 这贴就顶了 │
┣┫ ┗┫━━ ┃ ━━┣┛ ╰───────╯
┏┳┫┣┳┓ ┃ ━━━━━ ┃
┃ ┃ ┗━━━┳━━━┛
┗━━━━┻━━━━▇▇▇┛ ()000o
┃ ┃ (````)
┃ ┃ )``/
┛ ┗━━(__/
andy_linky
2006-11-08
打赏
举报
回复
接分,随便学习……
water_carrier
2006-11-08
打赏
举报
回复
mark
xfzhangbin
2006-11-08
打赏
举报
回复
接分咯
zlinerxz
2006-11-08
打赏
举报
回复
public boolean setClob(String ID, String SQL, String content)
{
boolean flag = false;
//com.bill.base.Lj.debug("content"+content);
LogManager loger = new LogManager();
Connection conn = null;
ResultSet rs=null;
oracle.sql.CLOB clob=null;
java.sql.PreparedStatement pstmt=null;
try
{
connectDatabase();
conn = getConnection();
conn.setAutoCommit(false);
pstmt = conn.prepareStatement(SQL);
pstmt.executeUpdate();
pstmt.close();
pstmt = conn.prepareStatement("select content from TBDEMAILWaiting where ID=? for update");
pstmt.setString(1,ID);
rs = pstmt.executeQuery();
if (rs.next())
{
clob = (oracle.sql.CLOB)((oracle.jdbc.OracleResultSet) rs).getClob(1);
//writer = ((CLOB)my_clob).setCharacterStream();
// 获得游标 // 使用输入流的形式来,把字符串输入到这个特有的数据库字段中去
BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());
//Writer wr = clob.setCharacterStream();
out.write(content);
//out.flush();
out.close();
rs.close();
conn.commit();
pstmt.close();
conn.close();
flag = true;
}
}
catch (SQLException ex1)
{
try
{
conn.rollback();
}
catch (Exception ex)
{
loger.writeLog("SQL rollback ERROR IS" + ex.toString());
}
loger.writeLog("SQL ERROR IS" + SQL);
loger.writeLog("dbm.connect error is: " + ex1.toString());
}
catch (Exception ex)
{
try
{
conn.rollback();
}
catch (Exception e)
{
loger.writeLog("SQL rollback ERROR IS" + e.toString());
}
loger.writeLog("setClob error is " + ex.toString());
}
finally
{
try
{
if (rs != null)
{
rs.close();
}
if (pstmt!=null)
{
pstmt.close();
}
if (conn != null)
{
conn.close();
}
}
catch (SQLException ex)
{
Loger.writeLog("dbman err is= " + ex.toString());
}
}
return flag;
}
public boolean setClob(String tabName ,String fieldName,String iDvalue,String contentVal,String SQL)
{
boolean flag = false;
LogManager loger = new LogManager();
Connection conn = null;
try
{
connectDatabase();
conn = getConnection();
conn.setAutoCommit(false);
executeUpdate(SQL);
Statement st = this.getStatement();
ResultSet rs = st.executeQuery(
"select content from "+tabName+" where "+fieldName+"='" +
iDvalue + "' for update");
if (rs.next())
{
oracle.sql.CLOB clob = ( (oracle.jdbc.driver.OracleResultSet) rs).
getCLOB(1);
clob.putString(1, contentVal);
SQL = "update "+tabName+" set content=? where "+fieldName+"='" + iDvalue + "'";
PreparedStatement pstmt = conn.prepareStatement(SQL);
pstmt.setClob(1, clob);
pstmt.executeUpdate();
pstmt.close();
}
rs.close();
st.close();
conn.commit();
flag = true;
}
catch (SQLException ex1)
{
try
{
conn.rollback();
}
catch (Exception ex)
{
loger.writeLog("SQL rollback ERROR IS" + ex.toString());
}
loger.writeLog("SQL ERROR IS" + SQL);
loger.writeLog("dbm.connect error is: " + ex1.toString());
}
catch (Exception ex)
{
try
{
conn.rollback();
}
catch (Exception e)
{
loger.writeLog("SQL rollback ERROR IS" + e.toString());
}
loger.writeLog("setClob error is " + ex.toString());
}
finally
{
try
{
if (conn != null)
{
conn.close();
}
}
catch (SQLException ex)
{
Loger.writeLog("dbman err is= " + ex.toString());
}
}
return flag;
}
/**
*
* @param ID String
* @return String
*/
public String getClob(String ID)
{
LogManager loger = new LogManager();
Connection conn = null;
try
{
connectDatabase();
conn = getConnection();
Statement st = this.getStatement();
ResultSet rs = st.executeQuery(
"select content from TBDEMAILWaiting where ID='" +
ID + "' ");
oracle.sql.BLOB blob = null;
String content = "";
if (rs.next())
{
oracle.sql.CLOB clob = ( (oracle.jdbc.driver.OracleResultSet) rs).
getCLOB(1);
if (clob != null)
{
Reader is = clob.getCharacterStream();
BufferedReader br = new BufferedReader(is);
String s = br.readLine();
while (s != null)
{
content += s + "\r\n";
s = br.readLine();
}
}
}
rs.close();
st.close();
conn.close();
return content;
}
catch (SQLException ex1)
{
loger.writeLog("dbm.connect error is: " + ex1.toString());
}
catch (Exception ex)
{
loger.writeLog("setClob error is " + ex.toString());
}
finally
{
try
{
if (conn != null)
{
conn.close();
}
}
catch (SQLException ex)
{
Loger.writeLog("dbman err is= " + ex.toString());
}
}
return "F";
}
public String getClob(String tabName,String fieldName,String contentID)
{
LogManager loger = new LogManager();
Connection conn = null;
try
{
connectDatabase();
conn = getConnection();
Statement st = this.getStatement();
ResultSet rs = st.executeQuery(
"select content from "+tabName+" where "+fieldName+"='" +
contentID + "' ");
oracle.sql.BLOB blob = null;
String content = "";
if (rs.next())
{
oracle.sql.CLOB clob = ( (oracle.jdbc.driver.OracleResultSet) rs).
getCLOB(1);
if (clob != null)
{
Reader is = clob.getCharacterStream();
BufferedReader br = new BufferedReader(is);
String s = br.readLine();
while (s != null)
{
content += s + "\r\n";
s = br.readLine();
}
}
}
rs.close();
st.close();
conn.close();
return content;
}
catch (SQLException ex1)
{
loger.writeLog("dbm.connect error is: " + ex1.toString());
}
catch (Exception ex)
{
loger.writeLog("setClob error is " + ex.toString());
}
finally
{
try
{
if (conn != null)
{
conn.close();
}
}
catch (SQLException ex)
{
Loger.writeLog("dbman err is= " + ex.toString());
}
}
return "F";
}
sun113
2006-11-08
打赏
举报
回复
zzd8310(经常被模仿,从未被超越!||我之所以把昵称写这么长。就是想看看昵称到底能写多长,真是长啊!!!!!!) ( ) 信誉:100 Blog 2006-11-1 8:14:52 得分: 0 jiu
mywanpi
2006-11-07
打赏
举报
回复
down
会跑步的程序员
2006-11-07
打赏
举报
回复
接粉
大选
2006-11-07
打赏
举报
回复
如果有人打著散分的幌子,來問問題,我就只能鄙視你了.
allright_flash
2006-11-07
打赏
举报
回复
祝福lz早点解决问题!
allright_flash
2006-11-07
打赏
举报
回复
接分,随便学习……
allright_flash
2006-11-07
打赏
举报
回复
没用过blob字段,帮顶
BabyWhite
2006-11-07
打赏
举报
回复
接分,随便学习……
加载更多回复(81)
西门子Smart
200
PLC与四台台达变频器Modbus轮询通讯操作指南
西门子smart
200
plc与4台台达变频器modbus轮询通讯 VFD-EL小型矢量变频器 1,读写变频器的内部参数 2,控制变频器启停,读频率电流 3,设置变频器输出频率 4,有彩色接线图,和参数设置说明, 有。
200
PLC 两台水泵一用一备经典案例解析
/ 定义总启动按钮// 定义总停止按钮// 1#电机运行信号// 1#电机故障信号// 2#电机运行信号// 2#电机故障信号// 1#电机启动输出// 2#电机启动输出// 报警输出// 时间相关变量。
QQ音乐Android wear,LG W
200
智能手表入手,性价比极高的Android Wear
最近想整个智能手表玩玩,稍微看了下Moto 360,华米,华为,Ticwatch等,感觉要么年代久远,要么不够智能,颜值不够好,要么就太贵。几经查探在咸鱼上发现了这款LG W
200
,感觉颜值、做工以及配置都还不错,最重要的是价格:RMB180,当然这么低有个条件,它的表带断了,需要重新配。看看这颜值,全圆屏显示,生活级防水。在看看配置:GENERAL3G Network2100 MHz4G Net...
Java EE
67,535
社区成员
225,851
社区内容
发帖
与我相关
我的任务
Java EE
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
复制链接
扫一扫
分享
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章