Oracle大文本clob数据类型的增删改查
package common;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
www.2cto.com
/*
*/
import oracle.sql.CLOB;
/**
* 连接数据库的类
* 最基础的类
*
*/
public class text {
/**
* 连接数据库常用的属性
*
*
*/
public String sDBDriver = "oracle.jdbc.driver.
OracleDriver";// 设置驱动
public String url = "jdbc:oracle:thin:@localhost :spe";// 设置数据库信息
public String sHint = "";
public ResultSet rs = null;
public Connection conn = null;
public Statement stmt = null;
public String user = "study";
public String pwd = "ok";
/**
* 加载配置文件读取信息
* www.2cto.com
*
*/
public text() throws IOException {
String userpath = System.getProperty("user.dir");
String filesparator = System.getProperty("file.separator");
String dbconfig = userpath + filesparator + "dbconfig.properties";
FileInputStream in;
in = new FileInputStream(dbconfig);
Properties dbp = new Properties();
dbp.load(in);
in.close();
this.url = dbp.getProperty("URL");
this.user = dbp.getProperty("USER");
this.pwd = dbp.getProperty("PASSWORD");
System.out.println("地址=" + dbconfig);
// System.out.println("真实="+this.url);
}
public String getSHint() {
return sHint;
}
public void setSDBDriver(String dbDriver) {
sDBDriver = dbDriver;
}
public String getSDBDriver() {
return sDBDriver;
}
public String getUrl() {
return url;
}
public void setUrl(String s) {
url = s;
}
public ResultSet getResultSet() {
return rs;
}
public boolean initialize(String url, String user, String pwd) {
this.url = url;
this.user = user;
this.pwd = pwd;
return initialize();
}
public boolean initialize() {// 默认构造方法
try {
Class.forName(sDBDriver);
sHint = "Initialization sucessfully";
return true;
} catch (ClassNotFoundException e) {
sHint = "Initialization Exception:" + e.getMessage();
return false;
}
}
/**
* 关闭数据库对象
* www.2cto.com
*
*/
public boolean close() {// 关闭数据库连接
try {
if (rs != null)
{ rs.close();}
if (stmt != null)
{stmt.close();}
if (conn != null)
{conn.close();}
return true;
} catch (SQLException ex) {
sHint = "Close Exception:" + ex.getMessage();
return false;
}
}
/**
* 插入大字段方法
*
*
*/
public String insertClob(int userid, int courseware_Id, int Progress,
String CourseClob) {// 插入数据库clob字段
try {
// int testid = 77;
// System.out.println("113用户ID" + userid + "课件ID" + courseware_Id+
// "进度" + Progress + "value=" + CourseClob);
Class.forName(this.sDBDriver);
Connection conn = DriverManager.getConnection(this.url, this.user,
this.pwd);
conn.setAutoCommit(false);
/* 以下表User_CourseWare中的Report字段时CLOB类型的 */
// 插入一条数据,注意CLOB字段,需要先插入一个空的