📄 connection.java
字号:
* * @throws SQLException passed through from the constructor */ public java.sql.Statement createStatement() throws SQLException { return createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); } /** * @see Connection#createStatement(int, int, int) */ public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { if (getPedantic()) { if (resultSetHoldability != java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT) { throw new SQLException("HOLD_CUSRORS_OVER_COMMIT is only supported holdability level", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } return createStatement(resultSetType, resultSetConcurrency); } /** * Is the server configured to use lower-case table names only? * * @return true if lower_case_table_names is 'on' */ public boolean lowerCaseTableNames() { return this.lowerCaseTableNames; } /** * A driver may convert the JDBC sql grammar into its system's native SQL * grammar prior to sending it; nativeSQL returns the native form of the * statement that the driver would have sent. * * @param sql a SQL statement that may contain one or more '?' parameter * placeholders * * @return the native form of this statement * * @exception SQLException if a database access error occurs */ public String nativeSQL(String sql) throws SQLException { if (sql == null) { return null; } Object escapedSqlResult = EscapeProcessor.escapeSQL(sql, serverSupportsConvertFn()); if (escapedSqlResult instanceof String) { return (String)escapedSqlResult; } return ((EscapeProcessorResult)escapedSqlResult).escapedSql; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public boolean parserKnowsUnicode() { return this.parserKnowsUnicode; } /** * DOCUMENT ME! * * @param sql DOCUMENT ME! * * @return DOCUMENT ME! * * @throws SQLException DOCUMENT ME! */ public java.sql.CallableStatement prepareCall(String sql) throws SQLException { if (this.getUseUltraDevWorkAround()) { return new UltraDevWorkAround(prepareStatement(sql)); } return prepareCall(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); } /** * JDBC 2.0 Same as prepareCall() above, but allows the default result set * type and result set concurrency type to be overridden. * * @param sql the SQL representing the callable statement * @param resultSetType a result set type, see ResultSet.TYPE_XXX * @param resultSetConcurrency a concurrency type, see ResultSet.CONCUR_XXX * * @return a new CallableStatement object containing the pre-compiled SQL * statement * * @exception SQLException if a database-access error occurs. */ public synchronized java.sql.CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { if (versionMeetsMinimum(5, 0, 0)) { CallableStatement cStmt = null; if (!getCacheCallableStatements()) { cStmt = new CallableStatement(this, sql, this.database); } else { if (this.parsedCallableStatementCache == null) { this.parsedCallableStatementCache = new LRUCache(getCallableStatementCacheSize()); } CompoundCacheKey key = new CompoundCacheKey(getCatalog(), sql); CallableStatement.CallableStatementParamInfo cachedParamInfo = (CallableStatement.CallableStatementParamInfo) this.parsedCallableStatementCache .get(key); if (cachedParamInfo != null) { cStmt = new CallableStatement(this, cachedParamInfo); } else { cStmt = new CallableStatement(this, sql, this.database); cachedParamInfo = cStmt.paramInfo; this.parsedCallableStatementCache.put(key, cachedParamInfo); } } cStmt.setResultSetType(resultSetType); cStmt.setResultSetConcurrency(resultSetConcurrency); return cStmt; } throw new SQLException("Callable statements not " + "supported.", SQLError.SQL_STATE_DRIVER_NOT_CAPABLE); } /** * @see Connection#prepareCall(String, int, int, int) */ public java.sql.CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { if (getPedantic()) { if (resultSetHoldability != java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT) { throw new SQLException("HOLD_CUSRORS_OVER_COMMIT is only supported holdability level", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } CallableStatement cStmt = (com.mysql.jdbc.CallableStatement) prepareCall(sql, resultSetType, resultSetConcurrency); return cStmt; } /** * A SQL statement with or without IN parameters can be pre-compiled and * stored in a PreparedStatement object. This object can then be used to * efficiently execute this statement multiple times. * * <p> * <B>Note:</B> This method is optimized for handling parametric SQL * statements that benefit from precompilation if the driver supports * precompilation. In this case, the statement is not sent to the database * until the PreparedStatement is executed. This has no direct effect on * users; however it does affect which method throws certain * java.sql.SQLExceptions * </p> * * <p> * MySQL does not support precompilation of statements, so they are handled * by the driver. * </p> * * @param sql a SQL statement that may contain one or more '?' IN parameter * placeholders * * @return a new PreparedStatement object containing the pre-compiled * statement. * * @exception SQLException if a database access error occurs. */ public java.sql.PreparedStatement prepareStatement(String sql) throws SQLException { return prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); } /** * JDBC 2.0 Same as prepareStatement() above, but allows the default result * set type and result set concurrency type to be overridden. * * @param sql the SQL query containing place holders * @param resultSetType a result set type, see ResultSet.TYPE_XXX * @param resultSetConcurrency a concurrency type, see ResultSet.CONCUR_XXX * * @return a new PreparedStatement object containing the pre-compiled SQL * statement * * @exception SQLException if a database-access error occurs. */ public java.sql.PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { checkClosed(); // // FIXME: Create warnings if can't create results of the given // type or concurrency // PreparedStatement pStmt = null; boolean canServerPrepare = true; if (getEmulateUnsupportedPstmts()) { canServerPrepare = canHandleAsServerPreparedStatement(sql); } if (this.useServerPreparedStmts && canServerPrepare) { try { pStmt = new com.mysql.jdbc.ServerPreparedStatement(this, sql, this.database); } catch (SQLException sqlEx) { // Punt, if necessary if (getEmulateUnsupportedPstmts()) { pStmt = clientPrepareStatement(sql); } } } else { pStmt = clientPrepareStatement(sql); } pStmt.setResultSetType(resultSetType); pStmt.setResultSetConcurrency(resultSetConcurrency); return pStmt; } /** * @see Connection#prepareStatement(String, int, int, int) */ public java.sql.PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { if (getPedantic()) { if (resultSetHoldability != java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT) { throw new SQLException("HOLD_CUSRORS_OVER_COMMIT is only supported holdability level", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } return prepareStatement(sql, resultSetType, resultSetConcurrency); } /** * @see Connection#prepareStatement(String, int) */ public java.sql.PreparedStatement prepareStatement(String sql, int autoGenKeyIndex) throws SQLException { java.sql.PreparedStatement pStmt = prepareStatement(sql); ((com.mysql.jdbc.PreparedStatement) pStmt).setRetrieveGeneratedKeys(autoGenKeyIndex == java.sql.Statement.RETURN_GENERATED_KEYS); return pStmt; } /** * @see Connection#prepareStatement(String, int[]) */ public java.sql.PreparedStatement prepareStatement(String sql, int[] autoGenKeyIndexes) throws SQLException { java.sql.PreparedStatement pStmt = prepareStatement(sql); ((com.mysql.jdbc.PreparedStatement) pStmt).setRetrieveGeneratedKeys((autoGenKeyIndexes != null) && (autoGenKeyIndexes.length > 0)); return pStmt; } /** * @see Connection#prepareStatement(String, String[]) */ public java.sql.PreparedStatement prepareStatement(String sql, String[] autoGenKeyColNames) throws SQLException { java.sql.PreparedStatement pStmt = prepareStatement(sql); ((com.mysql.jdbc.PreparedStatement) pStmt).setRetrieveGeneratedKeys((autoGenKeyColNames != null) && (autoGenKeyColNames.length > 0)); return pStmt; } /** * @see Connection#releaseSavepoint(Savepoint) */ public void releaseSavepoint(Savepoint arg0) throws SQLException { // this is a no-op } /** * Resets the server-side state of this connection. Doesn't work for MySQL * versions older than 4.0.6 or if isParanoid() is set (it will become a * no-op in these cases). Usually only used from connection pooling code. * * @throws SQLException if the operation fails while resetting server * state. */ public void resetServerState() throws SQLException { if (!getParanoid() && ((this.io != null) & versionMeetsMinimum(4, 0, 6))) { changeUser(this.user, this.password); } } /** * The method rollback() drops all changes made since the previous * commit/rollback and releases any database locks currently held by the * Connection. * * @exception SQLException if a database access error occurs * * @see commit */ public void rollback() throws SQLException { checkClosed(); try { // no-op if _relaxAutoCommit == true if (this.autoCommit && !getRelaxAutoCommit()) { throw new SQLException("Can't call rollback when autocommit=true", SQLError.SQL_STATE_CONNECTION_NOT_OPEN); } else if (this.transactionsSupported) { try { rollbackNoChecks(); } catch (SQLException sqlEx) { // We ignore non-transactional tables if told to do so if (getIgnoreNonTxTables() && (sqlEx.getErrorCode() != SQLError.ER_WARNING_NOT_COMPLETE_ROLLBACK)) { throw sqlEx; } } } } catch (SQLException sqlException) { if (SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE.equals(sqlException.getSQLState())) { throw new SQLException("Communications link failure during rollback(). Transaction resolution unknown.", SQLError.SQL_STATE_TRANSACTION_RESOLUTION_UNKNOWN); } throw sqlException; } finally { this.needsPing = this.getReconnectAtTxEnd(); } } /** * @see Connection#rollback(Savepoint) */ public void rollback(Savepoint savepoint) throws SQLException { if (versionMeetsMinimum(4, 0, 14) || versionMeetsMinimum(4, 1, 1)) { checkClosed(); try { StringBuffer rollbackQuery = new StringBuffer( "ROLLBACK TO SAVEPOINT "); rollbackQuery.append('`'); rollbackQuery.append(savepoint.getSavepointName()); rollbackQuery.append('`'); java.sql.Statement stmt = null; try { stmt = createStatement(); stmt.executeUpdate(rollbackQuery.toString()); } catch (SQLException sqlEx) { int errno = sqlEx.getErrorCode();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -