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


Java JdbcDataSource.setPassword方法代码示例

本文整理汇总了Java中org.h2.jdbcx.JdbcDataSource.setPassword方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcDataSource.setPassword方法的具体用法?Java JdbcDataSource.setPassword怎么用?Java JdbcDataSource.setPassword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.h2.jdbcx.JdbcDataSource的用法示例。


在下文中一共展示了JdbcDataSource.setPassword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMixedXaNormal

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
private void testMixedXaNormal() throws Exception {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test");
    ds.setUser("sa");
    ds.setPassword("");
    XAConnection xa = ds.getXAConnection();
    Connection c = xa.getConnection();
    assertTrue(c.getAutoCommit());
    MyXid xid = new MyXid();
    XAResource res = xa.getXAResource();

    res.start(xid, XAResource.TMNOFLAGS);
    assertTrue(!c.getAutoCommit());
    res.end(xid, XAResource.TMSUCCESS);
    res.commit(xid, true);
    assertTrue(c.getAutoCommit());

    res.start(xid, XAResource.TMNOFLAGS);
    assertTrue(!c.getAutoCommit());
    res.end(xid, XAResource.TMFAIL);
    res.rollback(xid);
    assertTrue(c.getAutoCommit());

    c.close();
    xa.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:27,代码来源:TestXA.java

示例2: testDataSource

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
private void testDataSource() throws SQLException {
    deleteDb("dataSource");
    JdbcDataSource ds = new JdbcDataSource();
    PrintWriter p = new PrintWriter(new StringWriter());
    ds.setLogWriter(p);
    assertTrue(p == ds.getLogWriter());
    ds.setURL(getURL("dataSource", true));
    ds.setUser(getUser());
    ds.setPassword(getPassword());
    Connection conn;
    conn = ds.getConnection();
    Statement stat;
    stat = conn.createStatement();
    stat.execute("SELECT * FROM DUAL");
    conn.close();
    conn = ds.getConnection(getUser(), getPassword());
    stat = conn.createStatement();
    stat.execute("SELECT * FROM DUAL");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:20,代码来源:TestDataSource.java

示例3: DLNAMediaDatabase

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
public DLNAMediaDatabase(String name) {
	dbName = name;
	File profileFolder = new File(configuration.getProfileFolder());
	dbDir = new File(profileFolder.isDirectory() ? profileFolder : null, "database").getAbsolutePath();
	boolean logDB = configuration.getDatabaseLogging();
	url = Constants.START_URL + dbDir + File.separator + dbName + (logDB ? ";TRACE_LEVEL_FILE=4" : "");
	LOGGER.debug("Using database URL: {}", url);
	LOGGER.info("Using database located at: \"{}\"", dbDir);
	if (logDB) {
		LOGGER.info("Database logging is enabled");
	} else if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("Database logging is disabled");
	}

	try {
		Class.forName("org.h2.Driver");
	} catch (ClassNotFoundException e) {
		LOGGER.error(null, e);
	}

	JdbcDataSource ds = new JdbcDataSource();
	ds.setURL(url);
	ds.setUser("sa");
	ds.setPassword("");
	cp = JdbcConnectionPool.create(ds);
}
 
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:27,代码来源:DLNAMediaDatabase.java

示例4: createDatabase

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
/**
 * To create certificate management database.
 *
 * @return Datasource.
 * @throws SQLException SQL Exception.
 */
private DataSource createDatabase() throws SQLException {
    URL resourceURL = ClassLoader.getSystemResource("sql-scripts" + File.separator + "h2.sql");
    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:mem:cert;DB_CLOSE_DELAY=-1");
    dataSource.setUser("sa");
    dataSource.setPassword("sa");
    final String LOAD_DATA_QUERY = "RUNSCRIPT FROM '" + resourceURL.getPath() + "'";
    Connection conn = null;
    Statement statement = null;
    try {
        conn = dataSource.getConnection();
        statement = conn.createStatement();
        statement.execute(LOAD_DATA_QUERY);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {}
        }
        if (statement != null) {
            statement.close();
        }
    }
    return dataSource;
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:32,代码来源:CertificateAuthenticatorTest.java

示例5: getH2Connection

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
private static Connection getH2Connection() {
    try {
        String url = "jdbc:h2:./h2db";
        String name = "tully";
        String pass = "tully";

        JdbcDataSource ds = new JdbcDataSource();
        ds.setURL(url);
        ds.setUser(name);
        ds.setPassword(pass);

        Connection connection = DriverManager.getConnection(url, name, pass);
        return connection;
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:vitaly-chibrikov,项目名称:homework_tester,代码行数:19,代码来源:DBServiceImpl.java

示例6: getH2Connection

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
public static Connection getH2Connection() {
    try {
        String url = "jdbc:h2:./h2db";
        String name = "tully";
        String pass = "tully";

        JdbcDataSource ds = new JdbcDataSource();
        ds.setURL(url);
        ds.setUser(name);
        ds.setPassword(pass);

        Connection connection = DriverManager.getConnection(url, name, pass);
        return connection;
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:vitaly-chibrikov,项目名称:stepic_java_webserver,代码行数:19,代码来源:DBService.java

示例7: beforeClass

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
    namingMixIn = new NamingMixIn();
    namingMixIn.initialize();

    connection = DriverManager.getConnection("jdbc:h2:mem:events-jpa-quickstart", "sa", "sa");

    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:events-jpa-quickstart");
    ds.setUser("sa");
    ds.setPassword("sa");

    InitialContext initialContext = new InitialContext();
    bind(initialContext, System.getProperty("jpa.persistence.datasource.name"), ds);

}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:17,代码来源:CamelJpaBindingTest.java

示例8: startUp

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
@BeforeClass
public static void startUp() throws Exception {
    dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:mem:test");
    dataSource.setUser("sa");
    dataSource.setPassword("sa");
    connection = dataSource.getConnection();

    String createStatement = "CREATE TABLE greetings ("
        + "id INT PRIMARY KEY AUTO_INCREMENT, "
        + "receiver VARCHAR(255), "
        + "sender VARCHAR(255) "
        + ");";

    connection.createStatement().executeUpdate("DROP TABLE IF EXISTS greetings");
    connection.createStatement().executeUpdate(createStatement);

    namingMixIn = new NamingMixIn();
    namingMixIn.initialize();
    bindDataSource(namingMixIn.getInitialContext(), "java:jboss/myDS", dataSource);
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:22,代码来源:CamelSqlBindingTest.java

示例9: main

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
public static void main(String[] args) throws SQLException {

        JdbcDataSource dataSource = new JdbcDataSource();
//        dataSource.setUrl("jdbc:h2:~/datasource-test.db");
        dataSource.setUrl("jdbc:h2:mem:test");
        dataSource.setUser("sa");
        dataSource.setPassword("");

        Connection connection = dataSource.getConnection();

        Statement statement = connection.createStatement();

        statement.execute("drop table t1 if exists ");
        statement.execute("create table t1(id int primary key, name char)");
        statement.execute("insert into t1(id,name) values (1,'jdbc')");
        statement.execute("insert into t1(id,name) values (2,'java')");
        statement.execute("insert into t1(id,name) values (3,'trainig')");
        statement.execute("insert into t1(id,name) values (4,'persistence')");

        ResultSet resultSet = statement.executeQuery("select * from t1");

        printResults(resultSet);
    }
 
开发者ID:ieugen,项目名称:trainings,代码行数:24,代码来源:DataSourceMain.java

示例10: getDataSource

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的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

示例11: getJdbcDataSource

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
public static JdbcDataSource getJdbcDataSource(String initScriptLocation) {
    Validate.notEmpty(initScriptLocation, "initScriptLocation is empty");

    String mavenRelativePath = "src/main/resources/" + initScriptLocation;
    String mavenRootRelativePath = "camel-cookbook-transactions/" + mavenRelativePath;

    // check that we can load the init script
    FileLocator locator = new FileLocator().with(initScriptLocation).with(mavenRelativePath).with(mavenRootRelativePath);
    File file = locator.find();
    Validate.notNull(file, locator.getErrorMessage());
    FileSystemResource script = new FileSystemResource(file);

    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1");
    dataSource.setUser("sa");
    dataSource.setPassword("");

    DataSourceInitializer.initializeDataSource(dataSource, script);

    return dataSource;
}
 
开发者ID:CamelCookbook,项目名称:camel-cookbook-examples,代码行数:22,代码来源:EmbeddedDataSourceFactory.java

示例12: dataSource

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
@Bean
public DataSource dataSource()
{
    try
    {
        // When running inside a container, use its resource directory.
        return (DataSource) new JndiTemplate().lookup("jdbc/spring_ds");
    }
    catch (NamingException e)
    {
        // When running on the command line, just create a temporary file DB (only needed for debug).
        System.out.println("JNDI datasource does not exist - falling back on hard coded DS");
        JdbcDataSource ds = new JdbcDataSource();
        ds.setURL("jdbc:h2:./target/TEST.db");
        ds.setUser("sa");
        ds.setPassword("sa");
        return ds;
    }
}
 
开发者ID:enioka,项目名称:jqm,代码行数:20,代码来源:DbConfig.java

示例13: createH2DataSource

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
private XADataSource createH2DataSource() {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test");
    ds.setUser("sa");
    ds.setPassword("");
    return ds;
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:8,代码来源:H2Test.java

示例14: testXAAutoCommit

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
private void testXAAutoCommit() throws Exception {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test");
    ds.setUser("sa");
    ds.setPassword("");
    XAConnection xa = ds.getXAConnection();
    MyXid xid = new MyXid();
    xa.getXAResource().start(xid,
            XAResource.TMNOFLAGS);
    Connection c = xa.getConnection();
    assertTrue(!c.getAutoCommit());
    c.close();
    xa.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:15,代码来源:TestXA.java

示例15: createXADatasource

import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
private XADataSource createXADatasource(boolean useOneDatabase, String url) {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setPassword(getPassword(""));
    ds.setUser("sa");
    if (useOneDatabase) {
        ds.setURL(getURL("xa", true));
    } else {
        ds.setURL(url);
    }
    return ds;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:12,代码来源:TestXA.java


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