好久没有光顾我的blog了,由于从8月1日起接到一个项目-××在线考试系统,至今一直在忙,从需求分析、数据库设计、架构设计、采用的技术路线基本上都由我来参与并做最后决定,着实感觉压力很大,需要解决的问题很多,而且需求方的时间上的要求非常的紧,好在现在系统已经基本完成。
在做这个项目的过程中,我遇到了一些非常棘手的问题,包括设计上、技术上以及管理上的。今天我先将开发中遇到的字符串存取的问题拿出来和大家分享,讨论一下最佳的解决办法。
问题背景:
数据库:Oracle 9i
中间件:Weblogic 8.1
数据库服务器OS\ Web应用服务器:Linux 企业版
系统架构(MVC):Struts + hibernate
在系统中的一个数据库表的设计如下:
由于某些字段的存储量较大,所以我将它们的长度都设成了Varchar类型的最大值。
在使用Hibernate进行数据存储的过程中,大家可能都会遇到一个问题,就是当存储的汉字超过666个汉字时,数据库就会报出长度超出字段最大值的错误,这个问题是由于使用String 类本省的问题引起的,在遇到这个问题时,我们一般采用流(setCharacterStream)的方式来存储。
因此写成如下方式:
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Connection conn = ThreadLocalSessionManager.getConnection();
PreparedStatement ps=null;
try {
conn.setAutoCommit(false);
/**获得序列的下一个值*/
StringBuffer sql = new StringBuffer();
sql.append("insert into Stxxmskhk ")
.append(" (stdm,zqda,tg,xxy,xxe,xxs,xxsi,ydy,yde,yds,ydsi,ydw,ydl,ydq,ydb," +
"fzy,fze,fzs,fzsi,fzw,fzl,fzq,fzb)");
sql.append(" values")
.append(" (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
logger.info("the sql is :::" + sql.toString());
ps = conn.prepareStatement(sql.toString());
ps.setInt(1, stxxmskhk.getStdm().intValue());
ps.setString(2, stxxmskhk.getZqda());
if(stxxmskhk.getTg() == null){
stxxmskhk.setTg("");
}
ps.setCharacterStream(3, new StringReader(stxxmskhk.getTg()),stxxmskhk.getTg().length());
if(stxxmskhk.getXxy() == null){
stxxmskhk.setXxy("");
}
ps.setCharacterStream(4, new StringReader(stxxmskhk.getXxy()),stxxmskhk.getXxy().length());
if(stxxmskhk.getXxe() == null){
stxxmskhk.setXxe("");
}
ps.setCharacterStream(5, new StringReader(stxxmskhk.getXxe()),stxxmskhk.getXxe().length());
if(stxxmskhk.getXxs() == null){
stxxmskhk.setXxs("");
}
ps.setCharacterStream(6, new StringReader(stxxmskhk.getXxs()),stxxmskhk.getXxs().length());
if(stxxmskhk.getXxsi() == null){
stxxmskhk.setXxsi("");
}
ps.setCharacterStream(7, new StringReader(stxxmskhk.getXxsi()),stxxmskhk.getXxsi().length());
if(stxxmskhk.getYdy() == null){
stxxmskhk.setYdy("");
}
ps.setCharacterStream(8, new StringReader(stxxmskhk.getYdy()),stxxmskhk.getYdy().length());
if(stxxmskhk.getYde() == null){
stxxmskhk.setYde("");
}
ps.setCharacterStream(9, new StringReader(stxxmskhk.getYde()),stxxmskhk.getYde().length());
if(stxxmskhk.getYds() == null){
stxxmskhk.setYds("");
}
ps.setCharacterStream(10, new StringReader(stxxmskhk.getYds()),stxxmskhk.getYds().length());
if(stxxmskhk.getYdsi() == null){
stxxmskhk.setYdsi("");
}
ps.setCharacterStream(11, new StringReader(stxxmskhk.getYdsi()),stxxmskhk.getYdsi().length());
if(stxxmskhk.getYdw() == null){
stxxmskhk.setYdw("");
}
ps.setCharacterStream(12, new StringReader(stxxmskhk.getYdw()),stxxmskhk.getYdw().length());
if(stxxmskhk.getYdl() == null){
stxxmskhk.setYdl("");
}
ps.setCharacterStream(13, new StringReader(stxxmskhk.getYdl()),stxxmskhk.getYdl().length());
if(stxxmskhk.getYdq() == null){
stxxmskhk.setYdq("");
}
ps.setCharacterStream(14, new StringReader(stxxmskhk.getYdq()),stxxmskhk.getYdq().length());
if(stxxmskhk.getYdb() == null){
stxxmskhk.setYdb("");
}
ps.setCharacterStream(15, new StringReader(stxxmskhk.getYdb()),stxxmskhk.getYdb().length());
if(stxxmskhk.getFzy() == null || "".equals(stxxmskhk.getFzy())){
stxxmskhk.setFzy(new Float(0));
}
if(stxxmskhk.getFze() == null || "".equals(stxxmskhk.getFze())){
stxxmskhk.setFze(new Float(0));
}
if(stxxmskhk.getFzs() == null || "".equals(stxxmskhk.getFzs())){
stxxmskhk.setFzs(new Float(0));
}
if(stxxmskhk.getFzsi() == null || "".equals(stxxmskhk.getFzsi())){
stxxmskhk.setFzsi(new Float(0));
}
if(stxxmskhk.getFzw() == null || "".equals(stxxmskhk.getFzw())){
stxxmskhk.setFzw(new Float(0));
}
if(stxxmskhk.getFzl() == null || "".equals(stxxmskhk.getFzl())){
stxxmskhk.setFzl(new Float(0));
}
if(stxxmskhk.getFzq() == null || "".equals(stxxmskhk.getFzq())){
stxxmskhk.setFzq(new Float(0));
}
if(stxxmskhk.getFzb() == null || "".equals(stxxmskhk.getFzb())){
stxxmskhk.setFzb(new Float(0));
}
ps.setFloat(16, stxxmskhk.getFzy().floatValue());
ps.setFloat(17, stxxmskhk.getFze().floatValue());
ps.setFloat(18, stxxmskhk.getFzs().floatValue());
ps.setFloat(19, stxxmskhk.getFzsi().floatValue());
ps.setFloat(20, stxxmskhk.getFzw().floatValue());
ps.setFloat(21, stxxmskhk.getFzl().floatValue());
ps.setFloat(22, stxxmskhk.getFzq().floatValue());
ps.setFloat(23, stxxmskhk.getFzb().floatValue());
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
// TODO 以流的方式处理数据
e.printStackTrace();
logger.debug("添加试题描述保存表时出现错误!");
String[] params = new String[] { stxxmskhk.toString() };
logger.error(MessageConst.LITEMREPORT_DAO_ADD_OPER, params, e);
throw new LabDBSysException(MessageConst.LITEMREPORT_DAO_ADD_OPER,
e);
}
。。。。。。。。。。。。。
写好后,进行测试,保存1000多汉字不成问题,系统不会提示长度超长的错误。但是仔细测试后发现如下问题:
1) 由于字段长度设置为4000的字段有10多个,在所有字段的输入长度保持在100个汉字以内时,保存的结果是正常的,但是当输入的汉字有个别较长时,保存到数据库的数据出现篡位的现象,即原来保存的顺序是 1、2、3,但保存到数据库的顺序确变成了3,4,5。
2) 在这10多个字段中,输入的字段数目不同,篡位的情况不同,例如,输入字段1、2的篡位情况和输入字段1、2、3、的篡位情况就不同。
我到网上查了查,看到一位朋友的解决办法如下:
/**********************************************************************/
JAVA 的问题,还是ORACLE 的问题 setCharacterStream的顺序
数据表
create table test4000( id int,c1 varchar2(4000),c2 varchar2(4000),c3 varchar2(4000),c4 varchar2(4000));
SQL_STRING =
"insert into TEST4000(ID,C1,C2,C3,C4) values(?,?,?,?,?)";
stmt = conn.prepareStatement(SQL_STRING);
stmt.setInt(1,1);
stmt.setCharacterStream( 2 , new StringReader(s4.toString()), 4000 );
stmt.setCharacterStream( 3 , new StringReader(s1.toString()), 4000);
stmt.setCharacterStream( 4 , new StringReader(s2.toString()), 4000);
stmt.setCharacterStream( 5 , new StringReader(s3.toString()), 4000);
检查数据库中的数据一致
但是请注意代码中的设置顺序
stmt.setCharacterStream( 2 , new StringReader(s4.toString()), 4000 );
stmt.setCharacterStream( 3 , new StringReader(s1.toString()), 4000);
stmt.setCharacterStream( 4 , new StringReader(s2.toString()), 4000);
stmt.setCharacterStream( 5 , new StringReader(s3.toString()), 4000);
经过测试发现
如果表中有2个VARCHAR2(4000) 的字段 要写成下面的顺序插入
stmt.setCharacterStream( 2 , new StringReader(s2.toString()), 4000 );
stmt.setCharacterStream( 3 , new StringReader(s1.toString()), 4000);
如果表中有3个VARCHAR2(4000) 的字段 要写成下面的顺序插入
stmt.setCharacterStream( 2 , new StringReader(s3.toString()), 4000 );
stmt.setCharacterStream( 3 , new StringReader(s1.toString()), 4000);
stmt.setCharacterStream( 4 , new StringReader(s2.toString()), 4000);
同理推测
如果表中有5个VARCHAR2(4000) 的字段 要写成下面的顺序插入
stmt.setCharacterStream( 2 , new StringReader(s5.toString()), 4000 );
stmt.setCharacterStream( 3 , new StringReader(s1.toString()), 4000);
stmt.setCharacterStream( 4 , new StringReader(s2.toString()), 4000);
stmt.setCharacterStream( 5 , new StringReader(s3.toString()), 4000);
stmt.setCharacterStream( 6 , new StringReader(s4.toString()), 4000 );
如果表中有n个VARCHAR2(4000) 的字段 要写成下面的顺序插入
stmt.setCharacterStream( 2 , new StringReader(sn.toString()), 4000 );
stmt.setCharacterStream( 3 , new StringReader(s1.toString()), 4000);
stmt.setCharacterStream( 4 , new StringReader(s2.toString()), 4000);
stmt.setCharacterStream( 5 , new StringReader(s3.toString()), 4000);
stmt.setCharacterStream( 6 , new StringReader(s4.toString()), 4000 );
.....
.....
stmt.setCharacterStream( n+1 , new StringReader(s(n-1).toString()), 4000 );
/**********************************************************************/
我按照上述方法进行实验,发现虽然篡位是有一定的规律的,但是和上述朋友的结论是不同的。
因为这些字段的值是可空的,用户可能只输入1个、2个、3个。。。或不输入数据,而用经测试,户输入不同数量字段的数据时,篡位的情况不同。如果要根据用户输入不同来获得篡位的规则,感觉花时间去解决这个问题有点不值得。考虑再三,决定用一个笨办法,如下:
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Connection conn = ThreadLocalSessionManager.getConnection();
PreparedStatement psinsert = null;
PreparedStatement psupdate = null;
try {
conn.setAutoCommit(false);
/**获得序列的下一个值*/
/*int seqid = Integer.parseInt(getNextSequenceValue("TLITEMREP_S"));*/
/*******************************insert begin ****************************/
StringBuffer insert = new StringBuffer();
insert.append("insert into stxxmskhk (stdm,zqda,tg,fzy,fze,fzs,fzsi,fzw,fzl,fzq,fzb) values(?,?,?,?,?,?,?,?,?,?,?)");
psinsert = conn.prepareStatement(insert.toString());
psinsert.setInt(1, stxxmskhk.getStdm().intValue());
psinsert.setString(2, stxxmskhk.getZqda());
if(stxxmskhk.getTg() == null){
stxxmskhk.setTg("");
}
psinsert.setCharacterStream(3, new StringReader(stxxmskhk.getTg()),stxxmskhk.getTg().length());
if(stxxmskhk.getFzy() == null || "".equals(stxxmskhk.getFzy())){
stxxmskhk.setFzy(new Float(0));
}
if(stxxmskhk.getFze() == null || "".equals(stxxmskhk.getFze())){
stxxmskhk.setFze(new Float(0));
}
if(stxxmskhk.getFzs() == null || "".equals(stxxmskhk.getFzs())){
stxxmskhk.setFzs(new Float(0));
}
if(stxxmskhk.getFzsi() == null || "".equals(stxxmskhk.getFzsi())){
stxxmskhk.setFzsi(new Float(0));
}
if(stxxmskhk.getFzw() == null || "".equals(stxxmskhk.getFzw())){
stxxmskhk.setFzw(new Float(0));
}
if(stxxmskhk.getFzl() == null || "".equals(stxxmskhk.getFzl())){
stxxmskhk.setFzl(new Float(0));
}
if(stxxmskhk.getFzq() == null || "".equals(stxxmskhk.getFzq())){
stxxmskhk.setFzq(new Float(0));
}
if(stxxmskhk.getFzb() == null || "".equals(stxxmskhk.getFzb())){
stxxmskhk.setFzb(new Float(0));
}
psinsert.setFloat(4, stxxmskhk.getFzy().floatValue());
psinsert.setFloat(5, stxxmskhk.getFze().floatValue());
psinsert.setFloat(6, stxxmskhk.getFzs().floatValue());
psinsert.setFloat(7, stxxmskhk.getFzsi().floatValue());
psinsert.setFloat(8, stxxmskhk.getFzw().floatValue());
psinsert.setFloat(9, stxxmskhk.getFzl().floatValue());
psinsert.setFloat(10, stxxmskhk.getFzq().floatValue());
psinsert.setFloat(11, stxxmskhk.getFzb().floatValue());
psinsert.executeUpdate();
/*********************************insert end *****************************/
/*********************************update xxy begin*******************************/
if(stxxmskhk.getXxy() != null){
StringBuffer xxy = new StringBuffer();
xxy.append("update stxxmskhk set xxy=? where stdm =?");
psupdate = conn.prepareStatement(xxy.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxy()),stxxmskhk.getXxy().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxy end*******************************/
/*********************************update xxe begin*******************************/
if(stxxmskhk.getXxe() != null){
StringBuffer xxe = new StringBuffer();
xxe.append("update stxxmskhk set xxe=? where stdm =?");
psupdate = conn.prepareStatement(xxe.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxe()),stxxmskhk.getXxe().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxe end*******************************/
/*********************************update xxs begin*******************************/
if(stxxmskhk.getXxs() != null){
StringBuffer xxs = new StringBuffer();
xxs.append("update stxxmskhk set xxs=? where stdm =?");
psupdate = conn.prepareStatement(xxs.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxs()),stxxmskhk.getXxs().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxs end*******************************/
/*********************************update xxsi begin*******************************/
if(stxxmskhk.getXxsi() != null){
StringBuffer xxsi = new StringBuffer();
xxsi.append("update stxxmskhk set xxsi=? where stdm =?");
psupdate = conn.prepareStatement(xxsi.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxsi()),stxxmskhk.getXxsi().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxsi end*******************************/
/*********************************update ydy begin*******************************/
if(stxxmskhk.getYdy() != null){
StringBuffer ydy = new StringBuffer();
ydy.append("update stxxmskhk set ydy=? where stdm =?");
psupdate = conn.prepareStatement(ydy.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdy()),stxxmskhk.getYdy().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydy end*******************************/
/*********************************update yde begin*******************************/
if(stxxmskhk.getYde() != null){
StringBuffer yde = new StringBuffer();
yde.append("update stxxmskhk set yde=? where stdm =?");
psupdate = conn.prepareStatement(yde.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYde()),stxxmskhk.getYde().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update yde end*******************************/
/*********************************update yds begin*******************************/
if(stxxmskhk.getYds() != null){
StringBuffer yds = new StringBuffer();
yds.append("update stxxmskhk set yds=? where stdm =?");
psupdate = conn.prepareStatement(yds.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYds()),stxxmskhk.getYds().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update yds end*******************************/
/*********************************update ydsi begin*******************************/
if(stxxmskhk.getYdsi() != null){
StringBuffer ydsi = new StringBuffer();
ydsi.append("update stxxmskhk set ydsi=? where stdm =?");
psupdate = conn.prepareStatement(ydsi.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdsi()),stxxmskhk.getYdsi().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydsi end*******************************/
/*********************************update ydw begin*******************************/
if(stxxmskhk.getYdw() != null){
StringBuffer ydw = new StringBuffer();
ydw.append("update stxxmskhk set ydw=? where stdm =?");
psupdate = conn.prepareStatement(ydw.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdw()),stxxmskhk.getYdw().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydw end*******************************/
/*********************************update ydl begin*******************************/
if(stxxmskhk.getYdl() != null){
StringBuffer ydl = new StringBuffer();
ydl.append("update stxxmskhk set ydl=? where stdm =?");
psupdate = conn.prepareStatement(ydl.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdl()),stxxmskhk.getYdl().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydl end*******************************/
/*********************************update ydq begin*******************************/
if(stxxmskhk.getYdq() != null){
StringBuffer ydq = new StringBuffer();
ydq.append("update stxxmskhk set ydq=? where stdm =?");
psupdate = conn.prepareStatement(ydq.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdq()),stxxmskhk.getYdq().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydq end*******************************/
/*********************************update ydb begin*******************************/
if(stxxmskhk.getYdb() != null){
StringBuffer ydb = new StringBuffer();
ydb.append("update stxxmskhk set ydb=? where stdm =?");
psupdate = conn.prepareStatement(ydb.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdb()),stxxmskhk.getYdb().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydb end*******************************/
logger.info("成功保存 试题详细描述代码 is " + stxxmskhk.getStdm());
} catch (SQLException e) {
// TODO 以流的方式处理数据
e.printStackTrace();
logger.debug("添加试题描述保存表时出现错误!");
String[] params = new String[] { stxxmskhk.toString() };
logger.error(MessageConst.LITEMREPORT_DAO_ADD_OPER, params, e);
throw new LabDBSysException(MessageConst.LITEMREPORT_DAO_ADD_OPER,
e);
}finally{
try {
psinsert.close();
psupdate.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
...........................................................
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Connection conn = ThreadLocalSessionManager.getConnection();
PreparedStatement psinsert = null;
PreparedStatement psupdate = null;
try {
conn.setAutoCommit(false);
/**获得序列的下一个值*/
/*int seqid = Integer.parseInt(getNextSequenceValue("TLITEMREP_S"));*/
/*******************************insert begin ****************************/
StringBuffer insert = new StringBuffer();
insert.append("insert into stxxmskhk (stdm,zqda,tg,fzy,fze,fzs,fzsi,fzw,fzl,fzq,fzb) values(?,?,?,?,?,?,?,?,?,?,?)");
psinsert = conn.prepareStatement(insert.toString());
psinsert.setInt(1, stxxmskhk.getStdm().intValue());
psinsert.setString(2, stxxmskhk.getZqda());
if(stxxmskhk.getTg() == null){
stxxmskhk.setTg("");
}
psinsert.setCharacterStream(3, new StringReader(stxxmskhk.getTg()),stxxmskhk.getTg().length());
if(stxxmskhk.getFzy() == null || "".equals(stxxmskhk.getFzy())){
stxxmskhk.setFzy(new Float(0));
}
if(stxxmskhk.getFze() == null || "".equals(stxxmskhk.getFze())){
stxxmskhk.setFze(new Float(0));
}
if(stxxmskhk.getFzs() == null || "".equals(stxxmskhk.getFzs())){
stxxmskhk.setFzs(new Float(0));
}
if(stxxmskhk.getFzsi() == null || "".equals(stxxmskhk.getFzsi())){
stxxmskhk.setFzsi(new Float(0));
}
if(stxxmskhk.getFzw() == null || "".equals(stxxmskhk.getFzw())){
stxxmskhk.setFzw(new Float(0));
}
if(stxxmskhk.getFzl() == null || "".equals(stxxmskhk.getFzl())){
stxxmskhk.setFzl(new Float(0));
}
if(stxxmskhk.getFzq() == null || "".equals(stxxmskhk.getFzq())){
stxxmskhk.setFzq(new Float(0));
}
if(stxxmskhk.getFzb() == null || "".equals(stxxmskhk.getFzb())){
stxxmskhk.setFzb(new Float(0));
}
psinsert.setFloat(4, stxxmskhk.getFzy().floatValue());
psinsert.setFloat(5, stxxmskhk.getFze().floatValue());
psinsert.setFloat(6, stxxmskhk.getFzs().floatValue());
psinsert.setFloat(7, stxxmskhk.getFzsi().floatValue());
psinsert.setFloat(8, stxxmskhk.getFzw().floatValue());
psinsert.setFloat(9, stxxmskhk.getFzl().floatValue());
psinsert.setFloat(10, stxxmskhk.getFzq().floatValue());
psinsert.setFloat(11, stxxmskhk.getFzb().floatValue());
psinsert.executeUpdate();
/*********************************insert end *****************************/
/*********************************update xxy begin*******************************/
if(stxxmskhk.getXxy() != null){
StringBuffer xxy = new StringBuffer();
xxy.append("update stxxmskhk set xxy=? where stdm =?");
psupdate = conn.prepareStatement(xxy.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxy()),stxxmskhk.getXxy().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxy end*******************************/
/*********************************update xxe begin*******************************/
if(stxxmskhk.getXxe() != null){
StringBuffer xxe = new StringBuffer();
xxe.append("update stxxmskhk set xxe=? where stdm =?");
psupdate = conn.prepareStatement(xxe.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxe()),stxxmskhk.getXxe().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxe end*******************************/
/*********************************update xxs begin*******************************/
if(stxxmskhk.getXxs() != null){
StringBuffer xxs = new StringBuffer();
xxs.append("update stxxmskhk set xxs=? where stdm =?");
psupdate = conn.prepareStatement(xxs.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxs()),stxxmskhk.getXxs().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxs end*******************************/
/*********************************update xxsi begin*******************************/
if(stxxmskhk.getXxsi() != null){
StringBuffer xxsi = new StringBuffer();
xxsi.append("update stxxmskhk set xxsi=? where stdm =?");
psupdate = conn.prepareStatement(xxsi.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxsi()),stxxmskhk.getXxsi().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxsi end*******************************/
/*********************************update ydy begin*******************************/
if(stxxmskhk.getYdy() != null){
StringBuffer ydy = new StringBuffer();
ydy.append("update stxxmskhk set ydy=? where stdm =?");
psupdate = conn.prepareStatement(ydy.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdy()),stxxmskhk.getYdy().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydy end*******************************/
/*********************************update yde begin*******************************/
if(stxxmskhk.getYde() != null){
StringBuffer yde = new StringBuffer();
yde.append("update stxxmskhk set yde=? where stdm =?");
psupdate = conn.prepareStatement(yde.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYde()),stxxmskhk.getYde().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update yde end*******************************/
/*********************************update yds begin*******************************/
if(stxxmskhk.getYds() != null){
StringBuffer yds = new StringBuffer();
yds.append("update stxxmskhk set yds=? where stdm =?");
psupdate = conn.prepareStatement(yds.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYds()),stxxmskhk.getYds().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update yds end*******************************/
/*********************************update ydsi begin*******************************/
if(stxxmskhk.getYdsi() != null){
StringBuffer ydsi = new StringBuffer();
ydsi.append("update stxxmskhk set ydsi=? where stdm =?");
psupdate = conn.prepareStatement(ydsi.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdsi()),stxxmskhk.getYdsi().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydsi end*******************************/
/*********************************update ydw begin*******************************/
if(stxxmskhk.getYdw() != null){
StringBuffer ydw = new StringBuffer();
ydw.append("update stxxmskhk set ydw=? where stdm =?");
psupdate = conn.prepareStatement(ydw.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdw()),stxxmskhk.getYdw().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydw end*******************************/
/*********************************update ydl begin*******************************/
if(stxxmskhk.getYdl() != null){
StringBuffer ydl = new StringBuffer();
ydl.append("update stxxmskhk set ydl=? where stdm =?");
psupdate = conn.prepareStatement(ydl.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdl()),stxxmskhk.getYdl().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydl end*******************************/
/*********************************update ydq begin*******************************/
if(stxxmskhk.getYdq() != null){
StringBuffer ydq = new StringBuffer();
ydq.append("update stxxmskhk set ydq=? where stdm =?");
psupdate = conn.prepareStatement(ydq.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdq()),stxxmskhk.getYdq().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydq end*******************************/
/*********************************update ydb begin*******************************/
if(stxxmskhk.getYdb() != null){
StringBuffer ydb = new StringBuffer();
ydb.append("update stxxmskhk set ydb=? where stdm =?");
psupdate = conn.prepareStatement(ydb.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdb()),stxxmskhk.getYdb().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydb end*******************************/
logger.info("成功保存 试题详细描述代码 is " + stxxmskhk.getStdm());
} catch (SQLException e) {
// TODO 以流的方式处理数据
e.printStackTrace();
logger.debug("添加试题描述保存表时出现错误!");
String[] params = new String[] { stxxmskhk.toString() };
logger.error(MessageConst.LITEMREPORT_DAO_ADD_OPER, params, e);
throw new LabDBSysException(MessageConst.LITEMREPORT_DAO_ADD_OPER,
e);
}finally{
try {
psinsert.close();
psupdate.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
...........................................................
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Connection conn = ThreadLocalSessionManager.getConnection();
PreparedStatement psinsert = null;
PreparedStatement psupdate = null;
try {
conn.setAutoCommit(false);
/**获得序列的下一个值*/
/*int seqid = Integer.parseInt(getNextSequenceValue("TLITEMREP_S"));*/
/*******************************insert begin ****************************/
StringBuffer insert = new StringBuffer();
insert.append("insert into stxxmskhk (stdm,zqda,tg,fzy,fze,fzs,fzsi,fzw,fzl,fzq,fzb) values(?,?,?,?,?,?,?,?,?,?,?)");
psinsert = conn.prepareStatement(insert.toString());
psinsert.setInt(1, stxxmskhk.getStdm().intValue());
psinsert.setString(2, stxxmskhk.getZqda());
if(stxxmskhk.getTg() == null){
stxxmskhk.setTg("");
}
psinsert.setCharacterStream(3, new StringReader(stxxmskhk.getTg()),stxxmskhk.getTg().length());
if(stxxmskhk.getFzy() == null || "".equals(stxxmskhk.getFzy())){
stxxmskhk.setFzy(new Float(0));
}
if(stxxmskhk.getFze() == null || "".equals(stxxmskhk.getFze())){
stxxmskhk.setFze(new Float(0));
}
if(stxxmskhk.getFzs() == null || "".equals(stxxmskhk.getFzs())){
stxxmskhk.setFzs(new Float(0));
}
if(stxxmskhk.getFzsi() == null || "".equals(stxxmskhk.getFzsi())){
stxxmskhk.setFzsi(new Float(0));
}
if(stxxmskhk.getFzw() == null || "".equals(stxxmskhk.getFzw())){
stxxmskhk.setFzw(new Float(0));
}
if(stxxmskhk.getFzl() == null || "".equals(stxxmskhk.getFzl())){
stxxmskhk.setFzl(new Float(0));
}
if(stxxmskhk.getFzq() == null || "".equals(stxxmskhk.getFzq())){
stxxmskhk.setFzq(new Float(0));
}
if(stxxmskhk.getFzb() == null || "".equals(stxxmskhk.getFzb())){
stxxmskhk.setFzb(new Float(0));
}
psinsert.setFloat(4, stxxmskhk.getFzy().floatValue());
psinsert.setFloat(5, stxxmskhk.getFze().floatValue());
psinsert.setFloat(6, stxxmskhk.getFzs().floatValue());
psinsert.setFloat(7, stxxmskhk.getFzsi().floatValue());
psinsert.setFloat(8, stxxmskhk.getFzw().floatValue());
psinsert.setFloat(9, stxxmskhk.getFzl().floatValue());
psinsert.setFloat(10, stxxmskhk.getFzq().floatValue());
psinsert.setFloat(11, stxxmskhk.getFzb().floatValue());
psinsert.executeUpdate();
/*********************************insert end *****************************/
/*********************************update xxy begin*******************************/
if(stxxmskhk.getXxy() != null){
StringBuffer xxy = new StringBuffer();
xxy.append("update stxxmskhk set xxy=? where stdm =?");
psupdate = conn.prepareStatement(xxy.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxy()),stxxmskhk.getXxy().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxy end*******************************/
/*********************************update xxe begin*******************************/
if(stxxmskhk.getXxe() != null){
StringBuffer xxe = new StringBuffer();
xxe.append("update stxxmskhk set xxe=? where stdm =?");
psupdate = conn.prepareStatement(xxe.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxe()),stxxmskhk.getXxe().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxe end*******************************/
/*********************************update xxs begin*******************************/
if(stxxmskhk.getXxs() != null){
StringBuffer xxs = new StringBuffer();
xxs.append("update stxxmskhk set xxs=? where stdm =?");
psupdate = conn.prepareStatement(xxs.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxs()),stxxmskhk.getXxs().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxs end*******************************/
/*********************************update xxsi begin*******************************/
if(stxxmskhk.getXxsi() != null){
StringBuffer xxsi = new StringBuffer();
xxsi.append("update stxxmskhk set xxsi=? where stdm =?");
psupdate = conn.prepareStatement(xxsi.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxsi()),stxxmskhk.getXxsi().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxsi end*******************************/
/*********************************update ydy begin*******************************/
if(stxxmskhk.getYdy() != null){
StringBuffer ydy = new StringBuffer();
ydy.append("update stxxmskhk set ydy=? where stdm =?");
psupdate = conn.prepareStatement(ydy.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdy()),stxxmskhk.getYdy().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydy end*******************************/
/*********************************update yde begin*******************************/
if(stxxmskhk.getYde() != null){
StringBuffer yde = new StringBuffer();
yde.append("update stxxmskhk set yde=? where stdm =?");
psupdate = conn.prepareStatement(yde.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYde()),stxxmskhk.getYde().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update yde end*******************************/
/*********************************update yds begin*******************************/
if(stxxmskhk.getYds() != null){
StringBuffer yds = new StringBuffer();
yds.append("update stxxmskhk set yds=? where stdm =?");
psupdate = conn.prepareStatement(yds.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYds()),stxxmskhk.getYds().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update yds end*******************************/
/*********************************update ydsi begin*******************************/
if(stxxmskhk.getYdsi() != null){
StringBuffer ydsi = new StringBuffer();
ydsi.append("update stxxmskhk set ydsi=? where stdm =?");
psupdate = conn.prepareStatement(ydsi.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdsi()),stxxmskhk.getYdsi().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydsi end*******************************/
/*********************************update ydw begin*******************************/
if(stxxmskhk.getYdw() != null){
StringBuffer ydw = new StringBuffer();
ydw.append("update stxxmskhk set ydw=? where stdm =?");
psupdate = conn.prepareStatement(ydw.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdw()),stxxmskhk.getYdw().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydw end*******************************/
/*********************************update ydl begin*******************************/
if(stxxmskhk.getYdl() != null){
StringBuffer ydl = new StringBuffer();
ydl.append("update stxxmskhk set ydl=? where stdm =?");
psupdate = conn.prepareStatement(ydl.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdl()),stxxmskhk.getYdl().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydl end*******************************/
/*********************************update ydq begin*******************************/
if(stxxmskhk.getYdq() != null){
StringBuffer ydq = new StringBuffer();
ydq.append("update stxxmskhk set ydq=? where stdm =?");
psupdate = conn.prepareStatement(ydq.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdq()),stxxmskhk.getYdq().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydq end*******************************/
/*********************************update ydb begin*******************************/
if(stxxmskhk.getYdb() != null){
StringBuffer ydb = new StringBuffer();
ydb.append("update stxxmskhk set ydb=? where stdm =?");
psupdate = conn.prepareStatement(ydb.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdb()),stxxmskhk.getYdb().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydb end*******************************/
logger.info("成功保存 试题详细描述代码 is " + stxxmskhk.getStdm());
} catch (SQLException e) {
// TODO 以流的方式处理数据
e.printStackTrace();
logger.debug("添加试题描述保存表时出现错误!");
String[] params = new String[] { stxxmskhk.toString() };
logger.error(MessageConst.LITEMREPORT_DAO_ADD_OPER, params, e);
throw new LabDBSysException(MessageConst.LITEMREPORT_DAO_ADD_OPER,
e);
}finally{
try {
psinsert.close();
psupdate.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
...........................................................
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Connection conn = ThreadLocalSessionManager.getConnection();
PreparedStatement psinsert = null;
PreparedStatement psupdate = null;
try {
conn.setAutoCommit(false);
/**获得序列的下一个值*/
/*int seqid = Integer.parseInt(getNextSequenceValue("TLITEMREP_S"));*/
/*******************************insert begin ****************************/
StringBuffer insert = new StringBuffer();
insert.append("insert into stxxmskhk (stdm,zqda,tg,fzy,fze,fzs,fzsi,fzw,fzl,fzq,fzb) values(?,?,?,?,?,?,?,?,?,?,?)");
psinsert = conn.prepareStatement(insert.toString());
psinsert.setInt(1, stxxmskhk.getStdm().intValue());
psinsert.setString(2, stxxmskhk.getZqda());
if(stxxmskhk.getTg() == null){
stxxmskhk.setTg("");
}
psinsert.setCharacterStream(3, new StringReader(stxxmskhk.getTg()),stxxmskhk.getTg().length());
if(stxxmskhk.getFzy() == null || "".equals(stxxmskhk.getFzy())){
stxxmskhk.setFzy(new Float(0));
}
if(stxxmskhk.getFze() == null || "".equals(stxxmskhk.getFze())){
stxxmskhk.setFze(new Float(0));
}
if(stxxmskhk.getFzs() == null || "".equals(stxxmskhk.getFzs())){
stxxmskhk.setFzs(new Float(0));
}
if(stxxmskhk.getFzsi() == null || "".equals(stxxmskhk.getFzsi())){
stxxmskhk.setFzsi(new Float(0));
}
if(stxxmskhk.getFzw() == null || "".equals(stxxmskhk.getFzw())){
stxxmskhk.setFzw(new Float(0));
}
if(stxxmskhk.getFzl() == null || "".equals(stxxmskhk.getFzl())){
stxxmskhk.setFzl(new Float(0));
}
if(stxxmskhk.getFzq() == null || "".equals(stxxmskhk.getFzq())){
stxxmskhk.setFzq(new Float(0));
}
if(stxxmskhk.getFzb() == null || "".equals(stxxmskhk.getFzb())){
stxxmskhk.setFzb(new Float(0));
}
psinsert.setFloat(4, stxxmskhk.getFzy().floatValue());
psinsert.setFloat(5, stxxmskhk.getFze().floatValue());
psinsert.setFloat(6, stxxmskhk.getFzs().floatValue());
psinsert.setFloat(7, stxxmskhk.getFzsi().floatValue());
psinsert.setFloat(8, stxxmskhk.getFzw().floatValue());
psinsert.setFloat(9, stxxmskhk.getFzl().floatValue());
psinsert.setFloat(10, stxxmskhk.getFzq().floatValue());
psinsert.setFloat(11, stxxmskhk.getFzb().floatValue());
psinsert.executeUpdate();
/*********************************insert end *****************************/
/*********************************update xxy begin*******************************/
if(stxxmskhk.getXxy() != null){
StringBuffer xxy = new StringBuffer();
xxy.append("update stxxmskhk set xxy=? where stdm =?");
psupdate = conn.prepareStatement(xxy.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxy()),stxxmskhk.getXxy().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxy end*******************************/
/*********************************update xxe begin*******************************/
if(stxxmskhk.getXxe() != null){
StringBuffer xxe = new StringBuffer();
xxe.append("update stxxmskhk set xxe=? where stdm =?");
psupdate = conn.prepareStatement(xxe.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxe()),stxxmskhk.getXxe().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxe end*******************************/
/*********************************update xxs begin*******************************/
if(stxxmskhk.getXxs() != null){
StringBuffer xxs = new StringBuffer();
xxs.append("update stxxmskhk set xxs=? where stdm =?");
psupdate = conn.prepareStatement(xxs.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxs()),stxxmskhk.getXxs().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxs end*******************************/
/*********************************update xxsi begin*******************************/
if(stxxmskhk.getXxsi() != null){
StringBuffer xxsi = new StringBuffer();
xxsi.append("update stxxmskhk set xxsi=? where stdm =?");
psupdate = conn.prepareStatement(xxsi.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getXxsi()),stxxmskhk.getXxsi().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update xxsi end*******************************/
/*********************************update ydy begin*******************************/
if(stxxmskhk.getYdy() != null){
StringBuffer ydy = new StringBuffer();
ydy.append("update stxxmskhk set ydy=? where stdm =?");
psupdate = conn.prepareStatement(ydy.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdy()),stxxmskhk.getYdy().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydy end*******************************/
/*********************************update yde begin*******************************/
if(stxxmskhk.getYde() != null){
StringBuffer yde = new StringBuffer();
yde.append("update stxxmskhk set yde=? where stdm =?");
psupdate = conn.prepareStatement(yde.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYde()),stxxmskhk.getYde().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update yde end*******************************/
/*********************************update yds begin*******************************/
if(stxxmskhk.getYds() != null){
StringBuffer yds = new StringBuffer();
yds.append("update stxxmskhk set yds=? where stdm =?");
psupdate = conn.prepareStatement(yds.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYds()),stxxmskhk.getYds().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update yds end*******************************/
/*********************************update ydsi begin*******************************/
if(stxxmskhk.getYdsi() != null){
StringBuffer ydsi = new StringBuffer();
ydsi.append("update stxxmskhk set ydsi=? where stdm =?");
psupdate = conn.prepareStatement(ydsi.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdsi()),stxxmskhk.getYdsi().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydsi end*******************************/
/*********************************update ydw begin*******************************/
if(stxxmskhk.getYdw() != null){
StringBuffer ydw = new StringBuffer();
ydw.append("update stxxmskhk set ydw=? where stdm =?");
psupdate = conn.prepareStatement(ydw.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdw()),stxxmskhk.getYdw().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydw end*******************************/
/*********************************update ydl begin*******************************/
if(stxxmskhk.getYdl() != null){
StringBuffer ydl = new StringBuffer();
ydl.append("update stxxmskhk set ydl=? where stdm =?");
psupdate = conn.prepareStatement(ydl.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdl()),stxxmskhk.getYdl().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydl end*******************************/
/*********************************update ydq begin*******************************/
if(stxxmskhk.getYdq() != null){
StringBuffer ydq = new StringBuffer();
ydq.append("update stxxmskhk set ydq=? where stdm =?");
psupdate = conn.prepareStatement(ydq.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdq()),stxxmskhk.getYdq().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydq end*******************************/
/*********************************update ydb begin*******************************/
if(stxxmskhk.getYdb() != null){
StringBuffer ydb = new StringBuffer();
ydb.append("update stxxmskhk set ydb=? where stdm =?");
psupdate = conn.prepareStatement(ydb.toString());
psupdate.setCharacterStream(1, new StringReader(stxxmskhk.getYdb()),stxxmskhk.getYdb().length());
psupdate.setInt(2, stxxmskhk.getStdm().intValue());
psupdate.executeUpdate();
}
/*********************************update ydb end*******************************/
logger.info("成功保存 试题详细描述代码 is " + stxxmskhk.getStdm());
} catch (SQLException e) {
// TODO 以流的方式处理数据
e.printStackTrace();
logger.debug("添加试题描述保存表时出现错误!");
String[] params = new String[] { stxxmskhk.toString() };
logger.error(MessageConst.LITEMREPORT_DAO_ADD_OPER, params, e);
throw new LabDBSysException(MessageConst.LITEMREPORT_DAO_ADD_OPER,
e);
}finally{
try {
psinsert.close();
psupdate.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
...........................................................
经过测试,一切都ok了,但是要提醒大家,一定要将将使用完的PreparedStatement变量关闭掉,因为这个系统的架构的原因Connection对象不能够在此关闭,但大家用的时候一定要在合适的位置将它关掉,否则会出现游标超长的错误。