1 Star 0 Fork 0

drguo/SpringWebMVC

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DBUtil.java 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
package utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBUtil {
private static final String url = "jdbc:mysql://localhost:3306/test";
private static final String driver = "com.mysql.jdbc.Driver";
private static final String un = "root";
private static final String psd = "728972";
public static Connection connect() {
Connection con = null;
try {
Class.forName(driver);
con = DriverManager.getConnection(url, un, psd);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
public static void free(Connection con, PreparedStatement pst, ResultSet rs) {
try {
if (rs != null) {
rs.close();
}
if (pst != null) {
pst.close();
}
if (con != null) {
con.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 测试
public static void main(String[] args) {
Connection con = connect();
System.out.println(con);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/drguo/SpringWebMVC.git
git@gitee.com:drguo/SpringWebMVC.git
drguo
SpringWebMVC
SpringWebMVC
master

搜索帮助