【发布时间】:2014-02-28 21:11:41
【问题描述】:
我一直在玩 JDBC 驱动程序。我想从经验代码大师那里得到一些建议。我想知道这是否是查找是否连接到数据库的好方法。如果不是,有人可以告诉我他们会怎么做吗?
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:mysql://localhost/"+database+"?+user="+user+"&password="+password);
} catch (SQLException e) {
System.out.println(e.getMessage());
if (con != null) {
System.out.println("hello");
} else {
System.out.println("Not Connected!");
}
}
我非常感谢所有有用的 cmets。非常感谢。
【问题讨论】: