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

📄 embedpreparedstatement.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 * @exception SQLException thrown on failure.      */    public final void setObject(int parameterIndex, Object x, int targetSqlType)		throws SQLException {		setObject(parameterIndex, x, targetSqlType, 0);	}    /**     * <p>Set the value of a parameter using an object; use the     * java.lang equivalent objects for integral values.     *     * <p>The JDBC specification specifies a standard mapping from     * Java Object types to SQL types.  The given argument java object     * will be converted to the corresponding SQL type before being     * sent to the database.     *     * <p>Note that this method may be used to pass datatabase     * specific abstract data types, by using a Driver specific Java     * type.     *     * @param parameterIndex The first parameter is 1, the second is 2, ...     * @param x The object containing the input parameter value 	 * @exception SQLException thrown on failure.     */    public final void setObject(int parameterIndex, Object x) throws SQLException {		checkStatus();			int colType = getParameterJDBCType(parameterIndex);		// JDBC Tutorial and Reference books states in the PreparedStatement		// overview, that passing a untyped null into setObject() is not allowed.		// JCC disallows this, basically SQL can not handle a untyped NULL.		// Section 25.1.6 (Third edition), 24.1.5 (Second Edition)		if (x == null) {			//setNull(parameterIndex, colType);			//return;			throw dataTypeConversion(parameterIndex, "null");		}				if (colType == org.apache.derby.iapi.reference.JDBC20Translation.SQL_TYPES_JAVA_OBJECT) {			try {				/* JDBC is one-based, DBMS is zero-based */				getParms().setParameterAsObject(parameterIndex - 1, x);				return;			} catch (Throwable t) {				throw EmbedResultSet.noStateChangeException(t);			}		}		// Need to do instanceof checks here so that the behaviour		// for these calls is consistent with the matching setXXX() value.		// These are the supported setObject conversions from JDBC 3.0 table B5		if (x instanceof String) {			setString(parameterIndex, (String) x);			return;		}		if (x instanceof Boolean) {			setBoolean(parameterIndex, ((Boolean) x).booleanValue());			return;		}		if (x instanceof Integer) {			setInt(parameterIndex, ((Integer) x).intValue());			return;		}		if (x instanceof Long) {			setLong(parameterIndex, ((Long) x).longValue());			return;		}		if (x instanceof Float) {			setFloat(parameterIndex, ((Float) x).floatValue());			return;		}		if (x instanceof Double) {			setDouble(parameterIndex, ((Double) x).doubleValue());			return;		}		if (x instanceof byte[]) {			setBytes(parameterIndex, (byte[]) x);			return;		}		if (x instanceof Date) {			setDate(parameterIndex, (Date) x);			return;		}		if (x instanceof Time) {			setTime(parameterIndex, (Time) x);			return;		}		if (x instanceof Timestamp) {			setTimestamp(parameterIndex, (Timestamp) x);			return;		}		if (x instanceof Blob) {			setBlob(parameterIndex, (Blob) x);			return;		}		if (x instanceof Clob) {			setClob(parameterIndex, (Clob) x);			return;		}		if (setObjectConvert(parameterIndex, x))			return;				throw dataTypeConversion(parameterIndex, x.getClass().getName());	}	/**		Allow explict setObject conversions by sub-classes for classes		not supported by this variant. E.g. BigDecimal		This top-level implementation always returns false.		@return true if the object was set successfully, false if no valid		conversion exists.		@exception SQLException value could not be set.	*/	boolean setObjectConvert(int parameterIndex, Object x) throws SQLException	{		return false;	}    /**     * @see java.sql.Statement#execute	 * @exception SQLException thrown on failure.     */    public final boolean execute() throws SQLException {		return executeStatement(activation, false, false);	}    /**     * Set a parameter to a java.sql.Date value.  The driver converts this     * to a SQL DATE 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 Feature not implemented for now.     */    public final void setDate(int parameterIndex, java.sql.Date x, Calendar cal)	    throws SQLException 	{		checkStatus();		try {			/* JDBC is one-based, DBMS is zero-based */			getParms().getParameterForSet(parameterIndex - 1).setValue(x, cal);		} catch (Throwable t) {			throw EmbedResultSet.noStateChangeException(t);		}	}    /**     * Set a parameter to a java.sql.Time value.  The driver converts this     * to a SQL TIME 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 Feature not implemented for now.     */    public final void setTime(int parameterIndex, java.sql.Time x, Calendar cal)	    throws SQLException 	{		checkStatus();		try {			/* JDBC is one-based, DBMS is zero-based */			getParms().getParameterForSet(parameterIndex - 1).setValue(x, cal);		} catch (Throwable t) {			throw EmbedResultSet.noStateChangeException(t);		}	}    /**     * Set a parameter to a java.sql.Timestamp value.  The driver     * converts this to a SQL TIMESTAMP 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 Feature not implemented for now.     */    public final void setTimestamp(int parameterIndex, java.sql.Timestamp x, Calendar cal)	    throws SQLException 	{		checkStatus();		try {			/* JDBC is one-based, DBMS is zero-based */			getParms().getParameterForSet(parameterIndex - 1).setValue(x, cal);		} catch (StandardException t) {			throw EmbedResultSet.noStateChangeException(t);		}	}    /**     * JDBC 2.0     *     * Set a BLOB parameter.     *     * @param i the first parameter is 1, the second is 2, ...     * @param x an object representing a BLOB     */    public void setBlob (int i, Blob x)        throws SQLException    {        int colType;        synchronized (getConnectionSynchronization())        {            colType = getParameterJDBCType(i);        }		// DB2: only allow setBlob on a BLOB column.		if (colType != Types.BLOB)            throw dataTypeConversion(i, "java.sql.Blob");		if (x == null)			setNull(i, Types.BLOB);		else			setBinaryStreamInternal(i, x.getBinaryStream(), -1);	}    /**     * JDBC 2.0     *     * Set a CLOB parameter.     *     * @param i the first parameter is 1, the second is 2, ...     * @param x an object representing a CLOB     */    public void setClob (int i, Clob x)        throws SQLException    {        int colType;        synchronized (getConnectionSynchronization())        {            colType = getParameterJDBCType(i);        }		// DB2, only allow setClob on a CLOB column.		if (colType != Types.CLOB)            throw dataTypeConversion(i, "java.sql.Clob");		if (x == null)			setNull(i, Types.CLOB);		else			setCharacterStreamInternal(i, x.getCharacterStream(), -1);	}	/**	 * Get the ParameterValueSet from the activation	 *	 *	 * @return	The ParameterValueSet for the activation	 *	 */	public final ParameterValueSet getParms() {		return activation.getParameterValueSet();	}	/**		Check the parameterINdex is in range and return the		array of type descriptors.		@exception SQLException parameter is out of range	*/	protected final DataTypeDescriptor[] getTypes(int parameterIndex)		throws SQLException {		DataTypeDescriptor[] types = preparedStatement.getParameterTypes();		if (types == null) {			throw newSQLException(SQLState.NO_INPUT_PARAMETERS);		}		/* Check that the parameterIndex is in range. */		if (parameterIndex < 1 ||				parameterIndex > types.length) {			/* This message matches the one used by the DBMS */			throw newSQLException(SQLState.LANG_INVALID_PARAM_POSITION,             new Integer(parameterIndex), new Integer(types.length));		}		return types;	}	/**		Get the target JDBC type for a parameter. Will throw exceptions		if the parameter index is out of range		@exception SQLException parameter is out of range	*/	protected int getParameterJDBCType(int parameterIndex)		throws SQLException {		DataTypeDescriptor[] types = getTypes(parameterIndex);		int type = types[parameterIndex -1] == null ? 			Types.OTHER :			types[parameterIndex - 1].getTypeId().getJDBCTypeId();		if (SanityManager.DEBUG) {			//int pmType = getEmbedParameterSetMetaData().getParameterType(parameterIndex);			//if (type != pmType) {				//SanityManager.THROWASSERT("MISMATCH PARAMETER META DATA param " + parameterIndex + " types " + type + " != " + pmType + "\n" + SQLText);			//}		}		return type;	}    /**     * Set the scale of a parameter.     *     * @param parameterIndex The first parameter is 1, the second is 2, ...     * @param scale	The scale	 * @exception SQLException thrown on failure.     */    private void setScale(int parameterIndex, int scale)		throws SQLException 	{		checkStatus();		if (scale < 0)			throw newSQLException(SQLState.BAD_SCALE_VALUE, new Integer(scale));				try {			ParameterValueSet pvs = getParms();			/* JDBC is one-based, DBMS is zero-based */			DataValueDescriptor value = pvs.getParameter(parameterIndex - 1);			int origvaluelen = value.getLength();			((VariableSizeDataValue)						value).setWidth(VariableSizeDataValue.IGNORE_PRECISION, 							scale, 							false);			if (value.getLength() < origvaluelen)			{				activation.addWarning(StandardException.newWarning(SQLState.LANG_VALUE_TRUNCATED, value.getString()));			}		} catch (StandardException t) {			throw EmbedResultSet.noStateChangeException(t);		}	}	/**    * Immitate the function in JDBC 3.0    *    * Retrieves the number, types and properties of this PreparedStatement    * object's parameters.    *    * @return a EmbedParameterSetMetaData object that contains information about the    * number, types and properties of this PreparedStatement object's parameters.    * @exception SQLException if a database access error occurs	*/	public EmbedParameterSetMetaData getEmbedParameterSetMetaData()    	throws SQLException	{	  checkExecStatus();	  return new EmbedParameterSetMetaData(				getParms(), preparedStatement.getParameterTypes());	}	/**    * JDBC 3.0    *    * Sets the designated parameter to the given java.net.URL value. The driver    * converts this to an SQL DATALINK value when it sends it to the database.    *    * @param parameterIndex - the first parameter is 1, the second is 2, ...    * @param x - the java.net.URL object to be set    * @exception SQLException Feature not implemented for now.	*/	public final void setURL(int parameterIndex, java.net.URL x)    throws SQLException	{		throw Util.notImplemented();	}	//	// methods to be overridden in subimplementations	// that want to stay within their subimplementation.	//	protected EmbedResultSetMetaData newEmbedResultSetMetaData(ResultDescription resultDesc) {		return new EmbedResultSetMetaData(resultDesc.getColumnInfo());	}	public String toString() {		if (activation != null)			return activation.getPreparedStatement().getObjectName();		return super.toString();	}	/*	**	*/	public void transferParameters(EmbedPreparedStatement newStatement) throws SQLException {		try {			newStatement.activation.setParameters(getParms(), preparedStatement.getParameterTypes());		} catch (StandardException se) {			throw EmbedResultSet.noStateChangeException(se);		}	}	boolean executeStatement(Activation a,                     boolean executeQuery, boolean executeUpdate)                     throws SQLException {		checkExecStatus();		checkIfInMiddleOfBatch();		clearResultSets();		return super.executeStatement(a, executeQuery, executeUpdate);	}	final SQLException dataTypeConversion(int column, String sourceType)		throws SQLException {		SQLException se = newSQLException(SQLState.LANG_DATA_TYPE_GET_MISMATCH, getEmbedParameterSetMetaData().getParameterTypeName(column),			sourceType);		return se;	}}

⌨️ 快捷键说明

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