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

📄 embedpreparedstatement.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*   Derby - Class org.apache.derby.impl.jdbc.EmbedPreparedStatement   Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable.   Licensed under the Apache License, Version 2.0 (the "License");   you may not use this file except in compliance with the License.   You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License. */package org.apache.derby.impl.jdbc;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.types.VariableSizeDataValue;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.PreparedStatement;import org.apache.derby.iapi.sql.execute.ExecPreparedStatement;import org.apache.derby.iapi.sql.ResultSet;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.sql.ParameterValueSet;import org.apache.derby.iapi.sql.ResultDescription;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.services.io.LimitReader;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.reference.JDBC30Translation;import org.apache.derby.iapi.reference.JDBC20Translation;import java.util.Calendar;import java.util.Vector;/* We would import these, but have name-overlapimport java.sql.PreparedStatement;import java.sql.ResultSet;*/import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.sql.Date;import java.sql.Time;import java.sql.Timestamp;import java.sql.Clob;import java.sql.Blob;import java.io.InputStream;import java.io.DataInputStream;import java.io.IOException;import java.io.EOFException;import java.io.Reader;import java.sql.Types;/** * * EmbedPreparedStatement is a local JDBC statement.  <P><B>Supports</B>   <UL>   <LI> JSR169   </UL> */public abstract class EmbedPreparedStatement	extends EmbedStatement	implements java.sql.PreparedStatement{	//Moving jdbc2.0 batch related code in this class because callableStatement in jdbc 20 needs	//this code too and it doesn't derive from prepared statement in jdbc 20 in our implementation.	protected ResultSetMetaData rMetaData;	//bug 4579-If the prepared statement was revalidated after doing getMetaData(), we	//should get the metadata info again on next getMetaData(). We store the generated	//class name in following variable during getMetaData() call. If it differs from the	//current generated class name, then that indicates a refetch of metadata is required.	private String			gcDuringGetMetaData;	protected PreparedStatement	preparedStatement;	private Activation			activation;	/*		Constructor assumes caller will setup context stack		and restore it.	 */	public EmbedPreparedStatement (EmbedConnection conn, String sql, boolean forMetaData,									  int resultSetType, int resultSetConcurrency,									  int resultSetHoldability,									  int autoGeneratedKeys,									  int[] columnIndexes,									  String[] columnNames)		throws SQLException {		super(conn, forMetaData, resultSetType, resultSetConcurrency, resultSetHoldability);		// if the sql string is null, raise an error		if (sql == null)  			throw newSQLException(SQLState.NULL_SQL_TEXT);			// set up the SQLText in EmbedStatement			SQLText = sql;			try {			    preparedStatement = lcc.prepareInternalStatement(sql);                addWarning(preparedStatement.getCompileTimeWarnings());			    activation = preparedStatement.getActivation(lcc, resultSetType == JDBC20Translation.TYPE_SCROLL_INSENSITIVE);				checkRequiresCallableStatement(activation);			//bug 4838 - save the auto-generated key information in activation. keeping this			//information in lcc will not work work as it can be tampered by a nested trasaction  				if (autoGeneratedKeys == JDBC30Translation.RETURN_GENERATED_KEYS)  					activation.setAutoGeneratedKeysResultsetInfo(columnIndexes, columnNames);			} catch (Throwable t) {		    throw handleException(t);			}	}	/**		JDBC states that a Statement is closed when garbage collected.		@exception Throwable Allows any exception to be thrown during finalize	*/	protected void finalize() throws Throwable {		super.finalize();		/*		** We mark the activation as not being used and	 	** that is it.  We rely on the connection to sweep		** through the activations to find the ones that		** aren't in use, and to close them.  We cannot	 	** do a activation.close() here because there are		** synchronized methods under close that cannot		** be called during finalization.		*/		if (activation != null) 		{			activation.markUnused();		}	}	/*	 * Statement interface		we override all Statement methods that take a SQL		string as they must thrown an exception in a PreparedStatement.		See the JDBC 3.0 spec.	 */	public final boolean execute(String sql) throws SQLException {		throw newSQLException(SQLState.NOT_FOR_PREPARED_STATEMENT, "execute(String)");	}	public final boolean execute(String sql, int autoGenKeys) throws SQLException {		throw newSQLException(SQLState.NOT_FOR_PREPARED_STATEMENT, "execute(String, int)");	}	public final boolean execute(String sql, int[] columnIndexes) throws SQLException {		throw newSQLException(SQLState.NOT_FOR_PREPARED_STATEMENT, "execute(String, int[])");	}	public final boolean execute(String sql, String[] columnNames) throws SQLException {		throw newSQLException(SQLState.NOT_FOR_PREPARED_STATEMENT, "execute(String, String[])");	}	public final java.sql.ResultSet executeQuery(String sql) throws SQLException {		throw newSQLException(SQLState.NOT_FOR_PREPARED_STATEMENT, "executeQuery(String)");	}	public final int executeUpdate(String sql) throws SQLException {		throw newSQLException(SQLState.NOT_FOR_PREPARED_STATEMENT, "executeUpdate(String)");	}	public final int executeUpdate(String sql, int autoGenKeys) throws SQLException {		throw newSQLException(SQLState.NOT_FOR_PREPARED_STATEMENT, "executeUpdate(String, int)");	}	public final int executeUpdate(String sql, int[] columnIndexes) throws SQLException {		throw newSQLException(SQLState.NOT_FOR_PREPARED_STATEMENT, "executeUpdate(String, int[])");	}	public final int executeUpdate(String sql, String[] columnNames) throws SQLException {		throw newSQLException(SQLState.NOT_FOR_PREPARED_STATEMENT, "executeUpdate(String, String[])");	}	public final void addBatch(String sql) throws SQLException {		throw newSQLException(SQLState.NOT_FOR_PREPARED_STATEMENT, "addBatch(String)");	}	/**		Additional close to close our activation.		@exception SQLException	thrown on failure	 */	protected void closeActions() throws SQLException {		//we release the resource for preparedStatement		preparedStatement = null;		try{			setupContextStack();		} catch (SQLException se) {			//we may have already committed the transaction in which case			//setupContextStack will fail, the close should just return			return;		}		try		{		    activation.close();			activation = null;		} catch (Throwable t)		{			throw handleException(t);		} finally {		    restoreContextStack();		}	}		/*	 * PreparedStatement interface; we have inherited from	 * EmbedStatement to get the Statement interface for	 * EmbedPreparedStatement (needed by PreparedStatement)	 * These are the JDBC interface comments, so we know	 * what to do.	 */	/**     * A prepared SQL query is executed and its ResultSet is returned.     *     * @return a ResultSet that contains the data produced by the     * query; never null	 * @exception SQLException thrown on failure.     */	public final java.sql.ResultSet executeQuery() throws SQLException {		executeStatement(activation, true, false);		if (SanityManager.DEBUG) {			if (results == null)				SanityManager.THROWASSERT("no results returned on executeQuery()");		}		return results;	}    /**     * Execute a SQL INSERT, UPDATE or DELETE statement. In addition,     * SQL statements that return nothing such as SQL DDL statements     * can be executed.     *     * @return either the row count for INSERT, UPDATE or DELETE; or 0     * for SQL statements that return nothing	 * @exception SQLException thrown on failure.     */	public final int executeUpdate() throws SQLException {		executeStatement(activation, false, true);		return updateCount;	}    /**     * Set a parameter to SQL NULL.     *     * <P><B>Note:</B> You must specify the parameter's SQL type.     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param sqlType SQL type code defined by java.sql.Types	 * @exception SQLException thrown on failure.     */    public void setNull(int parameterIndex, int sqlType) throws SQLException {		checkStatus();		int jdbcTypeId = getParameterJDBCType(parameterIndex);				if (!DataTypeDescriptor.isJDBCTypeEquivalent(jdbcTypeId, sqlType)) {			throw dataTypeConversion(parameterIndex, Util.typeName(sqlType));		}				try {			/* JDBC is one-based, DBMS is zero-based */			getParms().getParameterForSet(parameterIndex - 1).setToNull();		} catch (StandardException t) {			throw EmbedResultSet.noStateChangeException(t);		}	}    /**     * Set a parameter to a Java boolean value.  According to the JDBC API spec,	 * the driver converts this to a SQL BIT value when it sends it to the	 * database. But we don't have to do this, since the database engine	 * supports a boolean type.     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value	 * @exception SQLException thrown on failure.     */    public void setBoolean(int parameterIndex, boolean x) throws SQLException {				checkStatus();		try {			/* JDBC is one-based, DBMS is zero-based */			getParms().getParameterForSet(parameterIndex - 1).setValue(x);		} catch (StandardException t) {			throw EmbedResultSet.noStateChangeException(t);		}	}    /**     * Set a parameter to a Java byte value.  The driver converts this     * to a SQL TINYINT value when it sends it to the database.     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value	 * @exception SQLException thrown on failure.     */    public void setByte(int parameterIndex, byte x) throws SQLException {		checkStatus();		try {			getParms().getParameterForSet(parameterIndex - 1).setValue(x);		} catch (Throwable t) {			throw EmbedResultSet.noStateChangeException(t);		}	}    /**     * Set a parameter to a Java short value.  The driver converts this     * to a SQL SMALLINT value when it sends it to the database.     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value	 * @exception SQLException thrown on failure.     */    public void setShort(int parameterIndex, short x) throws SQLException {		checkStatus();		try {			/* JDBC is one-based, DBMS is zero-based */			getParms().getParameterForSet(parameterIndex - 1).setValue(x);		} catch (Throwable t) {			throw EmbedResultSet.noStateChangeException(t);		}	}    /**     * Set a parameter to a Java int value.  The driver converts this     * to a SQL INTEGER value when it sends it to the database.     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value	 * @exception SQLException thrown on failure.     */    public void setInt(int parameterIndex, int x) throws SQLException {		checkStatus();		try {			/* JDBC is one-based, DBMS is zero-based */			getParms().getParameterForSet(parameterIndex - 1).setValue(x);		} catch (Throwable t) {			throw EmbedResultSet.noStateChangeException(t);		}	}    /**     * Set a parameter to a Java long value.  The driver converts this     * to a SQL BIGINT value when it sends it to the database.     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value	 * @exception SQLException thrown on failure.     */    public void setLong(int parameterIndex, long x) throws SQLException {		checkStatus();		try {			/* JDBC is one-based, DBMS is zero-based */			getParms().getParameterForSet(parameterIndex - 1).setValue(x);		} catch (Throwable t) {			throw EmbedResultSet.noStateChangeException(t);		}	}    /**     * Set a parameter to a Java float value.  The driver converts this     * to a SQL FLOAT value when it sends it to the database.     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value	 * @exception SQLException thrown on failure.     */    public void setFloat(int parameterIndex, float x) throws SQLException {		checkStatus();		try {			/* JDBC is one-based, DBMS is zero-based */			getParms().getParameterForSet(parameterIndex - 1).setValue(x);		} catch (Throwable t) {			throw EmbedResultSet.noStateChangeException(t);		}	}    /**     * Set a parameter to a Java double value.  The driver converts this     * to a SQL DOUBLE value when it sends it to the database.     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value	 * @exception SQLException thrown on failure.     */    public void setDouble(int parameterIndex, double x) throws SQLException {		checkStatus();		try {			/* JDBC is one-based, DBMS is zero-based */			getParms().getParameterForSet(parameterIndex - 1).setValue(x);		} catch (Throwable t) {			throw EmbedResultSet.noStateChangeException(t);		}	}    /**     * Set a parameter to a Java String value.  The driver converts this     * to a SQL VARCHAR or LONGVARCHAR value (depending on the arguments     * size relative to the driver's limits on VARCHARs) when it sends     * it to the database.     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value	 * @exception SQLException thrown on failure.

⌨️ 快捷键说明

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