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

📄 embedpreparedstatement.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     */    public void setString(int parameterIndex, String 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 array of bytes.  The driver converts     * this to a SQL VARBINARY or LONGVARBINARY (depending on the     * argument's size relative to the driver's limits on VARBINARYs)     * 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 setBytes(int parameterIndex, byte 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.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 thrown on failure.     */    public void setDate(int parameterIndex, Date x) throws SQLException {        setDate( parameterIndex, x, (Calendar) null);	}    /**     * 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 thrown on failure.     */    public void setTime(int parameterIndex, Time x) throws SQLException {        setTime( parameterIndex, x, (Calendar) null);	}    /**     * 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 thrown on failure.     */    public void setTimestamp(int parameterIndex, Timestamp x)	    throws SQLException {        setTimestamp( parameterIndex, x, (Calendar) null);	}    /**	 * We do this inefficiently and read it all in here. The target type	 * is assumed to be a String.     *      * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the java input stream which contains the ASCII parameter value     * @param length the number of bytes in the stream 	 * @exception SQLException thrown on failure.     */    public final void setAsciiStream(int parameterIndex, InputStream x, int length)	    throws SQLException {		checkStatus();		int jdbcTypeId = getParameterJDBCType(parameterIndex);				switch (jdbcTypeId) {		case Types.CHAR:		case Types.VARCHAR:		case Types.LONGVARCHAR:		case Types.CLOB:			break;		default:			throw dataTypeConversion(parameterIndex, "java.io.InputStream(ASCII)");		}		java.io.Reader r = null;		if (x != null)		{			// Use ISO-8859-1 and not US-ASCII as JDBC seems to define			// ASCII as 8 bits. US-ASCII is 7.			try {				r = new java.io.InputStreamReader(x, "ISO-8859-1");			} catch (java.io.UnsupportedEncodingException uee) {				throw new SQLException(uee.getMessage());			}		}		setCharacterStream(parameterIndex, r, length);	}    /**		Deprecated in JDBC 3.0     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the java input stream which contains the     * UNICODE parameter value     * @param length the number of bytes in the stream	 * @exception SQLException thrown on failure.     */    public void setUnicodeStream(int parameterIndex, InputStream x, int length)	    throws SQLException	{		throw Util.notImplemented("setUnicodeStream");	}    /**     * JDBC 2.0     *     * When a very large UNICODE value is input to a LONGVARCHAR     * parameter, it may be more practical to send it via a     * java.io.Reader. JDBC will read the data from the stream     * as needed, until it reaches end-of-file.  The JDBC driver will     * do any necessary conversion from UNICODE to the database char format.     *     * <P><B>Note:</B> This stream object can either be a standard     * Java stream object or your own subclass that implements the     * standard interface.     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the java reader which contains the UNICODE data     * @param length the number of characters in the stream     * @exception SQLException if a database-access error occurs.     */    public final void setCharacterStream(int parameterIndex,       			  java.io.Reader reader,			  int length) throws SQLException	{		int jdbcTypeId = getParameterJDBCType(parameterIndex);		switch (jdbcTypeId) {		case Types.CHAR:		case Types.VARCHAR:		case Types.LONGVARCHAR:		case Types.CLOB:			break;		default:			throw dataTypeConversion(parameterIndex, "java.io.Reader");		}		if (length < 0) //we are doing the check here and not in setCharacterStreamInternal becuase setClob needs to pass -1 for length.			throw newSQLException(SQLState.NEGATIVE_STREAM_LENGTH);		if (reader == null)		{			setNull(parameterIndex, jdbcTypeId);			return;		}		setCharacterStreamInternal(parameterIndex, reader, length);	}    protected void setCharacterStreamInternal(int parameterIndex,						Reader reader, int length)	    throws SQLException	{		checkStatus();		int jdbcTypeId = getParameterJDBCType(parameterIndex);		try {			ParameterValueSet pvs = getParms();			LimitReader limitIn = new LimitReader(reader);			if (length != -1)				limitIn.setLimit(length);			ReaderToUTF8Stream utfIn = new ReaderToUTF8Stream(limitIn);			/* JDBC is one-based, DBMS is zero-based */			pvs.getParameterForSet(parameterIndex - 1).setValue(utfIn, length);		} catch (StandardException t) {			throw EmbedResultSet.noStateChangeException(t);		}	}    /**     *      * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the java input stream which contains the binary parameter value     * @param length the number of bytes in the stream 	 * @exception SQLException thrown on failure.     */    public final void setBinaryStream(int parameterIndex, InputStream x, int length)	    throws SQLException		{		int jdbcTypeId = getParameterJDBCType(parameterIndex);		switch (jdbcTypeId) {		case Types.BINARY:		case Types.VARBINARY:		case Types.LONGVARBINARY:		case Types.BLOB:			break;		default:			throw dataTypeConversion(parameterIndex, "java.io.InputStream");		}		if (length < 0) //we are doing the check here and not in setBinaryStreamInternal becuase setBlob needs to pass -1 for length.			throw newSQLException(SQLState.NEGATIVE_STREAM_LENGTH);    	setBinaryStreamInternal(parameterIndex, x, length);	}    protected void setBinaryStreamInternal(int parameterIndex, InputStream x,				int length)	    throws SQLException	{		checkStatus();		int jdbcTypeId = getParameterJDBCType(parameterIndex);		if (x == null) {			setNull(parameterIndex, jdbcTypeId);           	return;		}		try {			getParms().getParameterForSet(parameterIndex - 1).setValue(new RawToBinaryFormatStream(x, length), length);		} catch (StandardException t) {			throw EmbedResultSet.noStateChangeException(t);		}	}	/////////////////////////////////////////////////////////////////////////	//	//	JDBC 2.0	-	New public methods	//	/////////////////////////////////////////////////////////////////////////    /**     * JDBC 2.0     *     * Set null for user-named types and REF type parameters     *      * @exception SQLException if a database-access error occurs.     */	public void setNull(int paramIndex,						int sqlType,						String typeName)		 throws SQLException	{		throw Util.notImplemented("setNull");	}    /**     * JDBC 2.0     *     * Add a set of parameters to the batch.     *      * @exception SQLException if a database-access error occurs.     */    public void addBatch() throws SQLException {	  checkStatus();	  // need to synchronized to ensure that two threads	  // don't both create a Vector at the same time. This	  // would lead to one of the set of parameters being thrown	  // away  	  synchronized (getConnectionSynchronization()) {  			if (batchStatements == null)  				batchStatements = new Vector();          //get a clone of the parameterValueSet and save it in the vector          //which will be used later on at the time of batch execution.          //This way we will get a copy of the current statement's parameter          //values rather than a pointer to the statement's parameter value          //set which will change with every new statement in the batch.          batchStatements.addElement(getParms().getClone());          clearParameters();  	  }    }	boolean executeBatchElement(Object batchElement) throws SQLException, StandardException {				ParameterValueSet temp = (ParameterValueSet) batchElement;		int numberOfParameters = temp.getParameterCount();		for (int j=0; j<numberOfParameters; j++) {			temp.getParameter(j).setInto(this, j + 1);		}		return super.executeStatement(activation, false, true);	}     /**     * <P>In general, parameter values remain in force for repeated use of a     * Statement. Setting a parameter value automatically clears its     * previous value.  However, in some cases it is useful to immediately     * release the resources used by the current parameter values; this can     * be done by calling clearParameters.	 * @exception SQLException thrown on failure.     */    public void clearParameters() throws SQLException {		checkStatus();		ParameterValueSet pvs = getParms();		if (pvs != null)			pvs.clearParameters();	}    /**	 * JDBC 2.0	 *     * The number, types and properties of a ResultSet's columns     * are provided by the getMetaData method.     *     * @return the description of a ResultSet's columns     * @exception SQLException Feature not implemented for now.     */    public java.sql.ResultSetMetaData getMetaData() throws SQLException	{		checkExecStatus();		synchronized (getConnectionSynchronization())		{			//reason for casting is getActivationClass is not available on PreparedStatement			ExecPreparedStatement execp = (ExecPreparedStatement)preparedStatement;			setupContextStack(); // make sure there's context			try {				//bug 4579 - if the statement is invalid, regenerate the metadata info				if (preparedStatement.isValid() == false)				{					//need to revalidate the statement here, otherwise getResultDescription would					//still have info from previous valid statement					preparedStatement.rePrepare(lcc);					rMetaData = null;				}				//bug 4579 - gcDuringGetMetaData will be null if this is the first time				//getMetaData call is made.				//Second check - if the statement was revalidated since last getMetaData call,				//then gcDuringGetMetaData wouldn't match with current generated class name				if (gcDuringGetMetaData == null || gcDuringGetMetaData.equals(execp.getActivationClass().getName()) == false)				{					rMetaData = null;					gcDuringGetMetaData = execp.getActivationClass().getName();				}				if (rMetaData == null)				{					ResultDescription resd = preparedStatement.getResultDescription();					if (resd != null)					{						// Internally, the result description has information						// which is used for insert, update and delete statements						// Externally, we decided that statements which don't						// produce result sets such as insert, update and delete						// should not return ResultSetMetaData.  This is enforced						// here						String statementType = resd.getStatementType();						if (statementType.equals("INSERT") ||								statementType.equals("UPDATE") ||								statementType.equals("DELETE"))							rMetaData = null;						else				    		rMetaData = newEmbedResultSetMetaData(resd);					}				}			} catch (Throwable t) {				throw handleException(t);			}	finally {				restoreContextStack();			}		}		return rMetaData;	}    //----------------------------------------------------------------------    // Advanced features:    /**	 * The interface says that the type of the Object parameter must	 * be compatible with the type of the targetSqlType. We check that,	 * and if it flies, we expect the underlying engine to do the	 * required conversion once we pass in the value using its type.	 * So, an Integer converting to a CHAR is done via setInteger()	 * support on the underlying CHAR type.     *     * <p>If x is null, it won't tell us its type, so we pass it on to setNull     *     * @param parameterIndex The first parameter is 1, the second is 2, ...     * @param x The object containing the input parameter value     * @param targetSqlType The SQL type (as defined in java.sql.Types) to be      * sent to the database. The scale argument may further qualify this type.     * @param scale For java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types     *          this is the number of digits after the decimal.  For all other     *          types this value will be ignored,	 * @exception SQLException thrown on failure.     */    public final void setObject(int parameterIndex, Object x, int targetSqlType, int scale)            throws SQLException {		if (x == null) {			setNull(parameterIndex, targetSqlType);			return;		}		int paramJDBCType = getParameterJDBCType(parameterIndex);		if (paramJDBCType != java.sql.Types.JAVA_OBJECT) {			if (!DataTypeDescriptor.isJDBCTypeEquivalent(paramJDBCType, targetSqlType)) {				throw dataTypeConversion(parameterIndex, Util.typeName(targetSqlType));			}		}		setObject(parameterIndex, x);						/*		* If the parameter type is DECIMAL or NUMERIC, then		* we need to set the correct scale  or set it 		* to the default which is zero for setObject.		*/		if ((paramJDBCType == Types.DECIMAL) || 			 (paramJDBCType == Types.NUMERIC))		{			setScale(parameterIndex, scale);		}		}    /**      * This method is like setObject above, but assumes a scale of zero.

⌨️ 快捷键说明

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