本文整理汇总了Java中com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource.setDatabaseName方法的典型用法代码示例。如果您正苦于以下问题:Java MysqlConnectionPoolDataSource.setDatabaseName方法的具体用法?Java MysqlConnectionPoolDataSource.setDatabaseName怎么用?Java MysqlConnectionPoolDataSource.setDatabaseName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
的用法示例。
在下文中一共展示了MysqlConnectionPoolDataSource.setDatabaseName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDataSource
import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入方法依赖的package包/类
@Override
public DataSource getDataSource() {
MysqlConnectionPoolDataSource dataSource = new MysqlConnectionPoolDataSource();// do not use connection pool
dataSource.setServerName(this.host);
dataSource.setPort(this.port);
dataSource.setDatabaseName(this.db);
dataSource.setUser(this.user);
dataSource.setPassword(this.password);
dataSource.setAllowMultiQueries(true);
return dataSource;
}
示例2: connectToDatabase
import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入方法依赖的package包/类
private void connectToDatabase() throws ClassNotFoundException {
String type = getConfig().getString("database.type"),
host = getConfig().getString("database.host"),
dbName = getConfig().getString("database.db_name"),
user = getConfig().getString("database.user"),
pass = getConfig().getString("database.pass");
int port = getConfig().getInt("database.port");
SQLBackend dbType = SQLBackend.parse(type);
stmts = new StatementProvider("/db", dbType);
switch(dbType) {
case MYSQL:
Class.forName("com.mysql.jdbc.Driver");
MysqlConnectionPoolDataSource msqlpool = new MysqlConnectionPoolDataSource();
msqlpool.setDatabaseName(dbName);
msqlpool.setUser(user);
msqlpool.setPassword(pass);
msqlpool.setServerName(host);
msqlpool.setPort(port);
connections = msqlpool;
break;
case POSTGRES:
Class.forName("org.postgresql.Driver");
PGPoolingDataSource pgpool = new PGPoolingDataSource();
pgpool.setDataSourceName("mcanalytics-pg-pool");
pgpool.setServerName(host);
pgpool.setPortNumber(port);
pgpool.setDatabaseName(dbName);
pgpool.setUser(user);
pgpool.setPassword(pass);
pgpool.setMaxConnections(10);
connections = pgpool;
break;
default:
throw new IllegalStateException("unsupported database type in config.yml");
}
}