📄 callablestatement.java
字号:
* * @see java.sql.PreparedStatement#executeUpdate() */ public int executeUpdate() throws SQLException { int returnVal = -1; checkClosed(); checkStreamability(); if (this.callingStoredFunction) { execute(); return -1; } synchronized (this.connection.getMutex()) { setInOutParamsOnServer(); setOutParams(); returnVal = super.executeUpdate(); retrieveOutParams(); } return returnVal; } private String extractProcedureName() throws SQLException { String sanitizedSql = StringUtils.stripComments(this.originalSql, "`\"'", "`\"'", true, false, true, true); // TODO: Do this with less memory allocation int endCallIndex = StringUtils.indexOfIgnoreCase(sanitizedSql, "CALL "); //$NON-NLS-1$ int offset = 5; if (endCallIndex == -1) { endCallIndex = StringUtils.indexOfIgnoreCase(sanitizedSql, "SELECT "); offset = 7; } if (endCallIndex != -1) { StringBuffer nameBuf = new StringBuffer(); String trimmedStatement = sanitizedSql.substring( endCallIndex + offset).trim(); int statementLength = trimmedStatement.length(); for (int i = 0; i < statementLength; i++) { char c = trimmedStatement.charAt(i); if (Character.isWhitespace(c) || (c == '(') || (c == '?')) { break; } nameBuf.append(c); } return nameBuf.toString(); } throw SQLError.createSQLException(Messages.getString("CallableStatement.1"), //$NON-NLS-1$ SQLError.SQL_STATE_GENERAL_ERROR); } /** * Adds 'at' symbol to beginning of parameter names if needed. * * @param paramNameIn * the parameter name to 'fix' * * @return the parameter name with an 'a' prepended, if needed * * @throws SQLException * if the parameter name is null or empty. */ protected String fixParameterName(String paramNameIn) throws SQLException { if ((paramNameIn == null) || (paramNameIn.length() == 0)) { throw SQLError.createSQLException( ((Messages.getString("CallableStatement.0") + paramNameIn) == null) //$NON-NLS-1$ ? Messages.getString("CallableStatement.15") : Messages.getString("CallableStatement.16"), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ //$NON-NLS-2$ } if (this.connection.getNoAccessToProcedureBodies()) { throw SQLError.createSQLException("No access to parameters by name when connection has been configured not to access procedure bodies", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } return mangleParameterName(paramNameIn); /* * if (paramNameIn.startsWith("@")) { return paramNameIn; } else { * StringBuffer paramNameBuf = new StringBuffer("@"); * paramNameBuf.append(paramNameIn); * * return paramNameBuf.toString(); } */ } /** * @see java.sql.CallableStatement#getArray(int) */ public synchronized Array getArray(int i) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(i); Array retValue = rs.getArray(mapOutputParameterIndexToRsIndex(i)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getArray(java.lang.String) */ public synchronized Array getArray(String parameterName) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(0); // definitely not going to be // from ?= Array retValue = rs.getArray(fixParameterName(parameterName)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getBigDecimal(int) */ public synchronized BigDecimal getBigDecimal(int parameterIndex) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(parameterIndex); BigDecimal retValue = rs .getBigDecimal(mapOutputParameterIndexToRsIndex(parameterIndex)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * DOCUMENT ME! * * @param parameterIndex * DOCUMENT ME! * @param scale * DOCUMENT ME! * * @return DOCUMENT ME! * * @throws SQLException * DOCUMENT ME! * * @see java.sql.CallableStatement#getBigDecimal(int, int) * @deprecated */ public synchronized BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(parameterIndex); BigDecimal retValue = rs.getBigDecimal( mapOutputParameterIndexToRsIndex(parameterIndex), scale); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getBigDecimal(java.lang.String) */ public synchronized BigDecimal getBigDecimal(String parameterName) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(0); // definitely not going to be // from ?= BigDecimal retValue = rs.getBigDecimal(fixParameterName(parameterName)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getBlob(int) */ public synchronized Blob getBlob(int parameterIndex) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(parameterIndex); Blob retValue = rs .getBlob(mapOutputParameterIndexToRsIndex(parameterIndex)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getBlob(java.lang.String) */ public synchronized Blob getBlob(String parameterName) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(0); // definitely not going to be // from ?= Blob retValue = rs.getBlob(fixParameterName(parameterName)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getBoolean(int) */ public synchronized boolean getBoolean(int parameterIndex) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(parameterIndex); boolean retValue = rs .getBoolean(mapOutputParameterIndexToRsIndex(parameterIndex)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getBoolean(java.lang.String) */ public synchronized boolean getBoolean(String parameterName) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(0); // definitely not going to be // from ?= boolean retValue = rs.getBoolean(fixParameterName(parameterName)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getByte(int) */ public synchronized byte getByte(int parameterIndex) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(parameterIndex); byte retValue = rs .getByte(mapOutputParameterIndexToRsIndex(parameterIndex)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getByte(java.lang.String) */ public synchronized byte getByte(String parameterName) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(0); // definitely not going to be // from ?= byte retValue = rs.getByte(fixParameterName(parameterName)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getBytes(int) */ public synchronized byte[] getBytes(int parameterIndex) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(parameterIndex); byte[] retValue = rs .getBytes(mapOutputParameterIndexToRsIndex(parameterIndex)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getBytes(java.lang.String) */ public synchronized byte[] getBytes(String parameterName) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(0); // definitely not going to be // from ?= byte[] retValue = rs.getBytes(fixParameterName(parameterName)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getClob(int) */ public synchronized Clob getClob(int parameterIndex) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(parameterIndex); Clob retValue = rs .getClob(mapOutputParameterIndexToRsIndex(parameterIndex)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getClob(java.lang.String) */ public synchronized Clob getClob(String parameterName) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(0); // definitely not going to be // from ?= Clob retValue = rs.getClob(fixParameterName(parameterName)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getDate(int) */ public synchronized Date getDate(int parameterIndex) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(parameterIndex); Date retValue = rs .getDate(mapOutputParameterIndexToRsIndex(parameterIndex)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getDate(int, java.util.Calendar) */ public synchronized Date getDate(int parameterIndex, Calendar cal) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(parameterIndex); Date retValue = rs.getDate( mapOutputParameterIndexToRsIndex(parameterIndex), cal); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getDate(java.lang.String) */ public synchronized Date getDate(String parameterName) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(0); // definitely not going to be // from ?= Date retValue = rs.getDate(fixParameterName(parameterName)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getDate(java.lang.String, * java.util.Calendar) */ public synchronized Date getDate(String parameterName, Calendar cal) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(0); // definitely not going to be // from ?= Date retValue = rs.getDate(fixParameterName(parameterName), cal); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getDouble(int) */ public synchronized double getDouble(int parameterIndex) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(parameterIndex); double retValue = rs .getDouble(mapOutputParameterIndexToRsIndex(parameterIndex)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getDouble(java.lang.String) */ public synchronized double getDouble(String parameterName) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(0); // definitely not going to be // from ?= double retValue = rs.getDouble(fixParameterName(parameterName)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getFloat(int) */ public synchronized float getFloat(int parameterIndex) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(parameterIndex); float retValue = rs .getFloat(mapOutputParameterIndexToRsIndex(parameterIndex)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getFloat(java.lang.String) */ public synchronized float getFloat(String parameterName) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(0); // definitely not going to be // from ?= float retValue = rs.getFloat(fixParameterName(parameterName)); this.outputParamWasNull = rs.wasNull(); return retValue; } /** * @see java.sql.CallableStatement#getInt(int) */ public synchronized int getInt(int parameterIndex) throws SQLException { ResultSetInternalMethods rs = getOutputParameters(parameterIndex); int retValue = rs .getInt(mapOutputParameterIndexToRsIndex(parameterIndex)); this.outputParamWasNull = rs.wasNull(); return retValue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -