⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 embedconnection.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		if (isClosed())			throw Util.noCurrentConnection();		return factory.newEmbedStatement(this, false,			setResultSetType(resultSetType), setResultSetConcurrency(resultSetType, resultSetConcurrency),			resultSetHoldability);	}    /**     * 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, prepareStatement will send     * the statement to the database for precompilation. Some drivers     * may not support precompilation. In this case, the statement may     * not be sent to the database until the PreparedStatement is     * executed.  This has no direct affect on users; however, it does     * affect which method throws certain SQLExceptions.     *     * JDBC 2.0     *     * Result sets created using the returned PreparedStatement will have     * forward-only type, and read-only concurrency, by default.     *     * @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 final PreparedStatement prepareStatement(String sql)	    throws SQLException	{		return prepareStatement(sql,JDBC20Translation.TYPE_FORWARD_ONLY,			JDBC20Translation.CONCUR_READ_ONLY,			connectionHoldAbility,			JDBC30Translation.NO_GENERATED_KEYS,			null,			null);	}    /**     * JDBC 2.0     *     * Same as prepareStatement() 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 PreparedStatement object containing the     * pre-compiled SQL statement     * @exception SQLException if a database-access error occurs.     */    public final PreparedStatement prepareStatement(String sql, int resultSetType,					int resultSetConcurrency)	    throws SQLException	{		return prepareStatement(sql,			resultSetType,			resultSetConcurrency,			connectionHoldAbility,			JDBC30Translation.NO_GENERATED_KEYS,			null,			null);	}    /**     * JDBC 3.0     *     * Same as prepareStatement() above, but allows the default result set     * type, result set concurrency type and result set holdability     * to be overridden.     *     * @param resultSetType a result set type, see ResultSet.TYPE_XXX     * @param resultSetConcurrency a concurrency type, see ResultSet.CONCUR_XXX     * @param resultSetHoldability - one of the following ResultSet constants:     *  ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT     * @return a new PreparedStatement object containing the     *  pre-compiled SQL statement     * @exception SQLException if a database-access error occurs.     */    public final PreparedStatement prepareStatement(String sql, int resultSetType,					int resultSetConcurrency, int resultSetHoldability)	    throws SQLException	{		return prepareStatement(sql,			resultSetType,			resultSetConcurrency,			resultSetHoldability,			JDBC30Translation.NO_GENERATED_KEYS,			null,			null);	}	/**	 * Creates a default PreparedStatement object capable of returning	 * the auto-generated keys designated by the given array. This array contains	 * the indexes of the columns in the target table that contain the auto-generated	 * keys that should be made available. This array is ignored if the SQL statement	 * is not an INSERT statement		JDBC 3.0	 *	 *	 * @param sql  An SQL statement that may contain one or more ? IN parameter placeholders	 * @param columnIndexes  An array of column indexes indicating the columns	 *  that should be returned from the inserted row or rows	 *	 * @return  A new PreparedStatement object, containing the pre-compiled	 *  SQL statement, that will have the capability of returning auto-generated keys	 *  designated by the given array of column indexes	 *	 * @exception SQLException  Feature not implemented for now.	 */	public final PreparedStatement prepareStatement(			String sql,			int[] columnIndexes)    throws SQLException	{ 		throw Util.notImplemented("prepareStatement(String, int[])");	}	/**	 * Creates a default PreparedStatement object capable of returning	 * the auto-generated keys designated by the given array. This array contains	 * the names of the columns in the target table that contain the auto-generated	 * keys that should be returned. This array is ignored if the SQL statement	 * is not an INSERT statement	 *		JDBC 3.0	 *	 * @param sql  An SQL statement that may contain one or more ? IN parameter placeholders	 * @param columnNames  An array of column names indicating the columns	 *  that should be returned from the inserted row or rows	 *	 * @return  A new PreparedStatement object, containing the pre-compiled	 *  SQL statement, that will have the capability of returning auto-generated keys	 *  designated by the given array of column names	 *	 * @exception SQLException  Feature not implemented for now.	 */	public final PreparedStatement prepareStatement(			String sql,			String[] columnNames)    throws SQLException	{ 		throw Util.notImplemented("prepareStatement(String, String[])");	}	/**	 * Creates a default PreparedStatement object that has the capability to	 * retieve auto-generated keys. The given constant tells the driver	 * whether it should make auto-generated keys available for retrieval.	 * This parameter is ignored if the SQL statement is not an INSERT statement.	 * JDBC 3.0	 *	 * @param sql  A SQL statement that may contain one or more ? IN parameter placeholders	 * @param autoGeneratedKeys  A flag indicating whether auto-generated keys	 *  should be returned	 *	 * @return  A new PreparedStatement object, containing the pre-compiled	 *  SQL statement, that will have the capability of returning auto-generated keys	 *	 * @exception SQLException  Feature not implemented for now.	 */	public final PreparedStatement prepareStatement(			String sql,			int autoGeneratedKeys)    throws SQLException	{		return prepareStatement(sql,			JDBC20Translation.TYPE_FORWARD_ONLY,			JDBC20Translation.CONCUR_READ_ONLY,			connectionHoldAbility,			autoGeneratedKeys,			null,			null);	}    	private PreparedStatement prepareStatement(String sql, int resultSetType,					int resultSetConcurrency, int resultSetHoldability,					int autoGeneratedKeys, int[] columnIndexes, String[] columnNames)       throws SQLException	 {		synchronized (getConnectionSynchronization()) {                        setupContextStack();			try {			    return factory.newEmbedPreparedStatement(this, sql, false,											   setResultSetType(resultSetType),											   setResultSetConcurrency(resultSetType, resultSetConcurrency),											   resultSetHoldability,											   autoGeneratedKeys,											   columnIndexes,											   columnNames);			} finally {			    restoreContextStack();			}		}     }    /**     * A SQL stored procedure call statement is handled by creating a     * CallableStatement for it. The CallableStatement provides     * methods for setting up its IN and OUT parameters, and     * methods for executing it.     *     * <P><B>Note:</B> This method is optimized for handling stored     * procedure call statements. Some drivers may send the call     * statement to the database when the prepareCall is done; others     * may wait until the CallableStatement is executed. This has no     * direct affect on users; however, it does affect which method     * throws certain SQLExceptions.     *     * JDBC 2.0     *     * Result sets created using the returned CallableStatement will have     * forward-only type, and read-only concurrency, by default.     *     * @param sql a SQL statement that may contain one or more '?'     * parameter placeholders. Typically this  statement is a JDBC     * function call escape string.     * @return a new CallableStatement object containing the     * pre-compiled SQL statement      * @exception SQLException if a database-access error occurs.     */	public final CallableStatement prepareCall(String sql) 		throws SQLException 	{		return prepareCall(sql, JDBC20Translation.TYPE_FORWARD_ONLY,						   JDBC20Translation.CONCUR_READ_ONLY,						   connectionHoldAbility);	}    /**     * JDBC 2.0     *     * Same as prepareCall() 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 CallableStatement object containing the     * pre-compiled SQL statement      * @exception SQLException if a database-access error occurs.     */    public final CallableStatement prepareCall(String sql, int resultSetType,				 int resultSetConcurrency)		throws SQLException 	{		return prepareCall(sql, resultSetType, resultSetConcurrency,						   connectionHoldAbility);	}    /**     * JDBC 3.0     *     * Same as prepareCall() above, but allows the default result set     * type, result set concurrency type and result set holdability     * to be overridden.     *     * @param resultSetType a result set type, see ResultSet.TYPE_XXX     * @param resultSetConcurrency a concurrency type, see ResultSet.CONCUR_XXX     * @param resultSetHoldability - one of the following ResultSet constants:     *  ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT     * @return a new CallableStatement object containing the     * pre-compiled SQL statement      * @exception SQLException if a database-access error occurs.     */    public final CallableStatement prepareCall(String sql, int resultSetType, 				 int resultSetConcurrency, int resultSetHoldability)		throws SQLException 	{		if (SanityManager.DEBUG)			SanityManager.ASSERT(!isClosed(), "connection is closed");		synchronized (getConnectionSynchronization())		{            setupContextStack();			try 			{			    return factory.newEmbedCallableStatement(this, sql,											   setResultSetType(resultSetType),											   setResultSetConcurrency(resultSetType, resultSetConcurrency),											   resultSetHoldability);			} 			finally 			{			    restoreContextStack();			}		}	}    /**     * 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     */    public String nativeSQL(String sql) {		// we don't massage the strings at all, so this is easy:		return sql;	}    /**     * If a connection is in auto-commit mode, then all its SQL     * statements will be executed and committed as individual     * transactions.  Otherwise, its SQL statements are grouped into     * transactions that are terminated by either commit() or     * rollback().  By default, new connections are in auto-commit     * mode.     *     * The commit occurs when the statement completes or the next     * execute occurs, whichever comes first. In the case of     * statements returning a ResultSet, the statement completes when     * the last row of the ResultSet has been retrieved or the     * ResultSet has been closed. In advanced cases, a single     * statement may return multiple results as well as output     * parameter values. Here the commit occurs when all results and     * output param values have been retrieved.     *     * @param autoCommit true enables auto-commit; false disables     * auto-commit.       * @exception SQLException if a database-access error occurs.     */	public void setAutoCommit(boolean autoCommit) throws SQLException {		// Is this a nested connection		if (rootConnection != this) {			if (autoCommit)				throw newSQLException(SQLState.NO_AUTO_COMMIT_ON);		}		if (this.autoCommit != autoCommit)			commit();		this.autoCommit = autoCommit;	}    /**     * Get the current auto-commit state.     *     * @return Current state of auto-commit mode.     * @see #setAutoCommit      */    public boolean getAutoCommit() {		return autoCommit;	}    /**     * 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 SQLException if a database-access error occurs.     * @see #setAutoCommit      */    public void commit() throws SQLException {		synchronized (getConnectionSynchronization())		{			/*			** Note that the context stack is			** needed even for rollback & commit			*/            setupContextStack();			try			{		    	getTR().commit();			}            catch (Throwable t)			{				throw handleException(t);			}			finally 			{				restoreContextStack();			}			needCommit = false;		}	}    /**     * Rollback drops all changes made since the previous     * commit/rollback and releases any database locks currently held     * by the Connection. This method should only be used when auto     * commit has been disabled.     *     * @exception SQLException if a database-access error occurs.     * @see #setAutoCommit      */    public void rollback() throws SQLException {		synchronized (getConnectionSynchronization())		{			/*			** Note that the context stack is			** needed even for rollback & commit			*/            setupContextStack();			try			{		    	getTR().rollback();			} catch (Throwable t) {				throw handleException(t);			}			finally 			{				restoreContextStack();			}			needCommit = false;		} 	}    /**     * 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; the close method provides this     * immediate release.      *     * <P><B>Note:</B> A Connection is automatically closed when it is     * garbage collected. Certain fatal errors also result in a closed     * Connection.     *     * @exception SQLException if a database-access error occurs.     */    public void close() throws SQLException {		// JDK 1.4 javadoc indicates close on a closed connection is a no-op		if (isClosed())		   	return;		if (rootConnection == this)		{			/* Throw error to match DB2/JDBC if a tran is pending in non-autocommit mode */			if (!autoCommit && !transactionIsIdle()) {				throw newSQLException(SQLState.LANG_INVALID_TRANSACTION_STATE);			}			close(exceptionClose);		}		else			setInactive(); // nested connection	}	// This inner close takes the exception and calls 	// the context manager to make the connection close.	// The exception must be a session severity exception.	//	// NOTE: This method is not part of JDBC specs.	//    private void close(Exception e) throws SQLException {				synchronized(getConnectionSynchronization())		{			if (rootConnection == this)			{				/*				 * If it isn't active, it's already been closed.				 */				if (active) {					setupContextStack();					try {						tr.rollback();						// Let go of lcc reference so it can be GC'ed after						// cleanupOnError, the tr will stay around until the						// rootConnection itself is GC'ed, which is dependent						// on how long the client program wants to hold on to						// the Connection object.						tr.clearLcc(); 						tr.cleanupOnError(e);					} catch (Throwable t) {						throw handleException(t);					} finally {						restoreContextStack();					}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -