本文整理汇总了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;
}
}
示例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;
}
示例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();
}
}
}
示例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());
}
示例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);
}
示例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);
}
}
示例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();
}
示例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
}
示例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);
}
}
示例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);
}
示例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());
}
示例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");
}
}
示例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) {
}
}
}
示例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());
}
示例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);
}
}