當前位置: 首頁>>代碼示例>>Java>>正文


Java MysqlDataSource.setUrl方法代碼示例

本文整理匯總了Java中com.mysql.jdbc.jdbc2.optional.MysqlDataSource.setUrl方法的典型用法代碼示例。如果您正苦於以下問題:Java MysqlDataSource.setUrl方法的具體用法?Java MysqlDataSource.setUrl怎麽用?Java MysqlDataSource.setUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mysql.jdbc.jdbc2.optional.MysqlDataSource的用法示例。


在下文中一共展示了MysqlDataSource.setUrl方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: setUpService

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
@Before
public void setUpService() {
    MockitoAnnotations.initMocks(this);
    CaArrayUsernameHolder.setUser(STANDARD_USER);
    final ProjectManagementServiceBean pmsBean = new ProjectManagementServiceBean();

    pmsBean.setProjectDao(this.daoFactoryStub.getProjectDao());
    pmsBean.setFileDao(fileDao);
    pmsBean.setSampleDao(this.daoFactoryStub.getSampleDao());
    pmsBean.setSearchDao(this.daoFactoryStub.getSearchDao());
    pmsBean.setVocabularyDao(this.daoFactoryStub.getVocabularyDao());

    locatorStub = ServiceLocatorStub.registerEmptyLocator();
    locatorStub.addLookup(FileAccessService.JNDI_NAME, this.fileAccessServiceStub);
    locatorStub.addLookup(GenericDataService.JNDI_NAME, this.genericDataService);
    final MysqlDataSource ds = new MysqlDataSource();
    final Configuration config = hibernateHelper.getConfiguration();
    ds.setUrl(config.getProperty("hibernate.connection.url"));
    ds.setUser(config.getProperty("hibernate.connection.username"));
    ds.setPassword(config.getProperty("hibernate.connection.password"));
    locatorStub.addLookup("java:jdbc/CaArrayDataSource", ds);
    this.projectManagementService = pmsBean;
    locatorStub.addLookup(ProjectManagementService.JNDI_NAME, this.projectManagementService);
    hibernateHelper.setFiltersEnabled(false);
    this.transaction = hibernateHelper.beginTransaction();
}
 
開發者ID:NCIP,項目名稱:caarray,代碼行數:27,代碼來源:ProjectManagementServiceTest.java

示例6: createPermissionsManagementService

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
private PermissionsManagementService createPermissionsManagementService(GenericDataService genericDataServiceStub) {
    final CaArrayDaoFactory daoFactory = CaArrayDaoFactory.INSTANCE;
    final PermissionsManagementServiceBean bean = new PermissionsManagementServiceBean();
    bean.setHibernateHelper(this.hibernateHelper);
    bean.setCollaboratorGroupDao(daoFactory.getCollaboratorGroupDao());
    bean.setSearchDao(daoFactory.getSearchDao());

    final ServiceLocatorStub locatorStub = ServiceLocatorStub.registerEmptyLocator();
    locatorStub.addLookup(GenericDataService.JNDI_NAME, genericDataServiceStub);
    final MysqlDataSource ds = new MysqlDataSource();
    final Configuration config = this.hibernateHelper.getConfiguration();
    ds.setUrl(config.getProperty("hibernate.connection.url"));
    ds.setUser(config.getProperty("hibernate.connection.username"));
    ds.setPassword(config.getProperty("hibernate.connection.password"));
    locatorStub.addLookup("java:jdbc/CaArrayDataSource", ds);
    bean.setGenericDataService(genericDataServiceStub);

    return bean;
}
 
開發者ID:NCIP,項目名稱:caarray,代碼行數:20,代碼來源:PermissionsManagementServiceIntegrationTest.java

