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


Java MySQLConnection类代码示例

本文整理汇总了Java中com.mysql.jdbc.MySQLConnection的典型用法代码示例。如果您正苦于以下问题:Java MySQLConnection类的具体用法?Java MySQLConnection怎么用?Java MySQLConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testLocalInfileHooked

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
public void testLocalInfileHooked() throws Exception {
    createTable("localInfileHooked", "(field1 int, field2 varchar(255))");
    String streamData = "1\tabcd\n2\tefgh\n3\tijkl";
    InputStream stream = new ByteArrayInputStream(streamData.getBytes());
    try {
        ((com.mysql.jdbc.Statement) this.stmt).setLocalInfileInputStream(stream);
        this.stmt.execute("LOAD DATA LOCAL INFILE 'bogusFileName' INTO TABLE localInfileHooked CHARACTER SET "
                + CharsetMapping.getMysqlCharsetForJavaEncoding(((MySQLConnection) this.conn).getEncoding(), (com.mysql.jdbc.Connection) this.conn));
        assertEquals(-1, stream.read());
        this.rs = this.stmt.executeQuery("SELECT field2 FROM localInfileHooked ORDER BY field1 ASC");
        this.rs.next();
        assertEquals("abcd", this.rs.getString(1));
        this.rs.next();
        assertEquals("efgh", this.rs.getString(1));
        this.rs.next();
        assertEquals("ijkl", this.rs.getString(1));
    } finally {
        ((com.mysql.jdbc.Statement) this.stmt).setLocalInfileInputStream(null);
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:21,代码来源:StatementsTest.java

示例2: run

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
public void run() {
    System.out.println(this.num + ". Start cancelling at " + new Date().getTime());

    if (Proxy.isProxyClass(this.c.getClass())) {
        try {
            if (this.num == 7 || this.num == 10) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, Connection.class.getMethod("close", new Class[] {}), null);
            } else if (this.num == 8 || this.num == 11) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, MySQLConnection.class.getMethod("abortInternal", new Class[] {}), null);
            } else if (this.num == 9 || this.num == 12) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, com.mysql.jdbc.Connection.class.getMethod("abort", new Class[] { Executor.class }),
                        new Object[] { new ThreadPerTaskExecutor() });
            }

            ConnectionRegressionTest.this.testServerPrepStmtDeadlockCounter++;
            System.out.println(this.num + ". Done!");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:22,代码来源:ConnectionRegressionTest.java

示例3: testBug19354014

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
/**
 * Tests fix for BUG#19354014 - CHANGEUSER() CALL RESULTS IN "PACKETS OUT OF ORDER" ERROR
 * 
 * @throws Exception
 */
