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()));