示例7: testBug42267

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
public void testBug42267() throws Exception {
    MysqlDataSource ds = new MysqlDataSource();
    ds.setUrl(dbUrl);
    Connection c = ds.getConnection();
    String query = "select 1,2,345";
    PreparedStatement ps = c.prepareStatement(query);
    String psString = ps.toString();
    assertTrue("String representation of wrapped ps should contain query string", psString.endsWith(": " + query));
    ps.close();
    ps.toString();
    c.close();
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:13,代碼來源:DataSourceRegressionTest.java

示例8: testBug72632

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
/**
 * Tests fix for Bug#72632 - NullPointerException for invalid JDBC URL.
 */
public void testBug72632() throws Exception {
    final MysqlDataSource dataSource = new MysqlDataSource();
    dataSource.setUrl("bad-connection-string");
    assertThrows(SQLException.class, "Failed to get a connection using the URL 'bad-connection-string'.", new Callable<Void>() {
        public Void call() throws Exception {
            dataSource.getConnection();
            return null;
        }
    });
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:14,代碼來源:DataSourceRegressionTest.java

示例9: main

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
public static void main(String[] args) {

		// Define connection to the server
		MysqlDataSource dataSource = new MysqlDataSource(); // If you are not using MySQL, use different DataSource
		dataSource.setUrl("jdbc:mysql://relational.fit.cvut.cz"); // Public read-only database for testing
		dataSource.setUser("guest");
		dataSource.setPassword("relational");

		// Which database to analyse
		String databaseName = "mutagenesis"; // Another database to try: financial
		String schemaName = ""; // Always empty for MySQL databases

		// Connect to the database
		try (Connection connection = dataSource.getConnection()){

			// Estimate the PK and FK
			List<Table> tables = Schema.getPrimaryKeys(connection, databaseName, schemaName);
			tables = Optimization.optimize(tables);
			List<Relationship> relationships = Schema.getRelationships(connection, databaseName, schemaName, tables, false);
			OptimizationRelationship.optimize(relationships, tables);
			List<CompoundRelationship> compoundRelationships = CompoundRelationship.buildFrom(relationships);

			// Print the estimated PK and FK with the defined quote characters
			System.out.println("Estimated primary keys follow: ");
			System.out.println(SQL.getPkQuery(tables, '`', '`'));
			System.out.println("Estimated foreign key constraints follow: ");
			System.out.println(SQL.getFkQuery(compoundRelationships, '`', '`'));
		} catch (SQLException | InterruptedException e) {
			e.printStackTrace();
		}
	}
 
開發者ID:janmotl,項目名稱:linkifier,代碼行數:32,代碼來源:Demo.java

示例10: run

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
private void run() throws IOException, SQLException {
    MysqlDataSource dataSource = new MysqlDataSource();
    dataSource.setUrl("jdbc:mysql://" + host + ":" + port + "/" + database);
    dataSource.setUser(username);
    dataSource.setPassword(password);

    try (FileInputStream inputStream = new FileInputStream(file)) {
        ScriptRunner runner = new ScriptRunner(dataSource.getConnection());
        runner.setAutoCommit(true);
        runner.setStopOnError(true);
        runner.runScript(new InputStreamReader(inputStream));
        runner.closeConnection();
    }
}
 
開發者ID:syhily,項目名稱:sql-executor,代碼行數:15,代碼來源:Command.java

示例11: getConnection

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
public static Connection getConnection(String url, String username, String password) throws SQLException{
    MysqlDataSource ds = new MysqlDataSource();
    ds.setUrl(url);
    ds.setUser(username);
    ds.setPassword(password);
    return ds.getConnection();
}
 
開發者ID:kakao,項目名稱:adt,代碼行數:8,代碼來源:HandlerTest.java

示例12: initializeDataSource

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
/**
 * When the application is run in Tomcat this method MUST NOT be used, because then the data source is
 * automatically retrieved from the context. If we run the applications as stand alone, then we have to
 * initialize the data source ourselves. In the latter case this method should be used.
 * @param jdbcURL the database url
 * @param dbLoginName the login for the database
 * @param dbUserPassword the pasword for the database
 * @param db the database XCURE_CHAT_DB or XCURE_HOSTIP_DB
 * @throws Exception if the database is not recognized.
 */
public static void initializeDataSource( final String jdbcURL, final String dbLoginName,
										 final String dbUserPassword, final byte db ) throws Exception {
	MysqlDataSource dataSource = new MysqlDataSource();
	dataSource.setUrl ( jdbcURL );
	dataSource.setUser( dbLoginName );
	dataSource.setPassword( dbUserPassword );
	switch( db ) {
		case XCURE_CHAT_DB: xcureChatDataSource = dataSource; break;
		case XCURE_HOSTIP_DB: xcureHostipDataSource = dataSource; break;
		default:
			throw new Exception("Unknown DB = " + db + " should be either XCURE_CHAT_DB("+XCURE_CHAT_DB+") or XCURE_HOSTIP_DB("+XCURE_HOSTIP_DB+")");
	}
}
 
開發者ID:ivan-zapreev,項目名稱:x-cure-chat,代碼行數:24,代碼來源:ConnectionWrapper.java

示例13: testBug42267

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
public void testBug42267() throws Exception {
	MysqlDataSource ds = new MysqlDataSource();
	ds.setUrl(dbUrl);
	Connection conn = ds.getConnection();
	String query = "select 1,2,345";
	PreparedStatement ps = conn.prepareStatement(query);
	String psString = ps.toString();
	assertTrue("String representation of wrapped ps should contain query string", psString.endsWith(": " + query));
	ps.close();
	ps.toString();
	conn.close();
}
 
開發者ID:hinsenchan,項目名稱:fil_project_mgmt_app_v2,代碼行數:13,代碼來源:DataSourceRegressionTest.java

示例14: getAdhocDataSource

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
private static DataSource getAdhocDataSource() {
    MysqlDataSource ds = new MysqlDataSource();
    Configuration config = hibernateHelper.getConfiguration();
    ds.setUrl(config.getProperty(Environment.URL));
    ds.setUser(config.getProperty(Environment.USER));
    ds.setPassword(config.getProperty(Environment.PASS));
    return ds;
}
 
開發者ID:NCIP,項目名稱:caarray,代碼行數:9,代碼來源:ConfigurationHelper.java

示例15: createProjectManagementService

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
private ProjectManagementService createProjectManagementService(final FileAccessServiceStub fileAccessServiceStub) {
    final CaArrayDaoFactory daoFactory = CaArrayDaoFactory.INSTANCE;

    final GenericDataServiceBean genericDataServiceBean = new GenericDataServiceBean();
    genericDataServiceBean.setProjectDao(daoFactory.getProjectDao());
    genericDataServiceBean.setSearchDao(daoFactory.getSearchDao());
    this.genericDataService = genericDataServiceBean;

    final ProjectManagementServiceBean bean = new ProjectManagementServiceBean();
    bean.setProjectDao(daoFactory.getProjectDao());
    bean.setFileDao(daoFactory.getFileDao());
    bean.setSampleDao(daoFactory.getSampleDao());
    bean.setSearchDao(daoFactory.getSearchDao());
    bean.setVocabularyDao(daoFactory.getVocabularyDao());

    final ServiceLocatorStub locatorStub = ServiceLocatorStub.registerEmptyLocator();
    locatorStub.addLookup(FileAccessService.JNDI_NAME, fileAccessServiceStub);
    locatorStub.addLookup(GenericDataService.JNDI_NAME, this.genericDataService);
    final MysqlDataSource ds = new MysqlDataSource();
    final Configuration config = this.hibernateHelper.getConfiguration();
    ds.setUrl(config.getProperty("hibernate.connection.url"));
    ds.setUser(config.getProperty("hibernate.connection.username"));
    ds.setPassword(config.getProperty("hibernate.connection.password"));
    locatorStub.addLookup("java:jdbc/CaArrayDataSource", ds);

    return bean;
}
 
開發者ID:NCIP,項目名稱:caarray,代碼行數:28,代碼來源:ProjectManagementServiceIntegrationTest.java


注:本文中的com.mysql.jdbc.jdbc2.optional.MysqlDataSource.setUrl方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。