我正在使用Java編寫一個red5應用程序 ,我正在使用c3p0進行數據庫交互。java c3p0:我如何配置autoreconnect = true?
看來,在我的MySQL服務器超時連接後,我的應用程序停止工作,並建議配置autoreconnect = true。
我該怎麼做?
這是我用於創建數據源的功能:
private ComboPooledDataSource _createDataSource() {
Properties props = new Properties();
// Looks for the file 'database.properties' in {TOMCAT_HOME}\webapps\{RED5_HOME}\WEB-INF\
try {
FileInputStream in = new FileInputStream(System.getProperty("red5.config_root") + "/database.properties");
props.load(in);
in.close();
} catch (IOException ex) {
log.error("message: {}", ex.getMessage());
log.error("stack trace: " + ExceptionUtils.getFullStackTrace(ex));
return null;
}
// It will load the driver String from properties
String drivers = props.getProperty("jdbc.drivers");
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password");
ComboPooledDataSource cpds = new ComboPooledDataSource();
try {
cpds.setDriverClass(drivers);
} catch (PropertyVetoException ex) {
log.error("message: {}", ex.getMessage());
log.error("stack trace: " + ExceptionUtils.getFullStackTrace(ex));
return null;
}
cpds.setJdbcUrl(url);
cpds.setUser(username);
cpds.setPassword(password);
cpds.setMaxStatements(180);
return cpds;
}
是的!好多了。 autoreconnect正式被MYSQL強烈推薦 - 它可能會導致腐敗問題。對不起,沒有鏈接 - 幾年前見過。 – MJB 2011-04-24 23:39:53