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


Java Connection类代码示例

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


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

示例1: init

import com.mysql.jdbc.Connection; //导入依赖的package包/类
public void init(Connection conn, Properties props) throws SQLException {
    String regexFromUser = props.getProperty("resultSetScannerRegex");

    if (regexFromUser == null || regexFromUser.length() == 0) {
        throw new SQLException("resultSetScannerRegex must be configured, and must be > 0 characters");
    }

    try {
        this.regexP = Pattern.compile(regexFromUser);
    } catch (Throwable t) {
        SQLException sqlEx = new SQLException("Can't use configured regex due to underlying exception.");
        sqlEx.initCause(t);

        throw sqlEx;
    }

}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:18,代码来源:ResultSetScannerInterceptor.java

示例2: preProcess

import com.mysql.jdbc.Connection; //导入依赖的package包/类
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

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

示例3: populateMapWithSessionStatusValues

import com.mysql.jdbc.Connection; //导入依赖的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:lamsfoundation,项目名称:lams,代码行数:21,代码来源:ServerStatusDiffInterceptor.java

示例4: getInstance

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

    return (ConnectionWrapper) Util.handleNewInstance(JDBC_4_CONNECTION_WRAPPER_CTOR,
            new Object[] { mysqlPooledConnection, mysqlConnection, Boolean.valueOf(forXa) }, mysqlPooledConnection.getExceptionInterceptor());
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:9,代码来源:ConnectionWrapper.java

示例5: getLocales

import com.mysql.jdbc.Connection; //导入依赖的package包/类
/**
 * Returns a List of {@link Locale}s for the given user
 * @param userId of the user to get the locales from
 * @param con Connection to use - is injected automatically
 * @return a list of {@link Locale}s
 */
@GET
public Response getLocales(@PathParam("userId") final long userId, @Context final Connection con) {
	getAccessChecker().checkLoggedInUser(userId);
	final List<Locale> locales = new UserLocaleDao(con).getLocalesForUser(userId);
	return ok(locales);
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:13,代码来源:UserLocalesService.java

示例6: init

import com.mysql.jdbc.Connection; //导入依赖的package包/类
public void init(Connection conn, Properties props) throws SQLException {
    this.connection = conn;

    String pkURL = this.connection.getServerRSAPublicKeyFile();
    if (pkURL != null) {
        this.publicKeyString = readRSAKey(this.connection, pkURL);
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:9,代码来源:Sha256PasswordPlugin.java

示例7: getConnection

import com.mysql.jdbc.Connection; //导入依赖的package包/类
@Override
public synchronized java.sql.Connection getConnection() throws SQLException {
    if (this.currentXAConnection == null) {
        return getConnection(false, true);
    }

    return this.currentXAConnection.getConnection();
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:9,代码来源:SuspendableXAConnection.java

示例8: preProcess

import com.mysql.jdbc.Connection; //导入依赖的package包/类
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {

        if (connection.versionMeetsMinimum(5, 0, 2)) {
            populateMapWithSessionStatusValues(connection, this.preExecuteValues);
        }

        return null; // we don't actually modify a result set
    }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:ServerStatusDiffInterceptor.java

示例9: getActiveConnectionPassive

import com.mysql.jdbc.Connection; //导入依赖的package包/类
protected Connection getActiveConnectionPassive() {
    try {
        return getActiveConnection();
    } catch (SQLException ex) {
        throw new IllegalStateException("Unable to determine active connection", ex);
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:8,代码来源:FabricMySQLConnectionProxy.java

示例10: testSelectAll

import com.mysql.jdbc.Connection; //导入依赖的package包/类
@Test
public void testSelectAll() throws SQLException {
	String testSql = "SELECT * FROM Sequence";

	JdbcDatabase db = spy(new JdbcDatabase(null, null, null));
	Connection conn = mock(Connection.class);
	doReturn(conn).when(db).getConnection();
	PreparedStatement stmt = mock(PreparedStatement.class);
	when(conn.prepareStatement(any(String.class))).thenReturn(stmt);

	db.selectAll(testSql, rs -> null);
	verify(conn, times(1)).prepareStatement(testSql);
}
 
开发者ID:hivdb,项目名称:sierra,代码行数:14,代码来源:MySqlUtilsTest.java

示例11: encryptPassword

import com.mysql.jdbc.Connection; //导入依赖的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:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:15,代码来源:Sha256PasswordPlugin.java

示例12: checkConnection

import com.mysql.jdbc.Connection; //导入依赖的package包/类
public void checkConnection() {
    conn = (Connection) SqlConnection.DbConnetor();
    if (conn == null) {
        System.out.println("Connection not successfull");
        System.exit(1);
    } else {
        System.out.println("Connection successfull");
    }

}
 
开发者ID:dewarian,项目名称:FYS_T3,代码行数:11,代码来源:searchLugController.java

示例13: close

import com.mysql.jdbc.Connection; //导入依赖的package包/类
/**
 * Close this connection proxy which entails closing all
 * open connections to MySQL servers.
 */
public void close() throws SQLException {
    this.closed = true;
    for (Connection c : this.serverConnections.values()) {
        try {
            c.close();
        } catch (SQLException ex) {
        }
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:14,代码来源:FabricMySQLConnectionProxy.java

示例14: getInstance

import com.mysql.jdbc.Connection; //导入依赖的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: interceptException

import com.mysql.jdbc.Connection; //导入依赖的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:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:16,代码来源:ErrorReportingExceptionInterceptor.java


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