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


Java Connection.setCatalog方法代码示例

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


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

示例1: testDefaultCatalog

import java.sql.Connection; //导入方法依赖的package包/类
@Test
public void testDefaultCatalog() throws Exception {
    DataSourceProxy d1 = this.createDefaultDataSource();
    d1.setMaxActive(1);
    d1.setJdbcInterceptors(ConnectionState.class.getName());
    d1.setDefaultCatalog("information_schema");
    d1.setMinIdle(1);
    Connection c1 = d1.getConnection();
    Assert.assertEquals("Catalog should be information_schema",c1.getCatalog(),"information_schema");
    c1.close();
    c1 = d1.getConnection();
    Assert.assertEquals("Catalog should be information_schema",c1.getCatalog(),"information_schema");
    c1.setCatalog("mysql");
    Assert.assertEquals("Catalog should be information_schema",c1.getCatalog(),"mysql");
    c1.close();
    c1 = d1.getConnection();
    Assert.assertEquals("Catalog should be information_schema",c1.getCatalog(),"information_schema");
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:19,代码来源:TestConnectionState.java

示例2: apply

import java.sql.Connection; //导入方法依赖的package包/类
protected void apply(Connection conn, ConnectionProperties connProps)
    throws SQLException {
  if (connProps.isAutoCommit() != null) {
    conn.setAutoCommit(connProps.isAutoCommit());
  }
  if (connProps.isReadOnly() != null) {
    conn.setReadOnly(connProps.isReadOnly());
  }
  if (connProps.getTransactionIsolation() != null) {
    conn.setTransactionIsolation(connProps.getTransactionIsolation());
  }
  if (connProps.getCatalog() != null) {
    conn.setCatalog(connProps.getCatalog());
  }
  if (connProps.getSchema() != null) {
    conn.setSchema(connProps.getSchema());
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:19,代码来源:JdbcMeta.java

示例3: testBug12417

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests fix for Bug#12417 - stored procedure catalog name is case-sensitive
 * on Windows (this is actually a server bug, but we have a workaround in
 * place for it now).
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug12417() throws Exception {
    if (serverSupportsStoredProcedures() && isServerRunningOnWindows()) {

        createProcedure("testBug12417", "()\nBEGIN\nSELECT 1;end\n");

        Connection ucCatalogConn = null;

        try {
            ucCatalogConn = getConnectionWithProps((Properties) null);
            ucCatalogConn.setCatalog(this.conn.getCatalog().toUpperCase());
            ucCatalogConn.prepareCall("{call testBug12417()}");
        } finally {
            if (ucCatalogConn != null) {
                ucCatalogConn.close();
            }
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:27,代码来源:CallableStatementRegressionTest.java

示例4: testSuccessfulAuthentication

import java.sql.Connection; //导入方法依赖的package包/类
@Test
public void testSuccessfulAuthentication() throws SQLException {
    assumeTrue(!"".equals(user));

    Connection connection = DriverManager.getConnection(url, user, password);

    try {
        connection.setCatalog(database);

        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        rs.next();
    } finally {
        connection.close();
    }

}
 
开发者ID:mongodb,项目名称:mongosql-auth-java,代码行数:18,代码来源:MongoSqlAuthenticationPluginFunctionalTest.java

示例5: setDefaults

import java.sql.Connection; //导入方法依赖的package包/类
public void setDefaults(Connection connection) throws SQLException {

        connection.setHoldability(this.holdability);

        if (this.transactionIsolation != Connection.TRANSACTION_NONE) {
            connection.setTransactionIsolation(this.transactionIsolation);
        }
        connection.setAutoCommit(this.isAutoCommit);
        connection.setReadOnly(this.isReadOnly);
        connection.setCatalog(this.catalog);
    }
 
开发者ID:s-store,项目名称:s-store,代码行数:12,代码来源:ConnectionDefaults.java

示例6: testBug61150

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#61150 - First call to SP
 * fails with "No Database Selected"
 * The workaround introduced in DatabaseMetaData.getCallStmtParameterTypes
 * to fix the bug in server where SHOW CREATE PROCEDURE was not respecting
 * lower-case table names is misbehaving when connection is not attached to
 * database and on non-casesensitive OS.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug61150() throws Exception {
    NonRegisteringDriver driver = new NonRegisteringDriver();
    Properties oldProps = driver.parseURL(BaseTestCase.dbUrl, null);

    String host = driver.host(oldProps);
    int port = driver.port(oldProps);
    StringBuilder newUrlToTestNoDB = new StringBuilder("jdbc:mysql://");
    if (host != null) {
        newUrlToTestNoDB.append(host);
    }
    newUrlToTestNoDB.append(":").append(port).append("/");

    Statement savedSt = this.stmt;

    Properties props = getHostFreePropertiesFromTestsuiteUrl();
    props.remove(NonRegisteringDriver.DBNAME_PROPERTY_KEY);
    Connection conn1 = DriverManager.getConnection(newUrlToTestNoDB.toString(), props);

    this.stmt = conn1.createStatement();
    createDatabase("TST1");
    createProcedure("TST1.PROC", "(x int, out y int)\nbegin\ndeclare z int;\nset z = x+1, y = z;\nend\n");

    CallableStatement cStmt = null;
    cStmt = conn1.prepareCall("{call `TST1`.`PROC`(?, ?)}");
    cStmt.setInt(1, 5);
    cStmt.registerOutParameter(2, Types.INTEGER);

    cStmt.execute();
    assertEquals(6, cStmt.getInt(2));
    cStmt.clearParameters();
    cStmt.close();

    conn1.setCatalog("TST1");
    cStmt = null;
    cStmt = conn1.prepareCall("{call TST1.PROC(?, ?)}");
    cStmt.setInt(1, 5);
    cStmt.registerOutParameter(2, Types.INTEGER);

    cStmt.execute();
    assertEquals(6, cStmt.getInt(2));
    cStmt.clearParameters();
    cStmt.close();

    conn1.setCatalog("mysql");
    cStmt = null;
    cStmt = conn1.prepareCall("{call `TST1`.`PROC`(?, ?)}");
    cStmt.setInt(1, 5);
    cStmt.registerOutParameter(2, Types.INTEGER);

    cStmt.execute();
    assertEquals(6, cStmt.getInt(2));
    cStmt.clearParameters();
    cStmt.close();

    this.stmt = savedSt;
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:68,代码来源:MetaDataRegressionTest.java

示例7: testCollation41

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests if the driver configures character sets correctly for 4.1.x
 * servers. Requires that the 'admin connection' is configured, as this test
 * needs to create/drop databases.
 * 
 * @throws Exception
 *             if an error occurs
 */
public void testCollation41() throws Exception {
    if (versionMeetsMinimum(4, 1) && isAdminConnectionConfigured()) {
        Map<String, String> charsetsAndCollations = getCharacterSetsAndCollations();
        charsetsAndCollations.remove("latin7"); // Maps to multiple Java
        // charsets
        charsetsAndCollations.remove("ucs2"); // can't be used as a
        // connection charset

        for (String charsetName : charsetsAndCollations.keySet()) {
            Connection charsetConn = null;
            Statement charsetStmt = null;

            try {
                //String collationName = charsetsAndCollations.get(charsetName);

                Properties props = new Properties();
                props.put("characterEncoding", charsetName);

                System.out.println("Testing character set " + charsetName);

                charsetConn = getAdminConnectionWithProps(props);

                charsetStmt = charsetConn.createStatement();

                charsetStmt.executeUpdate("DROP DATABASE IF EXISTS testCollation41");
                charsetStmt.executeUpdate("DROP TABLE IF EXISTS testCollation41");

                charsetStmt.executeUpdate("CREATE DATABASE testCollation41 DEFAULT CHARACTER SET " + charsetName);
                charsetConn.setCatalog("testCollation41");

                // We've switched catalogs, so we need to recreate the
                // statement to pick this up...
                charsetStmt = charsetConn.createStatement();

                StringBuilder createTableCommand = new StringBuilder("CREATE TABLE testCollation41(field1 VARCHAR(255), field2 INT)");

                charsetStmt.executeUpdate(createTableCommand.toString());

                charsetStmt.executeUpdate("INSERT INTO testCollation41 VALUES ('abc', 0)");

                int updateCount = charsetStmt.executeUpdate("UPDATE testCollation41 SET field2=1 WHERE field1='abc'");
                assertTrue(updateCount == 1);
            } finally {
                if (charsetStmt != null) {
                    charsetStmt.executeUpdate("DROP TABLE IF EXISTS testCollation41");
                    charsetStmt.executeUpdate("DROP DATABASE IF EXISTS testCollation41");
                    charsetStmt.close();
                }

                if (charsetConn != null) {
                    charsetConn.close();
                }
            }
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:65,代码来源:ConnectionRegressionTest.java

示例8: testBug15570

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#15570 - ReplicationConnection incorrectly copies state,
 * doesn't transfer connection context correctly when transitioning between
 * the same read-only states.
 * 
 * (note, this test will fail if the test user doesn't have permission to
 * "USE 'mysql'".
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug15570() throws Exception {
    Connection replConn = null;

    try {
        replConn = getMasterSlaveReplicationConnection();

        int masterConnectionId = Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString());

        replConn.setReadOnly(false);

        assertEquals(masterConnectionId, Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString()));

        String currentCatalog = replConn.getCatalog();

        replConn.setCatalog(currentCatalog);
        assertEquals(currentCatalog, replConn.getCatalog());

        replConn.setReadOnly(true);

        int slaveConnectionId = Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString());

        // The following test is okay for now, as the chance of MySQL wrapping the connection id counter during our testsuite is very small.
        // As per Bug#21286268 fix a Replication connection first initializes the Slaves sub-connection, then the Masters.
        assertTrue("Master id " + masterConnectionId + " is not newer than slave id " + slaveConnectionId, masterConnectionId > slaveConnectionId);

        assertEquals(currentCatalog, replConn.getCatalog());

        String newCatalog = "mysql";

        replConn.setCatalog(newCatalog);
        assertEquals(newCatalog, replConn.getCatalog());

        replConn.setReadOnly(true);
        assertEquals(newCatalog, replConn.getCatalog());

        replConn.setReadOnly(false);
        assertEquals(masterConnectionId, Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString()));
    } finally {
        if (replConn != null) {
            replConn.close();
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:55,代码来源:ConnectionRegressionTest.java

示例9: testBug66430

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests fix for Bug#66430 - setCatalog on connection leaves ServerPreparedStatement cache for old catalog.
 */
public void testBug66430() throws Exception {
    createDatabase("testBug66430DB1");
    createTable("testBug66430DB1.testBug66430", "(id INT)");
    this.stmt.executeUpdate("INSERT INTO testBug66430DB1.testBug66430 VALUES (1)");

    createDatabase("testBug66430DB2");
    createTable("testBug66430DB2.testBug66430", "(id INT)");
    this.stmt.executeUpdate("INSERT INTO testBug66430DB2.testBug66430 VALUES (2)");

    boolean useSPS = false;
    boolean cachePS = false;
    do {
        final String testCase = String.format("Case: [useSPS: %s, cachePS: %s ]", useSPS ? "Y" : "N", cachePS ? "Y" : "N");

        Properties props = new Properties();
        props.setProperty("cachePrepStmts", Boolean.toString(cachePS));
        props.setProperty("useServerPrepStmts", Boolean.toString(useSPS));

        Connection testConn = getConnectionWithProps(props);

        testConn.setCatalog("testBug66430DB1");
        PreparedStatement testPStmt = testConn.prepareStatement("SELECT * FROM testBug66430 WHERE id > ?");
        testPStmt.setInt(1, 0);
        this.rs = testPStmt.executeQuery();
        assertTrue(testCase, this.rs.next());
        assertEquals(testCase, 1, this.rs.getInt(1));
        assertFalse(testCase, this.rs.next());
        testPStmt.close();

        testConn.setCatalog("testBug66430DB2");
        testPStmt = testConn.prepareStatement("SELECT * FROM testBug66430 WHERE id > ?");
        testPStmt.setInt(1, 0);
        this.rs = testPStmt.executeQuery();
        assertTrue(testCase, this.rs.next());
        assertEquals(testCase, 2, this.rs.getInt(1));
        assertFalse(testCase, this.rs.next());
        testPStmt.close();

        // Do it again to make sure cached prepared statements behave correctly.
        testConn.setCatalog("testBug66430DB1");
        testPStmt = testConn.prepareStatement("SELECT * FROM testBug66430 WHERE id > ?");
        testPStmt.setInt(1, 0);
        this.rs = testPStmt.executeQuery();
        assertTrue(testCase, this.rs.next());
        assertEquals(testCase, 1, this.rs.getInt(1));
        assertFalse(testCase, this.rs.next());
        testPStmt.close();

        testConn.setCatalog("testBug66430DB2");
        testPStmt = testConn.prepareStatement("SELECT * FROM testBug66430 WHERE id > ?");
        testPStmt.setInt(1, 0);
        this.rs = testPStmt.executeQuery();
        assertTrue(testCase, this.rs.next());
        assertEquals(testCase, 2, this.rs.getInt(1));
        assertFalse(testCase, this.rs.next());
        testPStmt.close();

        testConn.close();
    } while ((useSPS = !useSPS) || (cachePS = !cachePS));
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:64,代码来源:StatementRegressionTest.java


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