6 Star 0 Fork 0

NdyRa / SHOP

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Basedao.java 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
“用户名” 提交于 2020-06-24 02:16 . 初始化
package com.hr.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Basedao {
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getconn(){
Connection conn=null;
try {
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_shop?useUnicode=true&characterEncoding=UTF-8","root","root");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public static void closeall(ResultSet rs,Statement ps,Connection conn){
try {
if(rs!=null)
rs.close();
if(ps!=null)
ps.close();
if(conn!=null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static int exectuIUD(String sql,Object[] params){
int count=0;
Connection conn=Basedao.getconn();
PreparedStatement ps=null;
try {
ps=conn.prepareStatement(sql);
if(params!=null){
for (int i = 0; i < params.length; i++) {
ps.setObject(i+1, params[i]);
}
}
count=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
Basedao.closeall(null, ps, conn);
}
return count;
}
}
1
https://gitee.com/ndyra/SHOP.git
git@gitee.com:ndyra/SHOP.git
ndyra
SHOP
SHOP
master

搜索帮助