public
String getCourseClob(
int
user_id,
int
courseware_id) {
String content =
"null"
;
try
{
Class.forName(
this
.sDBDriver);
Connection conn = DriverManager.getConnection(
this
.url,
this
.user,
this
.pwd);
conn.setAutoCommit(
false
);
ResultSet rs =
null
;
CLOB clob =
null
;
String sql =
""
;
sql =
"select Report from User_CourseWare where user_id=? and courseware_id=? "
;
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(
1
, user_id);
pstmt.setInt(
2
, courseware_id);
rs = pstmt.executeQuery();
if
(rs.next()) {
clob = (CLOB) rs.getClob(
1
);
if
(clob !=
null
&& clob.length() !=
0
) {
content = clob.getSubString((
long
)
1
, (
int
) clob.length());
content =
this
.Clob2String(clob);
}
}
rs.close();
conn.commit();
pstmt.close();
conn.close();
}
catch
(ClassNotFoundException e) {
e.printStackTrace();
content =
"error"
;
}
catch
(SQLException e) {
e.printStackTrace();
content =
"error"
;
}
return
content;
}
public
String Clob2String(CLOB clob) {
String content =
null
;
StringBuffer stringBuf =
new
StringBuffer();
try
{
int
length =
0
;
Reader inStream = clob.getCharacterStream();
char
[] buffer =
new
char
[
10
];
while
((length = inStream.read(buffer)) != -
1
)
{
for
(
int
i =
0
; i < length; i++) {
stringBuf.append(buffer[i]);
}
}
inStream.close();
content = stringBuf.toString();
}
catch
(Exception ex) {
System.out.println(
"ClobUtil.Clob2String:"
+ ex.getMessage());
}
return
content;
}
public
String updateClob(
int
userid,
int
courseware_Id,
int
Progress,
String CourseClob) {
this
.updateUser_Course(userid, courseware_Id, Progress);
try
{
Class.forName(
this
.sDBDriver);
Connection conn = DriverManager.getConnection(
this
.url,
this
.user,
this
.pwd);
String sql =
"update User_CourseWare set Report=empty_clob() , Progress=? where User_Id = ? and Courseware_Id =? "
;
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(
1
, Progress);
pstmt.setInt(
2
, userid);
pstmt.setInt(
3
, courseware_Id);
int
i1 = pstmt.executeUpdate();
conn.commit();
pstmt =
null
;
if
(i1 >
0
) {
}
ResultSet rs =
null
;
CLOB clob =
null
;
String sql1 =
"select Report from User_CourseWare where User_id=? and Courseware_id=? for update"
;
pstmt = conn.prepareStatement(sql1);
pstmt.setInt(
1
, userid);
pstmt.setInt(
2
, courseware_Id);
rs = pstmt.executeQuery();
if
(rs.next()) {
clob = (CLOB) rs.getClob(
1
);
}
Writer writer = clob.getCharacterOutputStream();
writer.write(CourseClob);
writer.flush();
writer.close();
rs.close();
conn.commit();
pstmt.close();
conn.close();
}
catch
(Exception e) {
e.printStackTrace();
return
"error"
;
}
return
"success"
;
}