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

📄 callablestatement.java

📁 mysql5.0 JDBC 驱动 放在glassfish或者tomcat的lib文件夹下就可以了
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		paramDescriptor.desiredJdbcType = sqlType;	}	/**	 * @see java.sql.CallableStatement#registerOutParameter(int, int, int)	 */	public void registerOutParameter(int parameterIndex, int sqlType, int scale)			throws SQLException {		registerOutParameter(parameterIndex, sqlType);	}	/**	 * @see java.sql.CallableStatement#registerOutParameter(int, int,	 *      java.lang.String)	 */	public void registerOutParameter(int parameterIndex, int sqlType,			String typeName) throws SQLException {		checkIsOutputParam(parameterIndex);	}	/**	 * @see java.sql.CallableStatement#registerOutParameter(java.lang.String,	 *      int)	 */	public synchronized void registerOutParameter(String parameterName,			int sqlType) throws SQLException {		registerOutParameter(getNamedParamIndex(parameterName, true), sqlType);	}	/**	 * @see java.sql.CallableStatement#registerOutParameter(java.lang.String,	 *      int, int)	 */	public void registerOutParameter(String parameterName, int sqlType,			int scale) throws SQLException {		registerOutParameter(getNamedParamIndex(parameterName, true), sqlType);	}	/**	 * @see java.sql.CallableStatement#registerOutParameter(java.lang.String,	 *      int, java.lang.String)	 */	public void registerOutParameter(String parameterName, int sqlType,			String typeName) throws SQLException {		registerOutParameter(getNamedParamIndex(parameterName, true), sqlType,				typeName);	}	/**	 * Issues a second query to retrieve all output parameters.	 * 	 * @throws SQLException	 *             if an error occurs.	 */	private void retrieveOutParams() throws SQLException {		int numParameters = this.paramInfo.numberOfParameters();		this.parameterIndexToRsIndex = new int[numParameters];		for (int i = 0; i < numParameters; i++) {			this.parameterIndexToRsIndex[i] = NOT_OUTPUT_PARAMETER_INDICATOR;		}		int localParamIndex = 0;		if (numParameters > 0) {			StringBuffer outParameterQuery = new StringBuffer("SELECT "); //$NON-NLS-1$			boolean firstParam = true;			boolean hadOutputParams = false;			for (Iterator paramIter = this.paramInfo.iterator(); paramIter					.hasNext();) {				CallableStatementParam retrParamInfo = (CallableStatementParam) paramIter						.next();				if (retrParamInfo.isOut) {					hadOutputParams = true;					this.parameterIndexToRsIndex[retrParamInfo.index] = localParamIndex++;					String outParameterName = mangleParameterName(retrParamInfo.paramName);					if (!firstParam) {						outParameterQuery.append(","); //$NON-NLS-1$					} else {						firstParam = false;					}					if (!outParameterName.startsWith("@")) { //$NON-NLS-1$						outParameterQuery.append('@');					}					outParameterQuery.append(outParameterName);				}			}			if (hadOutputParams) {				// We can't use 'ourself' to execute this query, or any				// pending result sets would be overwritten				java.sql.Statement outParameterStmt = null;				java.sql.ResultSet outParamRs = null;				try {					outParameterStmt = this.connection.createStatement();					outParamRs = outParameterStmt							.executeQuery(outParameterQuery.toString());					this.outputParameterResults = ((com.mysql.jdbc.ResultSetInternalMethods) outParamRs)							.copy();					if (!this.outputParameterResults.next()) {						this.outputParameterResults.close();						this.outputParameterResults = null;					}				} finally {					if (outParameterStmt != null) {						outParameterStmt.close();					}				}			} else {				this.outputParameterResults = null;			}		} else {			this.outputParameterResults = null;		}	}	/**	 * @see java.sql.CallableStatement#setAsciiStream(java.lang.String,	 *      java.io.InputStream, int)	 */	public void setAsciiStream(String parameterName, InputStream x, int length)			throws SQLException {		setAsciiStream(getNamedParamIndex(parameterName, false), x, length);	}	/**	 * @see java.sql.CallableStatement#setBigDecimal(java.lang.String,	 *      java.math.BigDecimal)	 */	public void setBigDecimal(String parameterName, BigDecimal x)			throws SQLException {		setBigDecimal(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setBinaryStream(java.lang.String,	 *      java.io.InputStream, int)	 */	public void setBinaryStream(String parameterName, InputStream x, int length)			throws SQLException {		setBinaryStream(getNamedParamIndex(parameterName, false), x, length);	}	/**	 * @see java.sql.CallableStatement#setBoolean(java.lang.String, boolean)	 */	public void setBoolean(String parameterName, boolean x) throws SQLException {		setBoolean(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setByte(java.lang.String, byte)	 */	public void setByte(String parameterName, byte x) throws SQLException {		setByte(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setBytes(java.lang.String, byte[])	 */	public void setBytes(String parameterName, byte[] x) throws SQLException {		setBytes(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setCharacterStream(java.lang.String,	 *      java.io.Reader, int)	 */	public void setCharacterStream(String parameterName, Reader reader,			int length) throws SQLException {		setCharacterStream(getNamedParamIndex(parameterName, false), reader,				length);	}	/**	 * @see java.sql.CallableStatement#setDate(java.lang.String, java.sql.Date)	 */	public void setDate(String parameterName, Date x) throws SQLException {		setDate(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setDate(java.lang.String, java.sql.Date,	 *      java.util.Calendar)	 */	public void setDate(String parameterName, Date x, Calendar cal)			throws SQLException {		setDate(getNamedParamIndex(parameterName, false), x, cal);	}	/**	 * @see java.sql.CallableStatement#setDouble(java.lang.String, double)	 */	public void setDouble(String parameterName, double x) throws SQLException {		setDouble(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setFloat(java.lang.String, float)	 */	public void setFloat(String parameterName, float x) throws SQLException {		setFloat(getNamedParamIndex(parameterName, false), x);	}	/**	 * 	 */	private void setInOutParamsOnServer() throws SQLException {		if (this.paramInfo.numParameters > 0) {			int parameterIndex = 0;			for (Iterator paramIter = this.paramInfo.iterator(); paramIter					.hasNext();) {				CallableStatementParam inParamInfo = (CallableStatementParam) paramIter						.next();				if (inParamInfo.isOut && inParamInfo.isIn) {					String inOutParameterName = mangleParameterName(inParamInfo.paramName);					StringBuffer queryBuf = new StringBuffer(							4 + inOutParameterName.length() + 1 + 1);					queryBuf.append("SET "); //$NON-NLS-1$					queryBuf.append(inOutParameterName);					queryBuf.append("=?"); //$NON-NLS-1$					PreparedStatement setPstmt = null;					try {						setPstmt = (PreparedStatement) this.connection								.clientPrepareStatement(queryBuf.toString());						byte[] parameterAsBytes = getBytesRepresentation(								inParamInfo.index);						if (parameterAsBytes != null) {							if (parameterAsBytes.length > 8									&& parameterAsBytes[0] == '_'									&& parameterAsBytes[1] == 'b'									&& parameterAsBytes[2] == 'i'									&& parameterAsBytes[3] == 'n'									&& parameterAsBytes[4] == 'a'									&& parameterAsBytes[5] == 'r'									&& parameterAsBytes[6] == 'y'									&& parameterAsBytes[7] == '\'') {								setPstmt.setBytesNoEscapeNoQuotes(1,										parameterAsBytes);							} else {								int sqlType = inParamInfo.desiredJdbcType;																switch (sqlType) {								case Types.BIT:								case Types.BINARY: 								case Types.BLOB: 								case Types.JAVA_OBJECT:								case Types.LONGVARBINARY: 								case Types.VARBINARY:									setPstmt.setBytes(1, parameterAsBytes);									break;								default:									// the inherited PreparedStatement methods									// have already escaped and quoted these parameters									setPstmt.setBytesNoEscape(1, parameterAsBytes);								}							}						} else {							setPstmt.setNull(1, Types.NULL);						}						setPstmt.executeUpdate();					} finally {						if (setPstmt != null) {							setPstmt.close();						}					}				}				parameterIndex++;			}		}	}	/**	 * @see java.sql.CallableStatement#setInt(java.lang.String, int)	 */	public void setInt(String parameterName, int x) throws SQLException {		setInt(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setLong(java.lang.String, long)	 */	public void setLong(String parameterName, long x) throws SQLException {		setLong(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setNull(java.lang.String, int)	 */	public void setNull(String parameterName, int sqlType) throws SQLException {		setNull(getNamedParamIndex(parameterName, false), sqlType);	}	/**	 * @see java.sql.CallableStatement#setNull(java.lang.String, int,	 *      java.lang.String)	 */	public void setNull(String parameterName, int sqlType, String typeName)			throws SQLException {		setNull(getNamedParamIndex(parameterName, false), sqlType, typeName);	}	/**	 * @see java.sql.CallableStatement#setObject(java.lang.String,	 *      java.lang.Object)	 */	public void setObject(String parameterName, Object x) throws SQLException {		setObject(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setObject(java.lang.String,	 *      java.lang.Object, int)	 */	public void setObject(String parameterName, Object x, int targetSqlType)			throws SQLException {		setObject(getNamedParamIndex(parameterName, false), x, targetSqlType);	}	/**	 * @see java.sql.CallableStatement#setObject(java.lang.String,	 *      java.lang.Object, int, int)	 */	public void setObject(String parameterName, Object x, int targetSqlType,			int scale) throws SQLException {	}	private void setOutParams() throws SQLException {		if (this.paramInfo.numParameters > 0) {			for (Iterator paramIter = this.paramInfo.iterator(); paramIter					.hasNext();) {				CallableStatementParam outParamInfo = (CallableStatementParam) paramIter						.next();				if (!this.callingStoredFunction && outParamInfo.isOut) {					String outParameterName = mangleParameterName(outParamInfo.paramName);					int outParamIndex;										if (this.placeholderToParameterIndexMap == null) { 							outParamIndex = outParamInfo.index + 1;					} else {							outParamIndex = this.placeholderToParameterIndexMap[outParamInfo.index - 1 /* JDBC is 1-based */];					}										this.setBytesNoEscapeNoQuotes(outParamIndex,							StringUtils.getBytes(outParameterName,									this.charConverter, this.charEncoding,									this.connection											.getServerCharacterEncoding(),									this.connection.parserKnowsUnicode()));				}			}		}	}	/**	 * @see java.sql.CallableStatement#setShort(java.lang.String, short)	 */	public void setShort(String parameterName, short x) throws SQLException {		setShort(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setString(java.lang.String,	 *      java.lang.String)	 */	public void setString(String parameterName, String x) throws SQLException {		setString(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setTime(java.lang.String, java.sql.Time)	 */	public void setTime(String parameterName, Time x) throws SQLException {		setTime(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setTime(java.lang.String, java.sql.Time,	 *      java.util.Calendar)	 */	public void setTime(String parameterName, Time x, Calendar cal)			throws SQLException {		setTime(getNamedParamIndex(parameterName, false), x, cal);	}	/**	 * @see java.sql.CallableStatement#setTimestamp(java.lang.String,	 *      java.sql.Timestamp)	 */	public void setTimestamp(String parameterName, Timestamp x)			throws SQLException {		setTimestamp(getNamedParamIndex(parameterName, false), x);	}	/**	 * @see java.sql.CallableStatement#setTimestamp(java.lang.String,	 *      java.sql.Timestamp, java.util.Calendar)	 */	public void setTimestamp(String parameterName, Timestamp x, Calendar cal)			throws SQLException {		setTimestamp(getNamedParamIndex(parameterName, false), x, cal);	}	/**	 * @see java.sql.CallableStatement#setURL(java.lang.String, java.net.URL)	 */	public void setURL(String parameterName, URL val) throws SQLException {		setURL(getNamedParamIndex(parameterName, false), val);	}	/**	 * @see java.sql.CallableStatement#wasNull()	 */	public synchronized boolean wasNull() throws SQLException {		return this.outputParamWasNull;	}	public int[] executeBatch() throws SQLException {		if (this.hasOutputParams) {			throw SQLError.createSQLException("Can't call executeBatch() on CallableStatement with OUTPUT parameters",					SQLError.SQL_STATE_ILLEGAL_ARGUMENT);		}				return super.executeBatch();	}	protected int getParameterIndexOffset() {		if (this.callingStoredFunction) {			return -1;		}				return super.getParameterIndexOffset();	}		public void setAsciiStream(String parameterName, InputStream x) throws SQLException {		setAsci

⌨️ 快捷键说明

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