當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。