散分200,顺带问个问题。

duye 2006-10-31 09:14:50
主要是散分。
问题为:
j2ee应用中如何读写oracle数据库中的clob或者blob字段,要求是自己写过的例子,网上例子我找过,我们的开发人员都说不成,谢谢。
...全文
946 101 打赏 收藏 转发到动态 举报
写回复
用AI写文章
101 条回复
切换为时间正序
请发表友善的回复…
发表回复
abc1223 2006-11-09
  • 打赏
  • 举报
回复
Rodney815 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
  • 打赏
  • 举报
回复
如果有人打著散分的幌子,來問問題,我就只能鄙視你了.
allright_flash 2006-11-07
  • 打赏
  • 举报
回复
祝福lz早点解决问题!
allright_flash 2006-11-07
  • 打赏
  • 举报
回复
接分,随便学习……
allright_flash 2006-11-07
  • 打赏
  • 举报
回复
没用过blob字段,帮顶
BabyWhite 2006-11-07
  • 打赏
  • 举报
回复
接分,随便学习……
加载更多回复(81)

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