oracle大文本类型数字,Oracle大文本clob数据类型的增删改查(3)

// return null; content = error; } catch (SQLException e) { e.printStackTrace(); // return null; content = error; } return content; } /** * clob to string * 大字符串格式转换STRING * @param clob

// return "null";    content = "error";

} catch (SQLException e) {

e.printStackTrace();

// return "null";

content = "error";

}

return content;

}

/**

* clob to string

* 大字符串格式转换STRING

* @param clob

* @return 大字符串

*

*/

public String Clob2String(CLOB clob) {// Clob转换成String 的方法

String content = null;

StringBuffer stringBuf = new StringBuffer();

try {  www.2cto.com

int length = 0;

Reader inStream = clob.getCharacterStream(); // 取得大字侧段对象数据输出流

char[] buffer = new char[10];

while ((length = inStream.read(buffer)) != -1) // 读取数据库 //每10个10个读取

{

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;

}

/**

*

* 更新Clob(大字符串格式)内容

* @param userid

*            用户ID

* @param courseware_Id

*            课件ID

* @param Progress

*            课件进度

* @param CourseClob

*            XML 字符串

* @return boolean

*   www.2cto.com

*/

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

// System.out.println("update sql="+sql);

pstmt = null;  www.2cto.com

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

// System.out.println("select sql="+sql1);

pstmt.setInt(1, userid);

pstmt.setInt(2, courseware_Id);

rs = pstmt.executeQuery();

if (rs.next()) {

clob = (CLOB) rs.getClob(1);

}  www.2cto.com

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";

}  www.2cto.com

/*

* 参数:userid 用户ID courseware_Id 课件ID Progress 课件进度 返回值 课件进度不到100时不更新 到100时

* 更新 状态为2(已学)

*/

public String updateUser_Course(int userid, int courseware_Id, int Progress) {

String caseTest = "default";

if (Progress == 100) {

String sql = "update User_Course set  Status =2 where USER_ID =? and COURSE_ID =?   ";

try {

Class.forName(this.sDBDriver);

Connection conn = DriverManager.getConnection(this.url,

this.user, this.pwd);

PreparedStatement pstmt = conn.prepareStatement(sql);

pstmt.setInt(1, userid);

pstmt.setInt(2, courseware_Id);

www.2cto.com

int i1 = pstmt.executeUpdate();

conn.commit();

pstmt = null;

if (i1 > 0) {

// System.out.println("更新成功!");

}

caseTest = "success";

} catch (Exception e) {

caseTest = "error";

e.printStackTrace();

}

}

return caseTest;

}

www.2cto.com

/**

*

* @param sql

*            要执行的查询语句

* @return 结果集

*/

public ResultSet executeQuery(String sql) {

rs = null;

try {

Class.forName(this.sDBDriver);

conn = DriverManager.getConnection(this.url, this.user, this.pwd);

stmt = conn.createStatement();

rs = stmt.executeQuery(sql);

} catch (Exception ex) {

sHint = "Query Exception:" + ex.getMessage();

}  www.2cto.com

return rs;

}

/**

* 执行 更新删除等语句

*

* @param sql

* @return 返回执行结果的boolean值

*/

public boolean executeUpdate(String sql) {

try {

Class.forName(this.sDBDriver);

conn = DriverManager.getConnection(this.url, this.user, this.pwd);

stmt = conn.createStatement();

stmt.executeUpdate(sql);

conn.commit();

return true;  www.2cto.com

} catch (Exception ex) {

sHint = "Update Exception :" + ex.getMessage();

return false;

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值