当前位置: 首页>>代码示例>>Java>>正文


Java MysqlDataSource类代码示例

本文整理汇总了Java中com.mysql.jdbc.jdbc2.optional.MysqlDataSource的典型用法代码示例。如果您正苦于以下问题:Java MysqlDataSource类的具体用法?Java MysqlDataSource怎么用?Java MysqlDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MysqlDataSource类属于com.mysql.jdbc.jdbc2.optional包,在下文中一共展示了MysqlDataSource类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readTable

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
public void readTable(String user, String password, String server){
     MysqlDataSource dataSource = new MysqlDataSource();
     dataSource.setUser(user);
     dataSource.setPassword(password);
     dataSource.setServerName(server);
     try{
          Connection conn = dataSource.getConnection();
          Statement stmt = conn.createStatement();
          ResultSet rs = stmt.executeQuery("SELECT * FROM data_science.books");
          while (rs.next()){
               int id = rs.getInt("id");
               String book = rs.getString("book_name");
               String author = rs.getString("author_name");
               Date dateCreated = rs.getDate("date_created");
               System.out.format("%s, %s, %s, %s\n", id, book, author, dateCreated);
          }
          rs.close();
          stmt.close();
          conn.close();
     }catch (Exception e){
          //Your exception handling mechanism goes here.
     }
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:24,代码来源:TestDB.java

示例2: testBug19169

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
/**
 * Tests fix for BUG#19169 - ConnectionProperties (and thus some
 * subclasses) are not serializable, even though some J2EE containers
 * expect them to be.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug19169() throws Exception {
    MysqlDataSource toSerialize = new MysqlDataSource();
    toSerialize.setZeroDateTimeBehavior("convertToNull");

    boolean testBooleanFlag = !toSerialize.getAllowLoadLocalInfile();
    toSerialize.setAllowLoadLocalInfile(testBooleanFlag);

    int testIntFlag = toSerialize.getBlobSendChunkSize() + 1;
    toSerialize.setBlobSendChunkSize(String.valueOf(testIntFlag));

    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    ObjectOutputStream objOut = new ObjectOutputStream(bOut);
    objOut.writeObject(toSerialize);
    objOut.flush();

    ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(bOut.toByteArray()));

    MysqlDataSource thawedDs = (MysqlDataSource) objIn.readObject();

    assertEquals("convertToNull", thawedDs.getZeroDateTimeBehavior());
    assertEquals(testBooleanFlag, thawedDs.getAllowLoadLocalInfile());
    assertEquals(testIntFlag, thawedDs.getBlobSendChunkSize());
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:32,代码来源:DataSourceRegressionTest.java

示例3: testBug16791

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
/**
 * Tests fix for BUG#16791 - NullPointerException in MysqlDataSourceFactory
 * due to Reference containing RefAddrs with null content.
 * 
 * @throws Exception
 *             if the test fails
 */
public void testBug16791() throws Exception {
    MysqlDataSource myDs = new MysqlDataSource();
    myDs.setUrl(dbUrl);
    Reference asRef = myDs.getReference();
    System.out.println(asRef);

    removeFromRef(asRef, "port");
    removeFromRef(asRef, NonRegisteringDriver.USER_PROPERTY_KEY);
    removeFromRef(asRef, NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
    removeFromRef(asRef, "serverName");
    removeFromRef(asRef, "databaseName");

    //MysqlDataSource newDs = (MysqlDataSource)
    new MysqlDataSourceFactory().getObjectInstance(asRef, null, null, null);
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:23,代码来源:DataSourceRegressionTest.java

示例4: initDatasource

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
public void initDatasource(YadaConfiguration config) throws NamingException {
	MysqlDataSource dataSource = new MysqlDataSource();
	dataSource.setDatabaseName(config.getString("config/database/dbName"));
	dataSource.setUser(config.getString("config/database/user"));
	dataSource.setPassword(config.getString("config/database/password"));
	dataSource.setServerName(config.getString("config/database/server"));
	SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
	builder.bind("java:comp/env/jdbc/yadatestdb", dataSource);
	super.dataSource = dataSource;
	builder.activate();
	// Database
	Flyway flyway = new Flyway();
	flyway.setLocations("filesystem:schema"); // Where sql test scripts are stored
	flyway.setDataSource(dataSource);
	flyway.clean();
	flyway.migrate();
}
 
开发者ID:xtianus,项目名称:yadaframework,代码行数:18,代码来源:YadaTestConfig.java

示例5: DataIntegrityTestTool

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
public DataIntegrityTestTool(Properties prop) throws Exception{
    
    this.setName("data-integrity-test-thread");
    
    srcDs = new MysqlDataSource();
    srcDs.setURL(prop.getProperty(DMLQueryTool.PROP_MSR_SRC_URL));
    srcDs.setUser(prop.getProperty(DMLQueryTool.PROP_MSR_SRC_USERNAME));
    srcDs.setPassword(prop.getProperty(DMLQueryTool.PROP_MSR_SRC_PASSWROD));
    
    destCount = Integer.parseInt(prop.getProperty(DMLQueryTool.PROP_MSR_DEST_COUNT));
    destDs = new MysqlDataSource[destCount];
    for(int i=0; i<destCount; i++){
        destDs[i] = new MysqlDataSource();
        destDs[i].setURL(prop.getProperty(String.format(DMLQueryTool.PROP_MSR_DEST_URL, i)));
        destDs[i].setUser(prop.getProperty(String.format(DMLQueryTool.PROP_MSR_DEST_USERNAME, i)));
        destDs[i].setPassword(prop.getProperty(String.format(DMLQueryTool.PROP_MSR_DEST_PASSWORD, i)));
    }
}
 
开发者ID:kakao,项目名称:adt,代码行数:19,代码来源:DataIntegrityTestTool.java

示例6: beforeClass

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception{
    initializeTestEnv();
    
    final int sleepCount = 30;
    
    LOGGER.debug("sleep " + sleepCount + "sec for generating enough test data");
    for(int i=1; i<=sleepCount; i++){
        LOGGER.debug(i + "/" + sleepCount);
        Thread.sleep(1000);
    }
    
    // create dataSource
    dataSource = new MysqlDataSource();
    dataSource.setUrl(DB_URL);
    dataSource.setUser(DB_USER);
    dataSource.setPassword(DB_PW);
    
    
}
 
开发者ID:kakao,项目名称:adt,代码行数:21,代码来源:MysqlBinlogProcessorDBCopyTest.java

示例7: setUp

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
public void setUp() {
    MysqlDataSource mySQLDataSource = new MysqlDataSource();
    mySQLDataSource.setUser(SupportDatabaseService.DBUSER);
    mySQLDataSource.setPassword(SupportDatabaseService.DBPWD);
    mySQLDataSource.setURL("jdbc:mysql://localhost/test");

    String envName = "java:comp/env/jdbc/MySQLDB";
    SupportInitialContextFactory.addContextEntry(envName, mySQLDataSource);

    ConfigurationDBRef config = new ConfigurationDBRef();
    Properties properties = new Properties();
    properties.put("java.naming.factory.initial", SupportInitialContextFactory.class.getName());
    config.setDataSourceConnection(envName, properties);

    databaseDSConnFactory = new DatabaseDSConnFactory((ConfigurationDBRef.DataSourceConnection) config.getConnectionFactoryDesc(), config.getConnectionSettings());
}
 
开发者ID:espertechinc,项目名称:esper,代码行数:17,代码来源:TestDatabaseDSConnFactory.java

示例8: getConnection

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
public static Connection getConnection() {
    if(url==null||user==null||password==null){
        initData();
    }
    try {
        if (conn == null || conn.isClosed()) {
            MysqlDataSource ds_mysql = new MysqlDataSource();
            ds_mysql.setUrl(url);// 设置连接字符串
            conn = ds_mysql.getConnection(user, password);
            return conn;
        }
    } catch (SQLException e) {
        System.out.println("连接JDBC出错!");
        e.printStackTrace();
        return null;
    }
    return conn;
}
 
开发者ID:leoliew,项目名称:meta-programming-jdbc,代码行数:19,代码来源:DBManager.java

示例9: testBug19169

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
/** 
 * Tests fix for BUG#19169 - ConnectionProperties (and thus some
 * subclasses) are not serializable, even though some J2EE containers
 * expect them to be.
 * 
 * @throws Exception if the test fails.
 */
public void testBug19169() throws Exception {
	MysqlDataSource toSerialize = new MysqlDataSource();
	toSerialize.setZeroDateTimeBehavior("convertToNull");
	
	boolean testBooleanFlag = !toSerialize.getAllowLoadLocalInfile();
	toSerialize.setAllowLoadLocalInfile(testBooleanFlag);
	
	int testIntFlag = toSerialize.getBlobSendChunkSize() + 1;
	toSerialize.setBlobSendChunkSize(String.valueOf(testIntFlag));
	
	ByteArrayOutputStream bOut = new ByteArrayOutputStream();
	ObjectOutputStream objOut = new ObjectOutputStream(bOut);
	objOut.writeObject(toSerialize);
	objOut.flush();
	
	ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(bOut.toByteArray()));
	
	MysqlDataSource thawedDs = (MysqlDataSource)objIn.readObject();
	
	assertEquals("convertToNull", thawedDs.getZeroDateTimeBehavior());
	assertEquals(testBooleanFlag, thawedDs.getAllowLoadLocalInfile());
	assertEquals(testIntFlag, thawedDs.getBlobSendChunkSize());
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:31,代码来源:DataSourceRegressionTest.java

示例10: testBug16791

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
/**
 * Tests fix for BUG#16791 - NullPointerException in MysqlDataSourceFactory
 * due to Reference containing RefAddrs with null content.
 * 
 * @throws Exception if the test fails
 */
public void testBug16791() throws Exception {
	MysqlDataSource myDs = new MysqlDataSource();
	myDs.setUrl(dbUrl);
	Reference asRef = myDs.getReference();
	System.out.println(asRef);
	
	removeFromRef(asRef, "port");
	removeFromRef(asRef, NonRegisteringDriver.USER_PROPERTY_KEY);
	removeFromRef(asRef, NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
	removeFromRef(asRef, "serverName");
	removeFromRef(asRef, "databaseName");
	
	//MysqlDataSource newDs = (MysqlDataSource)
	new MysqlDataSourceFactory().getObjectInstance(asRef, null, null, null);
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:22,代码来源:DataSourceRegressionTest.java

示例11: getDataSourceLocator

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
@Override
public SQLDataSourceLocator getDataSourceLocator() {
    return new SQLDataSourceLocator() {
        public DataSource lookup(SQLDataSetDef def) throws Exception {
            String url = connectionSettings.getProperty("url");
            String user = connectionSettings.getProperty("user");
            String password = connectionSettings.getProperty("password");

            MysqlDataSource ds = new MysqlDataSource();
            ds.setURL(url);
            if (!StringUtils.isBlank(user)) {
                ds.setUser(user);
            }
            if (!StringUtils.isBlank(password)) {
                ds.setPassword(password);
            }
            return ds;
        }
    };
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:21,代码来源:MySqlTestSettings.java

示例12: before

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
@Before
public void before() throws IOException {
    tempLocation = Files.createTempDirectory("jpagen").toFile();
    System.out.println(tempLocation.getAbsolutePath());


    com.mysql.jdbc.jdbc2.optional.MysqlDataSource ds
            = new MysqlDataSource();
    ds.setUrl("jdbc:mysql://localhost/devopsplus");
    ds.setUser("devopsplus");
    ds.setPassword("devopsplus");
    DBI dbi = new DBI(ds);
    Handle handle = dbi.open();

    config = Configuration.fromStream(getClass().getResourceAsStream("/test-2.json"));
    reflector = new ReflectorMySql(config, handle);
}
 
开发者ID:realrunner,项目名称:jpa-gen,代码行数:18,代码来源:GeneratorTestLocal.java

示例13: 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);
}
 
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:20,代码来源:DynRuleBaseTester.java

示例14: getDataSource

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入依赖的package包/类
private static DataSource getDataSource(Driver driver, String url, String user, String password) {
    DataSource dataSource;
    switch (driver) {
        case H2:
            JdbcDataSource h2DataSource = new JdbcDataSource();
            h2DataSource.setUrl(url);
            user = user != null ? user : "";
            password = password != null ? password : "";
            h2DataSource.setUser(user);
            h2DataSource.setPassword(password);
            return h2DataSource;
        case MYSQL:
            MysqlDataSource mysqlDataSource = new MysqlDataSource();
            mysqlDataSource.setURL(url);
            mysqlDataSource.setUser(user);
            mysqlDataSource.setPassword(password);
            return mysqlDataSource;
        default:
            throw new IllegalArgumentException("Unknown database driver");
    }
}
 
开发者ID:autoschool,项目名称:splinter,代码行数:22,代码来源:DatabaseProvider.java


注:本文中的com.mysql.jdbc.jdbc2.optional.MysqlDataSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。