📄 callablestatement.java
字号:
*/ public synchronized URL getURL(String parameterName) throws SQLException { ResultSet rs = getOutputParameters(0); // definitely not going to be // from ?= URL retValue = rs.getURL(fixParameterName(parameterName)); this.outputParamWasNull = rs.wasNull(); return retValue; } private int mapOutputParameterIndexToRsIndex(int paramIndex) throws SQLException { if (this.returnValueParam != null && paramIndex == 1) { return 1; } checkParameterIndexBounds(paramIndex); int localParamIndex = paramIndex - 1; int rsIndex = this.parameterIndexToRsIndex[localParamIndex]; if (rsIndex == NOT_OUTPUT_PARAMETER_INDICATOR) { throw new SQLException( Messages.getString("CallableStatement.21") + paramIndex //$NON-NLS-1$ + Messages.getString("CallableStatement.22"), //$NON-NLS-1$ SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } return rsIndex + 1; } /** * @see java.sql.CallableStatement#registerOutParameter(int, int) */ public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException { CallableStatementParam paramDescriptor = checkIsOutputParam(parameterIndex); 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.ResultSet) 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 = this.connection .clientPrepareStatement(queryBuf.toString()); byte[] parameterAsBytes = this .getBytesRepresentation(parameterIndex); 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 { setPstmt.setBytes(1, parameterAsBytes); } } else { setPstmt.setNull(1, Types.NULL); } setPstmt.executeUpdate(); } finally { if (setPstmt != null) { setPstmt.close(); } } // StringBuffer fullName = new StringBuffer("@"); // fullName.append(outParameterName); /* * this.setBytesNoEscapeNoQuotes(paramInfo.index + 1, * StringUtils.getBytes(outParameterName, * this.charConverter, this.charEncoding, * this.connection.getServerCharacterEncoding(), * this.connection.parserKnowsUnicode())); */ } } 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 { } /** * @see java.sql.CallableStatement#setNull(java.lang.String, int) */ public void setNull(String parameterName, int sqlType) throws SQLException { } /** * @see java.sql.CallableStatement#setNull(java.lang.String, int, * java.lang.String) */ public void setNull(String parameterName, int sqlType, String typeName) throws SQLException { } /** * @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 (outParamInfo.isOut) { String outParameterName = mangleParameterName(outParamInfo.paramName); this.setBytesNoEscapeNoQuotes(outParamInfo.index + 1, 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; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -