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


Java Util类代码示例

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


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

示例1: testIsJdbcInterface

import com.mysql.jdbc.Util; //导入依赖的package包/类
/**
 * Tests Util.isJdbcInterface()
 * 
 * @throws Exception
 */
public void testIsJdbcInterface() throws Exception {
    // Classes directly or indirectly implementing JDBC interfaces.
    assertTrue(Util.isJdbcInterface(PreparedStatement.class));
    assertTrue(Util.isJdbcInterface(StatementImpl.class));
    assertTrue(Util.isJdbcInterface(Statement.class));
    assertTrue(Util.isJdbcInterface(ResultSetImpl.class));
    Statement s = (Statement) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { Statement.class }, new InvocationHandler() {
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return null;
        }
    });
    assertTrue(Util.isJdbcInterface(s.getClass()));

    // Classes not implementing JDBC interfaces.
    assertFalse(Util.isJdbcInterface(Util.class));
    assertFalse(Util.isJdbcInterface(UtilsTest.class));

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

示例2: testIsJdbcPackage

import com.mysql.jdbc.Util; //导入依赖的package包/类
/**
 * Tests Util.isJdbcPackage()
 * 
 * @throws Exception
 */
public void testIsJdbcPackage() throws Exception {
    // JDBC packages.
    assertTrue(Util.isJdbcPackage("java.sql"));
    assertTrue(Util.isJdbcPackage("javax.sql"));
    assertTrue(Util.isJdbcPackage("javax.sql.rowset"));
    assertTrue(Util.isJdbcPackage("com.mysql.jdbc"));
    assertTrue(Util.isJdbcPackage("com.mysql.jdbc"));
    assertTrue(Util.isJdbcPackage("com.mysql.jdbc.jdbc2.optional"));

    // Non-JDBC packages.
    assertFalse(Util.isJdbcPackage("java"));
    assertFalse(Util.isJdbcPackage("java.lang"));
    assertFalse(Util.isJdbcPackage("com"));
    assertFalse(Util.isJdbcPackage("com.mysql"));
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:21,代码来源:UtilsTest.java

示例3: testReservedWords

import com.mysql.jdbc.Util; //导入依赖的package包/类
public void testReservedWords() throws Exception {
    if (Util.isJdbc4()) {
        // there is a specific JCDB4 test for this
        return;
    }
    final String mysqlKeywords = "ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB,CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR,"
            + "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED,DETERMINISTIC,DISTINCTROW,DIV,DUAL,EACH,ELSEIF,ENCLOSED,ESCAPED,EXIT,EXPLAIN,FLOAT4,FLOAT8,"
            + "FORCE,FULLTEXT,GENERATED,HIGH_PRIORITY,HOUR_MICROSECOND,HOUR_MINUTE,HOUR_SECOND,IF,IGNORE,INDEX,INFILE,INOUT,INT1,INT2,INT3,INT4,INT8,"
            + "IO_AFTER_GTIDS,IO_BEFORE_GTIDS,ITERATE,KEYS,KILL,LEAVE,LIMIT,LINEAR,LINES,LOAD,LOCALTIME,LOCALTIMESTAMP,LOCK,LONG,LONGBLOB,LONGTEXT,LOOP,"
            + "LOW_PRIORITY,MASTER_BIND,MASTER_SSL_VERIFY_SERVER_CERT,MAXVALUE,MEDIUMBLOB,MEDIUMINT,MEDIUMTEXT,MIDDLEINT,MINUTE_MICROSECOND,MINUTE_SECOND,"
            + "MOD,MODIFIES,NO_WRITE_TO_BINLOG,OPTIMIZE,OPTIMIZER_COSTS,OPTIONALLY,OUT,OUTFILE,PARTITION,PURGE,RANGE,READS,READ_WRITE,REGEXP,RELEASE,"
            + "RENAME,REPEAT,REPLACE,REQUIRE,RESIGNAL,RETURN,RLIKE,SCHEMAS,SECOND_MICROSECOND,SENSITIVE,SEPARATOR,SHOW,SIGNAL,SPATIAL,SPECIFIC,"
            + "SQLEXCEPTION,SQLWARNING,SQL_BIG_RESULT,SQL_CALC_FOUND_ROWS,SQL_SMALL_RESULT,SSL,STARTING,STORED,STRAIGHT_JOIN,TERMINATED,TINYBLOB,TINYINT,"
            + "TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED,USE,UTC_DATE,UTC_TIME,UTC_TIMESTAMP,VARBINARY,VARCHARACTER,VIRTUAL,WHILE,XOR,YEAR_MONTH,ZEROFILL";
    assertEquals("MySQL keywords don't match expected.", mysqlKeywords, this.conn.getMetaData().getSQLKeywords());
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:17,代码来源:MetaDataRegressionTest.java

示例4: proxyIfInterfaceIsJdbc

import com.mysql.jdbc.Util; //导入依赖的package包/类
/**
 * Recursively checks for interfaces on the given object to determine
 * if it implements a java.sql interface, and if so, proxies the
 * instance so that we can catch and fire SQL errors.
 * 
 * @param toProxy
 * @param clazz
 */
private Object proxyIfInterfaceIsJdbc(Object toProxy, Class<?> clazz) {
    Class<?>[] interfaces = clazz.getInterfaces();

    for (Class<?> iclass : interfaces) {
        String packageName = Util.getPackageName(iclass);

        if ("java.sql".equals(packageName) || "javax.sql".equals(packageName)) {
            return Proxy.newProxyInstance(toProxy.getClass().getClassLoader(), interfaces, new ConnectionErrorFiringInvocationHandler(toProxy));
        }

        return proxyIfInterfaceIsJdbc(toProxy, iclass);
    }

    return toProxy;
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:24,代码来源:WrapperBase.java

示例5: populateMapWithSessionStatusValues

import com.mysql.jdbc.Util; //导入依赖的package包/类
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

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

示例6: testCouplingOfCursorFetch

import com.mysql.jdbc.Util; //导入依赖的package包/类
/**
 * Checks if setting useCursorFetch to "true" automatically enables
 * server-side prepared statements.
 */

public void testCouplingOfCursorFetch() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    Connection fetchConn = null;

    try {
        Properties props = new Properties();
        props.setProperty("useServerPrepStmts", "false"); // force the issue
        props.setProperty("useCursorFetch", "true");
        fetchConn = getConnectionWithProps(props);

        String classname = "com.mysql.jdbc.ServerPreparedStatement";

        if (Util.isJdbc42()) {
            classname = "com.mysql.jdbc.JDBC42ServerPreparedStatement";
        } else if (Util.isJdbc4()) {
            classname = "com.mysql.jdbc.JDBC4ServerPreparedStatement";
        }

        assertEquals(classname, fetchConn.prepareStatement("SELECT 1").getClass().getName());
    } finally {
        if (fetchConn != null) {
            fetchConn.close();
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:34,代码来源:ConnectionTest.java

示例7: testBug34703

import com.mysql.jdbc.Util; //导入依赖的package包/类
/** 34703 [NEW]: isValild() aborts Connection on timeout */

    public void testBug34703() throws Exception {
        if (!com.mysql.jdbc.Util.isJdbc4()) {
            return;
        }

        Method isValid = java.sql.Connection.class.getMethod("isValid", new Class[] { Integer.TYPE });

        Connection newConn = getConnectionWithProps((Properties) null);
        isValid.invoke(newConn, new Object[] { new Integer(1) });
        Thread.sleep(2000);
        assertTrue(((Boolean) isValid.invoke(newConn, new Object[] { new Integer(0) })).booleanValue());
    }
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:15,代码来源:ConnectionRegressionTest.java

示例8: testBug16634180

import com.mysql.jdbc.Util; //导入依赖的package包/类
/**
 * Tests fix for Bug#16634180 - LOCK WAIT TIMEOUT EXCEEDED CAUSES SQLEXCEPTION, SHOULD CAUSE SQLTRANSIENTEXCEPTION
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug16634180() throws Exception {

    if (Util.isJdbc4()) {
        // relevant JDBC4+ test is testsuite.regression.jdbc4.ConnectionRegressionTest.testBug16634180()
        return;
    }

    createTable("testBug16634180", "(pk integer primary key, val integer)", "InnoDB");
    this.stmt.executeUpdate("insert into testBug16634180 values(0,0)");

    Connection c1 = null;
    Connection c2 = null;

    try {
        c1 = getConnectionWithProps(new Properties());
        c1.setAutoCommit(false);
        Statement s1 = c1.createStatement();
        s1.executeUpdate("update testBug16634180 set val=val+1 where pk=0");

        c2 = getConnectionWithProps(new Properties());
        c2.setAutoCommit(false);
        Statement s2 = c2.createStatement();
        try {
            s2.executeUpdate("update testBug16634180 set val=val+1 where pk=0");
            fail("ER_LOCK_WAIT_TIMEOUT should be thrown.");
        } catch (MySQLTransientException ex) {
            assertEquals(MysqlErrorNumbers.ER_LOCK_WAIT_TIMEOUT, ex.getErrorCode());
            assertEquals(SQLError.SQL_STATE_ROLLBACK_SERIALIZATION_FAILURE, ex.getSQLState());
            assertEquals("Lock wait timeout exceeded; try restarting transaction", ex.getMessage());
        }
    } finally {
        if (c1 != null) {
            c1.close();
        }
        if (c2 != null) {
            c2.close();
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:46,代码来源:ConnectionRegressionTest.java

示例9: testBug73163

import com.mysql.jdbc.Util; //导入依赖的package包/类
/**
 * Tests fix for BUG#73163 - IndexOutOfBoundsException thrown preparing statement.
 * 
 * This bug occurs only if running with Java6+. Duplicated in testsuite.regression.StatementRegressionTest.testBug73163().
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug73163() throws Exception {
    try {
        stmt = conn.prepareStatement("LOAD DATA INFILE ? INTO TABLE testBug73163");
    } catch (SQLException e) {
        if (e.getCause() instanceof IndexOutOfBoundsException && Util.isJdbc4()) {
            fail("IOOBE thrown in Java6+ while preparing a LOAD DATA statement with placeholders.");
        } else {
            throw e;
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:20,代码来源:StatementRegressionTest.java

示例10: testBug73163

import com.mysql.jdbc.Util; //导入依赖的package包/类
/**
 * Tests fix for BUG#73163 - IndexOutOfBoundsException thrown preparing statement.
 * 
 * This bug occurs only if running with Java6+. Duplicated in testsuite.regression.StatementRegressionTest.jdbc4.testBug73163().
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug73163() throws Exception {
    try {
        this.stmt = this.conn.prepareStatement("LOAD DATA INFILE ? INTO TABLE testBug73163");
    } catch (SQLException e) {
        if (e.getCause() instanceof IndexOutOfBoundsException && Util.isJdbc4()) {
            fail("IOOBE thrown in Java6+ while preparing a LOAD DATA statement with placeholders.");
        } else {
            throw e;
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:20,代码来源:StatementRegressionTest.java

示例11: testBug17248345

import com.mysql.jdbc.Util; //导入依赖的package包/类
/**
 * Tests fix for BUG#17248345 - GETFUNCTIONCOLUMNS() METHOD RETURNS COLUMNS OF PROCEDURE. (this happens when
 * functions and procedures have a common name)
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug17248345() throws Exception {
    if (Util.isJdbc4()) {
        // there is a specific JCDB4 test for this
        return;
    }

    Connection testConn;

    // create one stored procedure and one function with same name
    createFunction("testBug17248345", "(funccol INT) RETURNS INT DETERMINISTIC RETURN 1");
    createProcedure("testBug17248345", "(IN proccol INT) SELECT 1");

    // test with standard connection (getProceduresReturnsFunctions=true & useInformationSchema=false)
    assertFalse("Property useInformationSchema should be false", ((ConnectionProperties) this.conn).getUseInformationSchema());
    assertTrue("Property getProceduresReturnsFunctions should be true", ((ConnectionProperties) this.conn).getGetProceduresReturnsFunctions());
    checkMetaDataInfoForBug17248345(this.conn);

    // test with property useInformationSchema=true (getProceduresReturnsFunctions=true)
    testConn = getConnectionWithProps("useInformationSchema=true");
    assertTrue("Property useInformationSchema should be true", ((ConnectionProperties) testConn).getUseInformationSchema());
    assertTrue("Property getProceduresReturnsFunctions should be true", ((ConnectionProperties) testConn).getGetProceduresReturnsFunctions());
    checkMetaDataInfoForBug17248345(testConn);
    testConn.close();

    // test with property getProceduresReturnsFunctions=false (useInformationSchema=false)
    testConn = getConnectionWithProps("getProceduresReturnsFunctions=false");
    assertFalse("Property useInformationSchema should be false", ((ConnectionProperties) testConn).getUseInformationSchema());
    assertFalse("Property getProceduresReturnsFunctions should be false", ((ConnectionProperties) testConn).getGetProceduresReturnsFunctions());
    checkMetaDataInfoForBug17248345(testConn);
    testConn.close();

    // test with property useInformationSchema=true & getProceduresReturnsFunctions=false
    testConn = getConnectionWithProps("useInformationSchema=true,getProceduresReturnsFunctions=false");
    assertTrue("Property useInformationSchema should be true", ((ConnectionProperties) testConn).getUseInformationSchema());
    assertFalse("Property getProceduresReturnsFunctions should be false", ((ConnectionProperties) testConn).getGetProceduresReturnsFunctions());
    checkMetaDataInfoForBug17248345(testConn);
    testConn.close();
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:46,代码来源:MetaDataRegressionTest.java

示例12: getInstance

import com.mysql.jdbc.Util; //导入依赖的package包/类
protected static MysqlPooledConnection getInstance(com.mysql.jdbc.Connection connection) throws SQLException {
    if (!Util.isJdbc4()) {
        return new MysqlPooledConnection(connection);
    }

    return (MysqlPooledConnection) Util.handleNewInstance(JDBC_4_POOLED_CONNECTION_WRAPPER_CTOR, new Object[] { connection },
            connection.getExceptionInterceptor());
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:9,代码来源:MysqlPooledConnection.java

示例13: findCallingClassAndMethod

import com.mysql.jdbc.Util; //导入依赖的package包/类
public static String findCallingClassAndMethod(Throwable t) {
    String stackTraceAsString = Util.stackTraceToString(t);

    String callingClassAndMethod = CALLER_INFORMATION_NOT_AVAILABLE;

    int endInternalMethods = stackTraceAsString.lastIndexOf("com.mysql.jdbc");

    if (endInternalMethods != -1) {
        int endOfLine = -1;
        int compliancePackage = stackTraceAsString.indexOf("com.mysql.jdbc.compliance", endInternalMethods);

        if (compliancePackage != -1) {
            endOfLine = compliancePackage - LINE_SEPARATOR_LENGTH;
        } else {
            endOfLine = stackTraceAsString.indexOf(LINE_SEPARATOR, endInternalMethods);
        }

        if (endOfLine != -1) {
            int nextEndOfLine = stackTraceAsString.indexOf(LINE_SEPARATOR, endOfLine + LINE_SEPARATOR_LENGTH);

            if (nextEndOfLine != -1) {
                callingClassAndMethod = stackTraceAsString.substring(endOfLine + LINE_SEPARATOR_LENGTH, nextEndOfLine);
            } else {
                callingClassAndMethod = stackTraceAsString.substring(endOfLine + LINE_SEPARATOR_LENGTH);
            }
        }
    }

    if (!callingClassAndMethod.startsWith("\tat ") && !callingClassAndMethod.startsWith("at ")) {
        return "at " + callingClassAndMethod;
    }

    return callingClassAndMethod;
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:35,代码来源:LogUtils.java

示例14: getInstance

import com.mysql.jdbc.Util; //导入依赖的package包/类
protected static SuspendableXAConnection getInstance(Connection mysqlConnection) throws SQLException {
    if (!Util.isJdbc4()) {
        return new SuspendableXAConnection(mysqlConnection);
    }

    return (SuspendableXAConnection) Util.handleNewInstance(JDBC_4_XA_CONNECTION_WRAPPER_CTOR, new Object[] { mysqlConnection },
            mysqlConnection.getExceptionInterceptor());
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:9,代码来源:SuspendableXAConnection.java

示例15: getInstance

import com.mysql.jdbc.Util; //导入依赖的package包/类
protected static CallableStatementWrapper getInstance(ConnectionWrapper c, MysqlPooledConnection conn, CallableStatement toWrap) throws SQLException {
    if (!Util.isJdbc4()) {
        return new CallableStatementWrapper(c, conn, toWrap);
    }

    return (CallableStatementWrapper) Util.handleNewInstance(JDBC_4_CALLABLE_STATEMENT_WRAPPER_CTOR, new Object[] { c, conn, toWrap },
            conn.getExceptionInterceptor());
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:9,代码来源:CallableStatementWrapper.java


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