private void disconnect() throws Exception {
if (con != null) {
con.close();
con = null;
}
}
protected void connect() throws Exception {
disconnect();
con = getConnection();
}
上面是一般寫法.
public Connection getConnection() throws Exception {
Class.forName(props.getProperty("driver"));
String url = props.getProperty("url");
Connection con = DriverManager.getConnection(url, props);
// showWarnings(con.getWarnings());
initLanguage(con);
return con;
}
if (con != null) {
con.close();
con = null;
}
}
protected void connect() throws Exception {
disconnect();
con = getConnection();
}
上面是一般寫法.
public Connection getConnection() throws Exception {
Class.forName(props.getProperty("driver"));
String url = props.getProperty("url");
Connection con = DriverManager.getConnection(url, props);
// showWarnings(con.getWarnings());
initLanguage(con);
return con;
}