当前位置: 首页>>代码示例>>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;未经允许,请勿转载。