當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。