本文整理汇总了Java中com.mysql.jdbc.jdbc2.optional.MysqlDataSource.setPort方法的典型用法代码示例。如果您正苦于以下问题:Java MysqlDataSource.setPort方法的具体用法?Java MysqlDataSource.setPort怎么用?Java MysqlDataSource.setPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mysql.jdbc.jdbc2.optional.MysqlDataSource
的用法示例。
在下文中一共展示了MysqlDataSource.setPort方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
public void init() throws SQLException, RuleBaseException, TeEngineMlException, ParserRunException
{
ruleBaseName = "origdirt";
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName("qa-srv");
dataSource.setPort(3308);
dataSource.setUser("db_readonly");
//dataSource.setPassword("");
distSimConnection = dataSource.getConnection();
DistSimParameters originalDirtParameters =
new DistSimParameters("original_dirt.od_templates", "original_dirt.od_rules", LIMIT_DISTSIM_RULES, 2*Constants.DEFAULT_DIRT_LIKE_RESOURCES_CACHE_SIZE, Constants.DEFAULT_DIRT_LIKE_RESOURCES_CACHE_SIZE);
ruleBase = new DistSimRuleBase(distSimConnection,originalDirtParameters,ruleBaseName,parserMode);
parser = ParserFactory.getParser(miniparParameter);
}
示例2: getDataSource
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
public static DataSource getDataSource(
String hostName,
int port,
String username,
String passwordClear,
String databaseName)
{
if (hostName == null) { throw new IllegalArgumentException("hostName cannot be null"); }
if (username == null) { throw new IllegalArgumentException("username cannot be null"); }
if (passwordClear == null) { throw new IllegalArgumentException("passwordClear cannot be null"); }
if (databaseName == null) { throw new IllegalArgumentException("databaseName cannot be null"); }
MysqlDataSource ds = new MysqlDataSource();
ds.setServerName(hostName);
ds.setPort(port);
ds.setUser(username);
ds.setPassword(passwordClear);
ds.setDatabaseName(databaseName);
return ds;
}
示例3: getAntiExploitConnection
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
private Connection getAntiExploitConnection() {
try {
MysqlDataSource mySqlDataSource = new MysqlDataSource();
mySqlDataSource.setDatabaseName(AntiExploit.getInstance().getConfiguration().getConfig().getDatabase());
mySqlDataSource.setUser(AntiExploit.getInstance().getConfiguration().getConfig().getUsername());
mySqlDataSource.setPassword(AntiExploit.getInstance().getConfiguration().getConfig().getPassword());
mySqlDataSource.setServerName(AntiExploit.getInstance().getConfiguration().getConfig().getHost());
mySqlDataSource.setPort(AntiExploit.getInstance().getConfiguration().getConfig().getPort());
return mySqlDataSource.getConnection();
} catch (SQLException ex) {
AntiExploit.getInstance().getLogger().error("Failed to connect to MySQL database!");
ex.printStackTrace();
}
return null;
}
示例4: dropDatabase
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
public static void dropDatabase(
String hostName,
int port,
String username,
String passwordClear,
String databaseName)
{
if (hostName == null) { throw new IllegalArgumentException("hostName cannot be null"); }
if (username == null) { throw new IllegalArgumentException("username cannot be null"); }
if (passwordClear == null) { throw new IllegalArgumentException("passwordClear cannot be null"); }
if (databaseName == null) { throw new IllegalArgumentException("databaseName cannot be null"); }
MysqlDataSource rootDs = new MysqlDataSource();
rootDs.setServerName(hostName);
rootDs.setPort(port);
rootDs.setUser(username);
rootDs.setPassword(passwordClear);
rootDs.setDatabaseName("mysql");
try
{
DatabaseHelper.execute(rootDs, String.format("DROP DATABASE `%s`;", databaseName));
}
catch(SQLException e)
{
throw new RuntimeException(e);
}
}
示例5: getAdminDataSource
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
/**
* Returns a DataSource for the information schema in the target MySQL database.
*
* @return a DataSource for the information schema in the target MySQL server.
* @since 1.0
*/
@Override public DataSource getAdminDataSource()
{
MysqlDataSource ds = new MysqlDataSource();
ds.setServerName(this.getHostName());
ds.setPort(this.getPort());
ds.setUser(this.getAdminUsername());
ds.setPassword(this.getAdminPassword());
ds.setDatabaseName("information_schema");
return ds;
}
示例6: getAppDataSource
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
/**
* Returns a DataSource for the application schema that this instance represents, in the target MySQL server.
*
* @return a DataSource for the application schema in the target MySQL server.
* @since 1.0
*/
@Override public DataSource getAppDataSource()
{
MysqlDataSource ds = new MysqlDataSource();
ds.setServerName(this.getHostName());
ds.setPort(this.getPort());
ds.setUser(this.getAdminUsername());
ds.setPassword(this.getAdminPassword());
ds.setDatabaseName(this.getDatabaseName());
return ds;
}
示例7: getDataSource
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
/**
* wrap a datasource with a tomcat jdbc pool
* Connection con = null;
*
* TODO: implement FUTURE connections
* try {
* Future<Connection> future = datasource.getConnectionAsync();
* while (!future.isDone()) {
* System.out.println(
* "Connection is not yet available. Do some background work");
* try {
* Thread.sleep(100); //simulate work
* }catch (InterruptedException x) {
* Thread.currentThread().interrupt();
* }
* }
* con = future.get(); //should return instantly
* Statement st = con.createStatement();
* ResultSet rs = st.executeQuery("select * from user");
*
* @return
*/
public static DataSource getDataSource() {
MysqlDataSource ds = new MysqlDataSource();
org.apache.tomcat.jdbc.pool.DataSource dsx = new org.apache.tomcat.jdbc.pool.DataSource();
PoolProperties p = new PoolProperties();
if (System.getProperty("PARAM1") != null
&& System.getProperty("PARAM1").equalsIgnoreCase("production")) {
ds.setServerName(sourceURL);
ds.setPassword(password);
p.setUrl(sourceURL);
}else{
ds.setServerName(backupURL);
ds.setPassword(backupPassword);
p.setUrl(backupURL);
p.setPassword(backupPassword);
}
ds.setPort(sourcePort);
ds.setDatabaseName(dbName);
ds.setUser(userName);
p.setDriverClassName("com.mysql.jdbc.Driver");
p.setUsername(userName);
p.setJmxEnabled(true);
p.setTestWhileIdle(false);
p.setTestOnBorrow(true);
p.setValidationQuery("SELECT 1");
p.setTestOnReturn(false);
p.setValidationInterval(30000);
p.setTimeBetweenEvictionRunsMillis(30000);
p.setMaxActive(100);
p.setInitialSize(10);
p.setMaxWait(10000);
p.setRemoveAbandonedTimeout(60);
p.setMinEvictableIdleTimeMillis(30000);
p.setMinIdle(10);
p.setLogAbandoned(true);
p.setRemoveAbandoned(true);
p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
+ "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
// wrap and allow for lazy queue fun
dsx.setPoolProperties(p);
dsx.setFairQueue(true);
dsx.setDataSource(ds);
return dsx;
}