连接数据库
来源:互联网 发布:雪茄属于淘宝禁售品吗 编辑:程序博客网 时间:2024/05/28 11:28
private static final String url="jdbc:mysql://localhost:3306/数据库名";
private static final String user="root";
private static final String password="密码";
//加载驱动
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//创建连接
public static Connection getConnection() throws SQLException{
return DriverManager.getConnection(url,user,password);
}
//关闭连接
public static void close(ResultSet res,PreparedStatement sta,Connection conn) throws SQLException{
if(res!=null){
res.close();
}
if(sta!=null){
sta.close();
}
if(conn!=null){
conn.close();
}
}
private static final String user="root";
private static final String password="密码";
//加载驱动
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//创建连接
public static Connection getConnection() throws SQLException{
return DriverManager.getConnection(url,user,password);
}
//关闭连接
public static void close(ResultSet res,PreparedStatement sta,Connection conn) throws SQLException{
if(res!=null){
res.close();
}
if(sta!=null){
sta.close();
}
if(conn!=null){
conn.close();
}
}
0 0
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 基于websocket和java实现webshell访问docker容器
- Flume+Kafka+Sparkstreaming日志分析
- MySQL免安装版下载安装及常用命令
- zookeeper原理
- 介绍几种ORM框架
- 连接数据库
- [操作系统概念]第七部分——文件与目录
- 最长&最短文本
- Mysql入门
- ZOJ 3204 Connect them
- 杭电 hdu 1003. Max Sum
- FRC(FIRST Robotics Competition) Pneumatics Manual 气动说明
- 七牛上传图片(前台JS+后台C#API获取token)
- 前端技能练习:html网页布局css属性position的属性值的描述