2个回答
展开全部
java JDBC:
public static synchronized Connection getConnection() throws DBAccessException {
String driverName= "com.mysql.jdbc.Driver";
String dbURL = "jdbc:mysql://localhost:3306/teleinfomanager";
String userName = "root";
String userPwd="123456";
Connection conn = null;
try {
Class.forName(driverName);
conn = DriverManager.getConnection(dbURL,userName,userPwd);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}catch (Exception e){
log.error(e.toString());
throw new DBAccessException("不能获得数据库连接!");
}
return conn; //返回数据库 连接
}
public static synchronized Connection getConnection() throws DBAccessException {
String driverName= "com.mysql.jdbc.Driver";
String dbURL = "jdbc:mysql://localhost:3306/teleinfomanager";
String userName = "root";
String userPwd="123456";
Connection conn = null;
try {
Class.forName(driverName);
conn = DriverManager.getConnection(dbURL,userName,userPwd);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}catch (Exception e){
log.error(e.toString());
throw new DBAccessException("不能获得数据库连接!");
}
return conn; //返回数据库 连接
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询