public void testBug19354014() throws Exception {
    if (versionMeetsMinimum(5, 5, 7)) {
        Connection con = null;
        createUser("'bug19354014user'@'%'", "identified WITH mysql_native_password");
        this.stmt.executeUpdate("grant all on *.* to 'bug19354014user'@'%'");
        this.stmt.executeUpdate(versionMeetsMinimum(5, 7, 6) ? "ALTER USER 'bug19354014user'@'%' IDENTIFIED BY 'pwd'"
                : "set password for 'bug19354014user'@'%' = PASSWORD('pwd')");
        this.stmt.executeUpdate("flush privileges");

        try {
            Properties props = new Properties();
            props.setProperty("useCompression", "true");

            con = getConnectionWithProps(props);
            ((MySQLConnection) con).changeUser("bug19354014user", "pwd");
        } finally {
            this.stmt.executeUpdate("flush privileges");

            if (con != null) {
                con.close();
            }
        }
    }
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:30,代码来源:ConnectionRegressionTest.java

示例4: testBug73663

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
/**
 * Tests fix for Bug#73663 (19479242), utf8mb4 does not work for connector/j >=5.1.13
 * 
 * This test is only run when character_set_server=utf8mb4 and collation-server set to one of utf8mb4 collations (it's better to test two configurations:
 * with default utf8mb4_general_ci and one of non-default, say utf8mb4_bin)
 * 
 * @throws Exception
 */
public void testBug73663() throws Exception {

    this.rs = this.stmt.executeQuery("show variables like 'collation_server'");
    this.rs.next();
    String collation = this.rs.getString(2);

    if (collation != null && collation.startsWith("utf8mb4") && "utf8mb4".equals(((MySQLConnection) this.conn).getServerVariable("character_set_server"))) {
        Properties p = new Properties();
        p.setProperty("characterEncoding", "UTF-8");
        p.setProperty("statementInterceptors", Bug73663StatementInterceptor.class.getName());

        getConnectionWithProps(p);
        // exception will be thrown from the statement interceptor if any "SET NAMES utf8" statement is issued instead of "SET NAMES utf8mb4"
    } else {
        System.out.println(
                "testBug73663 was skipped: This test is only run when character_set_server=utf8mb4 and collation-server set to one of utf8mb4 collations.");
    }
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:27,代码来源:CharsetRegressionTest.java

示例5: testBug12218

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
/**
 * Tests fix for BUG#12218, properties shared between master and slave with
 * replication connection.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug12218() throws Exception {
    if (runMultiHostTests()) {
        Connection replConn = null;

        try {
            replConn = getMasterSlaveReplicationConnection();
            assertTrue(!((MySQLConnection) ((ReplicationConnection) replConn).getMasterConnection())
                    .hasSameProperties(((ReplicationConnection) replConn).getSlavesConnection()));
        } finally {
            if (replConn != null) {
                replConn.close();
            }
        }
    }
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:23,代码来源:ConnectionRegressionTest.java

示例6: testBug78961

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
/**
 * Tests fix for Bug#78961 - Can't call MySQL procedure with InOut parameters in Fabric environment.
 * 
 * Although this is a Fabric related bug we are able reproduce it using a couple of multi-host connections.
 */
public void testBug78961() throws Exception {
    createProcedure("testBug78961", "(IN c1 FLOAT, IN c2 FLOAT, OUT h FLOAT, INOUT t FLOAT) BEGIN SET h = SQRT(c1 * c1 + c2 * c2); SET t = t + h; END;");

    Connection highLevelConn = getLoadBalancedConnection(null);
    assertTrue(highLevelConn.getClass().getName().startsWith("com.sun.proxy") || highLevelConn.getClass().getName().startsWith("$Proxy"));

    Connection lowLevelConn = getMasterSlaveReplicationConnection(null);
    // This simulates the behavior from Fabric connections that are causing the problem.
    ((ReplicationConnection) lowLevelConn).setProxy((MySQLConnection) highLevelConn);

    CallableStatement cstmt = lowLevelConn.prepareCall("{CALL testBug78961 (?, ?, ?, ?)}");
    cstmt.setFloat(1, 3.0f);
    cstmt.setFloat(2, 4.0f);
    cstmt.setFloat(4, 5.0f);
    cstmt.registerOutParameter(3, Types.FLOAT);
    cstmt.registerOutParameter(4, Types.FLOAT);
    cstmt.execute();

    assertEquals(5.0f, cstmt.getFloat(3));
    assertEquals(10.0f, cstmt.getFloat(4));
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:27,代码来源:StatementRegressionTest.java

示例7: testBug37570

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
public void testBug37570() throws Exception {
    Properties props = new Properties();
    props.setProperty("characterEncoding", "utf-8");
    props.setProperty("passwordCharacterEncoding", "utf-8");

    // TODO enable for usual connection?
    Connection adminConn = getAdminConnectionWithProps(props);

    if (adminConn != null) {

        String unicodePassword = "\u0430\u0431\u0432"; // Cyrillic string
        String user = "bug37570";
        Statement adminStmt = adminConn.createStatement();

        adminStmt.executeUpdate("create user '" + user + "'@'127.0.0.1' identified by 'foo'");
        adminStmt.executeUpdate("grant usage on *.* to '" + user + "'@'127.0.0.1'");
        adminStmt.executeUpdate("update mysql.user set password=PASSWORD('" + unicodePassword + "') where user = '" + user + "'");
        adminStmt.executeUpdate("flush privileges");

        try {
            ((MySQLConnection) adminConn).changeUser(user, unicodePassword);
        } catch (SQLException sqle) {
            assertTrue("Connection with non-latin1 password failed", false);
        }

    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:28,代码来源:ConnectionRegressionTest.java

示例8: testBug44587

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
/**
 * Tests fix for BUG#44587, provide last packet sent/received timing in all
 * connection failure errors.
 */
public void testBug44587() throws Exception {
    Exception e = null;
    String msg = SQLError.createLinkFailureMessageBasedOnHeuristics((MySQLConnection) this.conn, System.currentTimeMillis() - 1000,
            System.currentTimeMillis() - 2000, e);
    assertTrue(containsMessage(msg, "CommunicationsException.ServerPacketTimingInfo"));
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:11,代码来源:ConnectionRegressionTest.java

示例9: testBug45419

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
/**
 * Tests fix for BUG#45419, ensure that time is not converted to seconds
 * before being reported as milliseconds.
 */
public void testBug45419() throws Exception {
    Exception e = null;
    String msg = SQLError.createLinkFailureMessageBasedOnHeuristics((MySQLConnection) this.conn, System.currentTimeMillis() - 1000,
            System.currentTimeMillis() - 2000, e);
    Matcher m = Pattern.compile("([\\d\\,\\.]+)", Pattern.MULTILINE).matcher(msg);
    assertTrue(m.find());
    assertTrue(Long.parseLong(m.group(0).replaceAll("[,.]", "")) >= 2000);
    assertTrue(Long.parseLong(m.group(1).replaceAll("[,.]", "")) >= 1000);
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:14,代码来源:ConnectionRegressionTest.java

示例10: assertCurrentUser

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
private void assertCurrentUser(String url, Properties props, String expectedUser, boolean sslRequired) throws SQLException {
    Connection connection = url == null ? getConnectionWithProps(props) : getConnectionWithProps(url, props);
    if (sslRequired) {
        assertTrue("SSL connection isn't actually established!", ((MySQLConnection) connection).getIO().isSSLEstablished());
    }
    Statement st = connection.createStatement();
    ResultSet rset = st.executeQuery("select USER(),CURRENT_USER()");
    rset.next();
    assertEquals(expectedUser, rset.getString(1).split("@")[0]);
    assertEquals(expectedUser, rset.getString(2).split("@")[0]);
    connection.close();
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:13,代码来源:ConnectionRegressionTest.java

示例11: encryptPassword

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
private static byte[] encryptPassword(String password, String seed, Connection connection, String key) throws SQLException {
    byte[] input = null;
    try {
        input = password != null ? StringUtils.getBytesNullTerminated(password, connection.getPasswordCharacterEncoding()) : new byte[] { 0 };
    } catch (UnsupportedEncodingException e) {
        throw SQLError.createSQLException(Messages.getString("Sha256PasswordPlugin.3", new Object[] { connection.getPasswordCharacterEncoding() }),
                SQLError.SQL_STATE_GENERAL_ERROR, null);
    }
    byte[] mysqlScrambleBuff = new byte[input.length];
    Security.xorString(input, mysqlScrambleBuff, seed.getBytes(), input.length);
    return ExportControlled.encryptWithRSAPublicKey(mysqlScrambleBuff,
            ExportControlled.decodeRSAPublicKey(key, ((MySQLConnection) connection).getExceptionInterceptor()),
            ((MySQLConnection) connection).getExceptionInterceptor());
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:15,代码来源:Sha256PasswordPlugin.java

示例12: testBug72712

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
/**
 * Test for Bug#72712 - SET NAMES issued unnecessarily.
 * 
 * Using a statement interceptor, ensure that SET NAMES is not
 * called if the encoding requested by the client application
 * matches that of character_set_server.
 * 
 * Also test that character_set_results is not set unnecessarily.
 */
public void testBug72712() throws Exception {
    // this test is only run when character_set_server=latin1
    if (!((MySQLConnection) this.conn).getServerVariable("character_set_server").equals("latin1")) {
        return;
    }

    Properties p = new Properties();
    p.setProperty("characterEncoding", "cp1252");
    p.setProperty("characterSetResults", "cp1252");
    p.setProperty("statementInterceptors", Bug72712StatementInterceptor.class.getName());

    getConnectionWithProps(p);
    // exception will be thrown from the statement interceptor if any SET statements are issued
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:24,代码来源:ConnectionRegressionTest.java

示例13: testBug18869381WithProperties

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
private void testBug18869381WithProperties(Properties props) throws Exception {
    Connection testConn = null;
    Statement testSt = null;
    ResultSet testRs = null;

    try {
        testConn = getConnectionWithProps(sha256Url, props);

        ((MySQLConnection) testConn).changeUser("bug18869381user1", "LongLongLongLongLongLongLongLongLongLongLongLongPwd1");
        testSt = testConn.createStatement();
        testRs = testSt.executeQuery("select USER(),CURRENT_USER()");
        testRs.next();
        assertEquals("bug18869381user1", testRs.getString(1).split("@")[0]);
        assertEquals("bug18869381user1", testRs.getString(2).split("@")[0]);
        testSt.close();

        ((MySQLConnection) testConn).changeUser("bug18869381user2", "pwd2");
        testSt = testConn.createStatement();
        testRs = testSt.executeQuery("select USER(),CURRENT_USER()");
        testRs.next();
        assertEquals("bug18869381user2", testRs.getString(1).split("@")[0]);
        assertEquals("bug18869381user2", testRs.getString(2).split("@")[0]);
        testSt.close();

        ((MySQLConnection) testConn).changeUser("bug18869381user3", "pwd3");
        testSt = testConn.createStatement();
        testRs = testSt.executeQuery("select USER(),CURRENT_USER()");
        testRs.next();
        assertEquals("bug18869381user3", testRs.getString(1).split("@")[0]);
        assertEquals("bug18869381user3", testRs.getString(2).split("@")[0]);

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

示例14: getActiveMySQLConnection

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
public MySQLConnection getActiveMySQLConnection() {
    try {
        return getActiveMySQLConnectionChecked();
    } catch (SQLException ex) {
        throw new IllegalStateException("Unable to determine active connection", ex);
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:8,代码来源:FabricMySQLConnectionProxy.java

示例15: interceptException

import com.mysql.jdbc.MySQLConnection; //导入依赖的package包/类
public SQLException interceptException(SQLException sqlEx, Connection conn) {
    MySQLConnection mysqlConn = (MySQLConnection) conn;

    // don't intercept exceptions during initialization, before the proxy has a chance to setProxy() on the physical connection
    if (ConnectionImpl.class.isAssignableFrom(mysqlConn.getMultiHostSafeProxy().getClass())) {
        return null;
    }

    FabricMySQLConnectionProxy fabricProxy = (FabricMySQLConnectionProxy) mysqlConn.getMultiHostSafeProxy();
    try {
        return fabricProxy.interceptException(sqlEx, conn, this.fabricHaGroup, this.hostname, this.port);
    } catch (FabricCommunicationException ex) {
        return SQLError.createSQLException("Failed to report error to Fabric.", SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE, ex, null);
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:16,代码来源:ErrorReportingExceptionInterceptor.java


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