如题,代码如下:
/*
* DAO具体方法实现
* 编辑帐户 zhwei 2006-04-13
* @param identityID 帐户ID,-1时添加,否则修改;name 用户名;indentityType 帐户类型
* @return int 成功返回帐户的ID,否则返回-1
* @throws SQLException
*/
private int EditSecurityIdentity(int identityID,String name,String indentityType) throws SQLException{
int returnID=-1;
Connection cn=null;
try{
cn=dm.getConnection();//dm是DBConnectionManager
boolean bln=false;
String strSQL="";
if(identityID==-1){
strSQL="insert into SecurityIdentity (Name,IdentityType)";
strSQL=strSQL + " values ('" + name + "','" + indentityType + "')";
}else{
strSQL="update SecurityIdentity set Name='" + name + "',";
strSQL=strSQL + "IdentityType='" + indentityType + "'";
strSQL=strSQL + " where ID=" + identityID;
}
System.out.println("EditSecurityIdentity SQL:" + strSQL);
//执行编辑
Statement stmt=cn.createStatement();
int exeRow=stmt.executeUpdate(strSQL);
System.out.println("EditSecurityIdentity Add ExeRowCount=" + exeRow);
// cn.commit();//使用此句是提示:在事务管理过程中不能Commit
System.out.println(bln);
if(identityID==-1){
System.out.println("--EditSecurityIdentity Success--");
strSQL="select ID from SecurityIdentity where ";
strSQL=strSQL + "Name='" + name + "' and IdentityType='" + indentityType + "'";
ResultSet rs = stmt.executeQuery(strSQL);
if(rs.next())
returnID=rs.getInt("ID");//编辑成功,返回帐户ID
rs.close();
rs=null;
}else
returnID=identityID;
stmt.close();
stmt=null;
}catch(SQLException ex){
System.out.println("业务操作异常,"+ex.getMessage());
throw new SQLException(ex.getMessage());
}catch(DBConnectException ex){
System.out.println("数据库连接异常,"+ex.getMessage());
throw new SQLException(ex.getMessage());
}catch(Exception ex){
System.out.println("怪异异常,"+ex.getMessage());
throw new SQLException("怪异异常,"+ex.getMessage());
}finally{
cn=null;
}
System.out.println("EditSecurityIdentity returnID=" + returnID);
return returnID;
}
SQL语句正确,exeRow=1,returnID=96,但数据表中就是没有记录。请问这是什么原因?应该如何解决?谢谢!
/*
* DAO具体方法实现
* 编辑帐户 zhwei 2006-04-13
* @param identityID 帐户ID,-1时添加,否则修改;name 用户名;indentityType 帐户类型
* @return int 成功返回帐户的ID,否则返回-1
* @throws SQLException
*/
private int EditSecurityIdentity(int identityID,String name,String indentityType) throws SQLException{
int returnID=-1;
Connection cn=null;
try{
cn=dm.getConnection();//dm是DBConnectionManager
boolean bln=false;
String strSQL="";
if(identityID==-1){
strSQL="insert into SecurityIdentity (Name,IdentityType)";
strSQL=strSQL + " values ('" + name + "','" + indentityType + "')";
}else{
strSQL="update SecurityIdentity set Name='" + name + "',";
strSQL=strSQL + "IdentityType='" + indentityType + "'";
strSQL=strSQL + " where ID=" + identityID;
}
System.out.println("EditSecurityIdentity SQL:" + strSQL);
//执行编辑
Statement stmt=cn.createStatement();
int exeRow=stmt.executeUpdate(strSQL);
System.out.println("EditSecurityIdentity Add ExeRowCount=" + exeRow);
// cn.commit();//使用此句是提示:在事务管理过程中不能Commit
System.out.println(bln);
if(identityID==-1){
System.out.println("--EditSecurityIdentity Success--");
strSQL="select ID from SecurityIdentity where ";
strSQL=strSQL + "Name='" + name + "' and IdentityType='" + indentityType + "'";
ResultSet rs = stmt.executeQuery(strSQL);
if(rs.next())
returnID=rs.getInt("ID");//编辑成功,返回帐户ID
rs.close();
rs=null;
}else
returnID=identityID;
stmt.close();
stmt=null;
}catch(SQLException ex){
System.out.println("业务操作异常,"+ex.getMessage());
throw new SQLException(ex.getMessage());
}catch(DBConnectException ex){
System.out.println("数据库连接异常,"+ex.getMessage());
throw new SQLException(ex.getMessage());
}catch(Exception ex){
System.out.println("怪异异常,"+ex.getMessage());
throw new SQLException("怪异异常,"+ex.getMessage());
}finally{
cn=null;
}
System.out.println("EditSecurityIdentity returnID=" + returnID);
return returnID;
}
SQL语句正确,exeRow=1,returnID=96,但数据表中就是没有记录。请问这是什么原因?应该如何解决?谢谢!
解决方案 »
- 明明已经释放连接池了,还是提示错误。请大家帮忙看看阿
- 超级郁闷的问题——有关wap视频下载的
- 由于不熟悉jsp要改别人的程序遇到的幼稚问题!
- 如何在spring的quartz中访问DAO对数据库操作?
- 门户网站项目外包,感兴趣的或知道有比较好的软件公司的,请进来:)
- struts中,在验证actionform时,如何判断input中输入的字符串(日期:yyyymmdd)比当前日期晚两天?
- 能不能在ResultSet的结果集中进行统计操作了?
- javamail收信时报错:There is no such mailbox on this server,真的找不到错误。各位救我!
- JDBC的疑问?
- ?? 将jsp生成的页面保存成html ??
- 选择JSP的理由?
- 同一页的多页面显示
一般来说只有写操作的sql才有必要做为一个原子操作写事务.select一般很少写在事务里面.