璇誨彇綆鍗曠偣錛岀敤鍒拌緭鍏ヨ緭鍑烘祦銆?/p>
1
private String getClob (CLOB clob) throws Exception
2

{
3
//2縐嶅啓娉?/span>
4
/** *//**
5
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob(1);
6
BufferedReader in = new BufferedReader(clob.getCharacterStream());
7
StringWriter out=new StringWriter();
8
int c;
9
while((c=in.read())!=-1)
10
{
11
out.write(c);
12
}
13
String content=out.toString();
14
*/
15
16
String content = "";
17
18
Reader is = clob.getCharacterStream();
19
BufferedReader br = new BufferedReader(is);
20
String s = br.readLine();
21
while (s != null)
22
{
23
content += s + "\r\n";
24
s = br.readLine();
25
}
26
27
return content;
28
29
}
涓嬮潰鏄啓鍏LOB
1
//the first, run
2
//ResultSet rs = null;
3
//String sSQL = "select " + ColName + " from " + tableName + " where id= '" + ID + "' for update";
4
//(oracle.sql.CLOB)rs.getClob(number);
5
private void fillClob (CLOB clob, String data) throws Exception
6
{
7
if (data == null)
8
{
9
data = "no value !";
10
}
11
if (clob != null)
12
{
13
Writer wr = clob.getCharacterOutputStream();
14
wr.write(data);
15
wr.flush();
16
wr.close();
17
}
18
}
conn.setAutoCommit(false);//鍙栨秷鑷姩鎻愪氦
闇瑕佽棣栧厛鎵ц
闇瑕佹彃鍏ヤ竴鏉℃柊鐨勮褰曟椂錛屽彲浠ュ儚涓嬮潰榪欐牱錛?br>
1. 鍏堝彇sequence鐨勫?br> strSql = "select sequence(琛ㄤ腑column鐨勫悕瀛?.nextval from dual";
pstm = this.conn.prepareStatement(strSql);
rs = pstm.executeQuery();
2. 鎻掑叆涓涓┖鍊肩殑CLOB
insert into tableName t (t.CLOB_column, t.sequence) values(empty_clob(), id)
pstm.executeUpdate();
3. 鎶婅繖涓琛岄攣瀹氾紝鐢╯elect ...for update璇彞錛岀劧鍚庡湪鍐欏叆
strSql = "select t.CLOB_column from tableName t where t.sequence= " + id + " for update";
pstm = this.conn.prepareStatement(strSql);
rs = pstm.executeQuery();
if (rs.next())
{
clob1= (oracle.sql.CLOB) rs.getClob(1);
fillClob(clob1, content);
}
rs.close();
conn.commit();//瀵瑰簲涓婇潰鐨勯偅鍙?br> pstm.close();
鏇存柊涓鏉¤褰?br>
1. 娓呯┖CLOB鐨勫唴瀹?br>
strSql = "update tableName t set t.CLOB_column = empty_clob() where t.id ='" + id + "'";
pstm = this.conn.prepareStatement(strSql);
pstm.executeUpdate();
2. 鍜屾彃鍏ユ柊璁板綍涓鏍鳳紝闇瑕佺敤for update閿佸畾
1
strSql = "select t.CLOB_column from tableName t where t. ='" + id + "' for update";
2
pstm = this.conn.prepareStatement(strSql);
3
rs = pstm.executeQuery();
4
while (rs.next())
5

{
6
clob = (oracle.sql.CLOB) rs.getClob(3);
7
fillClob(clob, content);
8
conn.commit();
9
}
10
pstm = null;
11
12
strSql = "update tableName t set t.CLOB_column, t.date = to_date('" + sdate + "','YYYY-MM-DD') where t.id = " + id;
13
pstm = this.conn.prepareStatement(strSql);
14
int aflag = pstm.executeUpdate();
15
conn.commit();
16
17
rs.close();
18
pstm.close();

]]>