public static int exeUpdate(String sqlName) {
int result = 0;
// 成功返回1
Connection conn = null;
Statement stmt = null; try {
DataSource ds = getDataSource(null);
conn = ds.getConnection(); if (conn == null) {
System.out.println("不能得到连接");
}
String command = sqlName.trim();
conn.setAutoCommit(false);
stmt = conn.createStatement();
result = stmt.executeUpdate(command);
commit(conn);
stmt.close();
stmt = null;
return result;
} catch (Exception e) { result = -1;
if (conn != null) {
rollback(conn); try {
conn.close();
conn = null;
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} }
if (stmt != null) {
try {
stmt.close();
stmt = null;
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} } finally { try {
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e) {
e.printStackTrace();
} }
return result;
}
int result = 0;
// 成功返回1
Connection conn = null;
Statement stmt = null; try {
DataSource ds = getDataSource(null);
conn = ds.getConnection(); if (conn == null) {
System.out.println("不能得到连接");
}
String command = sqlName.trim();
conn.setAutoCommit(false);
stmt = conn.createStatement();
result = stmt.executeUpdate(command);
commit(conn);
stmt.close();
stmt = null;
return result;
} catch (Exception e) { result = -1;
if (conn != null) {
rollback(conn); try {
conn.close();
conn = null;
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} }
if (stmt != null) {
try {
stmt.close();
stmt = null;
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} } finally { try {
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e) {
e.printStackTrace();
} }
return result;
}
解决方案 »
- struts2 和 spring 集成出现的一个怪问题,请各位大侠献计
- java 如何调用 linux下的 。so文件 给我接口了 就是启动服务
- 问一个网站链接的问题
- struts2
- struts框架使用实体对象传值得到的都为空值,求救!!
- 请推荐几本学习java ee 5的好书
- 用ibatis出现异常,com.ibatis.common.jdbc.exception.NestedSQLException
- 请问关于Struts与动态表单的问题
- 关于实体类(POJO)里面能不能写逻辑的疑问
- 问一下下面这个action标签几个属性的用法
- 自己在MyEclipse中做猜数字,碰到错误500,代码贴出来了,请解释原因及改进方法,多谢(分不多...)
- Ext 分页提交参数不正常。在线等
int result = 0;
// 成功返回1
Connection conn = null;
Statement stmt = null;try {
//创建数据库连接
DataSource ds = getDataSource(null);
conn = ds.getConnection();//判断连接是否为空
if (conn == null) {
System.out.println("不能得到连接");
}
//去除参数前后空格
String command = sqlName.trim();
conn.setAutoCommit(false);
//创建容器
stmt = conn.createStatement();
//修改数据
result = stmt.executeUpdate(command);
commit(conn);
//关闭容器
stmt.close();
stmt = null;
return result;
} catch (Exception e) {
//抛出异常处理
result = -1;
if (conn != null) {
rollback(conn);//数据库回滚try {
//关闭连接
conn.close();
conn = null;
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}}
//如果容器不为null,关闭容器
if (stmt != null) {
try {
stmt.close();
stmt = null;
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}} finally {try {
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e) {
e.printStackTrace();
}}
return result;
}
stmt.executeUpdate(command);不过看你的那个参数是什么了
这个参数是这样的String command = Xml2Sql.getStatement(sqlName, params);