public class DBManager {
private static final String DRIVER = "org.gjt.mm.mysql.Driver";//MySQL資料庫驅動類
private static final String URL = "jdbc:mysql://localhost:3306/bank";//MySQL資料庫的連線串
private static final String USER_NAME = "root";//使用者名稱
private static final String PASSWORD = "root";//密碼
//構造方法前執行
static{
try{
Class.forName(DRIVER);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
//建立一個連線
public Connection getConnection() {
Connection con = null;
try {
con = DriverManager.getConnection(URL,USER_NAME,PASSWORD);
} catch (SQLException e) {
return con;
//釋放資源
public void releaseResources(Connection con, Statement stmt,ResultSet result) {
if(result != null) {
result.close();
if(stmt != null) {
stmt.close();
if(con != null) {
con.close();
} catch (Exception e) {
public class DBManager {
private static final String DRIVER = "org.gjt.mm.mysql.Driver";//MySQL資料庫驅動類
private static final String URL = "jdbc:mysql://localhost:3306/bank";//MySQL資料庫的連線串
private static final String USER_NAME = "root";//使用者名稱
private static final String PASSWORD = "root";//密碼
//構造方法前執行
static{
try{
Class.forName(DRIVER);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
//建立一個連線
public Connection getConnection() {
Connection con = null;
try {
con = DriverManager.getConnection(URL,USER_NAME,PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
//釋放資源
public void releaseResources(Connection con, Statement stmt,ResultSet result) {
try {
if(result != null) {
result.close();
}
if(stmt != null) {
stmt.close();
}
if(con != null) {
con.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}