在服务器上连接数据库,第一次连接数据库失败,重新连接一次,怎么弄
var ioc = {
dbConfig : {
jdbcUrl : 'jdbc:mysql://localhost/b2b?useUnicode=true&characterEncoding=UTF-8',
name : 'root',
password : '123456',
driver : 'com.mysql.jdbc.Driver'
}
}
static SimpleDataSource dataSource;
static{
Ioc ioc = new NutIoc(new JsonLoader("com/tongxin/b2b/ioc/db.js"));
DBHelper db = ioc.get(DBHelper.class, "dbConfig");
ioc.depose();
try {
Class.forName(db.getDriver());
} catch (ClassNotFoundException e) {
new DBHelper();
e.printStackTrace();
}
dataSource = new SimpleDataSource();
dataSource.setJdbcUrl(db.getJdbcUrl());
dataSource.setUsername(db.getName());
dataSource.setPassword(db.getPassword());
dao = new NutDao(dataSource);
}