📄 connection.java
字号:
* * @throws SQLException if the connection is closed. */ public void setProfileSql(boolean flag) throws SQLException { // For re-connection this.props.setProperty("profileSql", String.valueOf(flag)); getIO().setProfileSql(flag); } /** * You can put a connection in read-only mode as a hint to enable database * optimizations <B>Note:</B> setReadOnly cannot be called while in the * middle of a transaction * * @param readOnly - true enables read-only mode; false disables it * * @exception java.sql.SQLException if a database access error occurs */ public void setReadOnly(boolean readOnly) throws java.sql.SQLException { if (Driver.TRACE) { Object[] args = { new Boolean(readOnly) }; Debug.methodCall(this, "setReadOnly", args); Debug.returnValue(this, "setReadOnly", new Boolean(readOnly)); } checkClosed(); this.readOnly = readOnly; } /** * Tests to see if the connection is in Read Only Mode. Note that we * cannot really put the database in read only mode, but we pretend we can * by returning the value of the readOnly flag * * @return true if the connection is read only * * @exception java.sql.SQLException if a database access error occurs */ public boolean isReadOnly() throws java.sql.SQLException { if (Driver.TRACE) { Object[] args = new Object[0]; Debug.methodCall(this, "isReadOnly", args); Debug.returnValue(this, "isReadOnly", new Boolean(this.readOnly)); } return this.readOnly; } /** * @see Connection#setSavepoint() */ public java.sql.Savepoint setSavepoint() throws SQLException { throw new NotImplemented(); } /** * @see Connection#setSavepoint(String) */ public java.sql.Savepoint setSavepoint(String arg0) throws SQLException { throw new NotImplemented(); } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public TimeZone getServerTimezone() { return this.serverTimezone; } /** * DOCUMENT ME! * * @param level DOCUMENT ME! * * @throws java.sql.SQLException DOCUMENT ME! * @throws SQLException DOCUMENT ME! */ public void setTransactionIsolation(int level) throws java.sql.SQLException { if (Driver.TRACE) { Object[] args = { new Integer(level) }; Debug.methodCall(this, "setTransactionIsolation", args); } checkClosed(); if (this.hasIsolationLevels) { StringBuffer sql = new StringBuffer( "SET SESSION TRANSACTION ISOLATION LEVEL "); switch (level) { case java.sql.Connection.TRANSACTION_NONE: throw new SQLException("Transaction isolation level " + "NONE not supported by MySQL"); case java.sql.Connection.TRANSACTION_READ_COMMITTED: sql.append("READ COMMITTED"); break; case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED: sql.append("READ UNCOMMITTED"); break; case java.sql.Connection.TRANSACTION_REPEATABLE_READ: sql.append("REPEATABLE READ"); break; case java.sql.Connection.TRANSACTION_SERIALIZABLE: sql.append("SERIALIZABLE"); break; default: throw new SQLException("Unsupported transaction " + "isolation level '" + level + "'", "S1C00"); } execSQL(sql.toString(), -1, this.database); isolationLevel = level; } else { throw new java.sql.SQLException("Transaction Isolation Levels are " + "not supported on MySQL versions older than 3.23.36.", "S1C00"); } } /** * Get this Connection's current transaction isolation mode. * * @return the current TRANSACTION_ mode value * * @exception java.sql.SQLException if a database access error occurs * @throws SQLException DOCUMENT ME! */ public int getTransactionIsolation() throws java.sql.SQLException { if (Driver.TRACE) { Object[] args = new Object[0]; Debug.methodCall(this, "getTransactionIsolation", args); Debug.returnValue(this, "getTransactionIsolation", new Integer(isolationLevel)); } if (this.hasIsolationLevels) { java.sql.Statement stmt = null; java.sql.ResultSet rs = null; try { stmt = this.createStatement(); if (stmt.getMaxRows() != 0) { stmt.setMaxRows(0); } String query = null; if (this.io.versionMeetsMinimum(4, 0, 3)) { query = "SHOW VARIABLES LIKE 'tx_isolation'"; } else { query = "SHOW VARIABLES LIKE 'transaction_isolation'"; } rs = stmt.executeQuery(query); if (rs.next()) { String s = rs.getString(2); if (s != null) { Integer intTI = (Integer) mapTransIsolationName2Value .get(s); if (intTI != null) { return intTI.intValue(); } } throw new SQLException( "Could not map transaction isolation '" + s + " to a valid JDBC level.", SQLError.SQL_STATE_GENERAL_ERROR); } else { throw new SQLException("Could not retrieve transaction isolation level from server", SQLError.SQL_STATE_GENERAL_ERROR); } } finally { if (rs != null) { try { rs.close(); } catch (Exception ex) { // ignore } rs = null; } if (stmt != null) { try { stmt.close(); } catch (Exception ex) { // ignore } stmt = null; } } } return isolationLevel; } /** * JDBC 2.0 Install a type-map object as the default type-map for this * connection * * @param map the type mapping * * @throws SQLException if a database error occurs. */ public void setTypeMap(java.util.Map map) throws SQLException { this.typeMap = map; } /** * JDBC 2.0 Get the type-map object associated with this connection. By * default, the map returned is empty. * * @return the type map * * @throws SQLException if a database error occurs */ public synchronized java.util.Map getTypeMap() throws SQLException { if (this.typeMap == null) { this.typeMap = new HashMap(); } return this.typeMap; } /** * The first warning reported by calls on this Connection is returned. * <B>Note:</B> Sebsequent warnings will be changed to this * java.sql.SQLWarning * * @return the first java.sql.SQLWarning or null * * @exception java.sql.SQLException if a database access error occurs */ public java.sql.SQLWarning getWarnings() throws java.sql.SQLException { if (Driver.TRACE) { Object[] args = new Object[0]; Debug.methodCall(this, "getWarnings", args); Debug.returnValue(this, "getWarnings", null); } return null; } /** * Allow use of LOAD LOCAL INFILE? * * @return true if allowLoadLocalInfile was set to true. */ public boolean allowLoadLocalInfile() { return this.allowLoadLocalInfile; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public boolean capitalizeDBMDTypes() { return this.capitalizeDBMDTypes; } /** * Changes the user on this connection by performing a re-authentication. * If authentication fails, the connection will remain under the context * of the current user. * * @param userName the username to authenticate with * @param newPassword the password to authenticate with * * @throws SQLException if authentication fails, or some other error occurs * while performing the command. */ public void changeUser(String userName, String newPassword) throws SQLException { if ((userName == null) || userName.equals("")) { userName = ""; } if (newPassword == null) { newPassword = ""; } this.io.changeUser(userName, newPassword, this.database); this.user = userName; this.password = newPassword; if (this.io.versionMeetsMinimum(4, 1, 0)) { configureClientCharacterSet(); } } /** * After this call, getWarnings returns null until a new warning is * reported for this connection. * * @exception java.sql.SQLException if a database access error occurs */ public void clearWarnings() throws java.sql.SQLException { if (Driver.TRACE) { Object[] args = new Object[0]; Debug.methodCall(this, "clearWarnings", args); } // firstWarning = null; } /** * In some cases, it is desirable to immediately release a Connection's * database and JDBC resources instead of waiting for them to be * automatically released (cant think why off the top of my head) * <B>Note:</B> A Connection is automatically closed when it is garbage * collected. Certain fatal errors also result in a closed connection. * * @exception java.sql.SQLException if a database access error occurs */ public void close() throws java.sql.SQLException { if (this.explicitCloseLocation == null) { this.explicitCloseLocation = new Throwable(); } realClose(true, true); } /** * The method commit() makes all changes made since the previous * commit/rollback permanent and releases any database locks currently * held by the Connection. This method should only be used when * auto-commit has been disabled. * * @exception java.sql.SQLException if a database access error occurs * * @see setAutoCommit */ public void commit() throws java.sql.SQLException { if (Driver.TRACE) { Object[] args = new Object[0]; Debug.methodCall(this, "commit", args); } checkClosed(); try { // no-op if _relaxAutoCommit == true if (this.autoCommit && !this.relaxAutoCommit) { throw new SQLException("Can't call commit when autocommit=true", SQLError.SQL_STATE_GENERAL_ERROR); } else if (this.transactionsSupported) { execSQL("commit", -1, this.database); } } finally { if (this.reconnectAtTxEnd) { pingAndReconnect(true); } } return; } //--------------------------JDBC 2.0----------------------------- /** * JDBC 2.0 Same as createStatement() above, but allows the default result * set type and result set concurrency type to be overridden. * * @param resultSetType a result set type, see ResultSet.TYPE_XXX * @param resultSetConcurrency a concurrency type, see ResultSet.CONCUR_XXX * * @return a new Statement object * * @exception SQLException if a database-access error occurs. */ public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { checkClosed(); Statement stmt = new com.mysql.jdbc.Statement(this, this.database); stmt.setResultSetType(resultSetType);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -