将更新表a和表b的操作放在一个事务中,出错就rollback
解决方案 »
- 请问我从数据库中读取了一个流后 ,如何在JSP页面上放映,前提是我不希望将流保存到服务器的硬盘生成一个文件,页就是说我想直接通过流来放映.
- 关于日期的传递
- fusionchart v3导出pdf
- 求velocity的Eclipse插件Velocity Web Edit
- 谁有在linux下运行的eWebEditor
- 请问<form name="form" method="get"action="http://localhost:8080/servlet/form>
- 大家看下我这个存储表单的代码
- 关于SERVLET的一个小问题
- jsp&java
- ssm+debbo+zk+mysql+redis
- 在SQL数据库中的汉字为什么在jsp页面中无法正确显示
- 单独 执行页面 是500服务器内部错误,如果从主页上连接的话就是404请求资源不可用错误,是个小的jsp文件,是个赌博游戏,可以帮我看看吗?谢谢
public boolean addProduct(String productname,String kindid ,String model,String weight,
String price,String explain,String picurlid ,String companyid)
{
ResultSet rs=null;
boolean bolRet = false;
List co_List = new ArrayList();
String sql = " INSERT INTO CO_PRODUCT("
+ " productNAME," //1.名称
+ " kindID," //2.类别ID
+ " model," //3.规格
+ " weight," //4.重量
+ " price," //5.价格
+ " explain," //6.说明
+ " REGSITERTIME," //7.注册时间
+ " PICURLID," //8.图片ID
+ " COMPANYID," //9.对应企业ID
+ " ISAVAILABILITY )" //10是否生效
+ " VALUES(?,?,?,?,?,?,?,?,?,?)";
DatabaseTool tool = DatabaseTool.getInstance(sql);
//获取制定格式的当前时间
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd hh-mm-ss");
java.util.Date currentTime_1 = new java.util.Date();
String now = (String) formatter.format(currentTime_1);
try
{
tool.setString(1,productname);
tool.setString(2,kindid);
tool.setString(3,model);
tool.setString(4,weight);
tool.setString(5,price);
tool.setString(6,explain);
tool.setString(7,now);
tool.setString(8,picurlid);
tool.setString(9,companyid);
tool.setInt(10,0);
tool.executeUpdate();
bolRet = true; } catch (SQLException e)
{
bolRet = false;
System.out.println("Error in news_newsInsert " + e);
} finally {
tool.close(); //关闭连接
tool = null;
return bolRet;
}
}
给一段伪代码:connection1.setAutoCommit(false)
try{
boolean ok1= SQLupdate1...
boolean ok2 = SQLupdate2...
if( ok1 && ok2 ) {
connection1.commit();
} else {
connection1.rollback();
}catch(SQLException se){
System.out.println( se );
connection1.rollback();
connection1.close();
}
...