public class DBManage
{
public static final String DRIVERNAME = "org.gjt.mm.mysql.Driver";
{
public static final String DRIVERNAME = "org.gjt.mm.mysql.Driver";
public static final String URL = "jdbc:mysql://127.0.0.1:3306/manage";
// 获得一个数据库连接
public static Connection getConnection()
{
Connection conn = null;
try
{
Class.forName(DRIVERNAME);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
try
{
conn = DriverManager.getConnection(URL, "root", "root");
}
catch (SQLException e)
{
e.printStackTrace();
}
return conn;
}
public static Connection getConnection()
{
Connection conn = null;
try
{
Class.forName(DRIVERNAME);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
try
{
conn = DriverManager.getConnection(URL, "root", "root");
}
catch (SQLException e)
{
e.printStackTrace();
}
return conn;
}
public static void main(String[] args)
{
// 测试数据库连接是否成功,如果conn的值不为null,则表示数据库连接成功
Connection conn = DBManage.getConeection();
System.out.println("conn = " + conn);
}
}
阅读(819) | 评论(0) | 转发(0) |
0 {
// 测试数据库连接是否成功,如果conn的值不为null,则表示数据库连接成功
Connection conn = DBManage.getConeection();
System.out.println("conn = " + conn);
}
}
上一篇:JDK 环境变量
相关热门文章 给主人留下些什么吧!~~ 评论热议