2007-11-23
clob字段的读和取
clob字段读取时不能用数据源,所以必须用原始方法存储。
代码如下:
存储数据:
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.1:1521:orcl","username","password");
}catch(ClassNotFoundException E){
}catch(SQLException e){
}
try {
conn.setAutoCommit(false);
ps = conn.prepareStatement(sql);
ps.setString(1,form.getPreTitle());
ps.setString(2,form.getTitle());
。。。。。。。。。。。。。。。。。
flag = ps.executeUpdate();
String sql_1 = "select news_content from t_news_temp where news_title='"+form.getTitle()+"' for update";
st = conn.createStatement();
rs = st.executeQuery(sql_1);
CLOB clob = null;
if(rs.next()){
clob = ((oracle.jdbc.OracleResultSet)rs).getCLOB("news_content");
java.io.Writer writer = clob.getCharacterOutputStream();
try {
writer.write(form.getContent());
writer.flush();
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e);
}
}
conn.commit();
conn.setAutoCommit(true);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e);
return 0;
}
修改数据:
修改也不能直接用数据源。
conn = ConnectionHelper.getConnection();
conn.setAutoCommit(false);
ps = conn.prepareStatement(sql);
ps.setString(1,form.getPreTitle());
ps.setString(2,form.getTitle());
ps.executeUpdate();
String sql_1 = "select news_content from t_news where news_id="+form.getId();
st = conn.createStatement();
rs = st.executeQuery(sql_1);
CLOB clob = null;
while(rs.next()){
clob = ((oracle.jdbc.OracleResultSet) rs).getCLOB("news_content");
oracle.sql.CLOB my_clob = (oracle.sql.CLOB) clob;
java.io.Writer writer = my_clob.getCharacterOutputStream();
try {
writer.write(form.getContent());
writer.flush();
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
conn.commit();
conn.setAutoCommit(true);
查询数据:
查询数据也可以直接用数据源。
clob = rs.getClob("news_content");
form.setContent(clob.getSubString((long)1,(int)clob.length()));
代码如下:
存储数据:
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.1:1521:orcl","username","password");
}catch(ClassNotFoundException E){
}catch(SQLException e){
}
try {
conn.setAutoCommit(false);
ps = conn.prepareStatement(sql);
ps.setString(1,form.getPreTitle());
ps.setString(2,form.getTitle());
。。。。。。。。。。。。。。。。。
flag = ps.executeUpdate();
String sql_1 = "select news_content from t_news_temp where news_title='"+form.getTitle()+"' for update";
st = conn.createStatement();
rs = st.executeQuery(sql_1);
CLOB clob = null;
if(rs.next()){
clob = ((oracle.jdbc.OracleResultSet)rs).getCLOB("news_content");
java.io.Writer writer = clob.getCharacterOutputStream();
try {
writer.write(form.getContent());
writer.flush();
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e);
}
}
conn.commit();
conn.setAutoCommit(true);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e);
return 0;
}
修改数据:
修改也不能直接用数据源。
conn = ConnectionHelper.getConnection();
conn.setAutoCommit(false);
ps = conn.prepareStatement(sql);
ps.setString(1,form.getPreTitle());
ps.setString(2,form.getTitle());
ps.executeUpdate();
String sql_1 = "select news_content from t_news where news_id="+form.getId();
st = conn.createStatement();
rs = st.executeQuery(sql_1);
CLOB clob = null;
while(rs.next()){
clob = ((oracle.jdbc.OracleResultSet) rs).getCLOB("news_content");
oracle.sql.CLOB my_clob = (oracle.sql.CLOB) clob;
java.io.Writer writer = my_clob.getCharacterOutputStream();
try {
writer.write(form.getContent());
writer.flush();
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
conn.commit();
conn.setAutoCommit(true);
查询数据:
查询数据也可以直接用数据源。
clob = rs.getClob("news_content");
form.setContent(clob.getSubString((long)1,(int)clob.length()));
发表评论
- 浏览: 6775 次
- 性别:

- 来自: 长沙

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
我的Ext超级简单教程
先下载,谢谢,现在正需要掌握 EXT.JS
-- by simon1006 -
我的Ext超级简单教程
Thanks a lot
-- by chaoerkaka -
oracle操作基本调优 工作 ...
Libra Man 写道数据库操作主要包含如下操作: 1.insert,2.de ...
-- by Lucas Lee -
oracle操作基本调优 工作 ...
说的非常有价值,谢谢!
-- by Libra Man -
oracle操作基本调优 工作 ...
不用in,用exists代替 取值范围小的字段用bitmap索引 表和索引放在不 ...
-- by taelons






评论排行榜