📄 callablestatement.java
字号:
java.sql.DatabaseMetaData dbmd = this.connection.getMetaData(); boolean useCatalog = false; if (procName.indexOf(".") == -1) { useCatalog = true; } paramTypesRs = dbmd.getProcedureColumns(this.connection .versionMeetsMinimum(5, 0, 2) & useCatalog ? this.currentCatalog : null, null, procName, "%"); //$NON-NLS-1$ this.paramInfo = new CallableStatementParamInfo(paramTypesRs); } finally { SQLException sqlExRethrow = null; if (paramTypesRs != null) { try { paramTypesRs.close(); } catch (SQLException sqlEx) { sqlExRethrow = sqlEx; } paramTypesRs = null; } if (sqlExRethrow != null) { throw sqlExRethrow; } } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#execute() */ public boolean execute() throws SQLException { boolean returnVal = false; checkClosed(); checkStreamability(); synchronized (this.connection.getMutex()) { setInOutParamsOnServer(); setOutParams(); returnVal = super.execute(); if (this.callingStoredFunction) { this.functionReturnValueResults = this.results; this.functionReturnValueResults.next(); this.results = null; } retrieveOutParams(); } if (!this.callingStoredFunction) { return returnVal; } // Functions can't return results return false; } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#executeQuery() */ public synchronized java.sql.ResultSet executeQuery() throws SQLException { checkClosed(); checkStreamability(); java.sql.ResultSet execResults = null; synchronized (this.connection.getMutex()) { setInOutParamsOnServer(); setOutParams(); execResults = super.executeQuery(); retrieveOutParams(); } return execResults; } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#executeUpdate() */ public synchronized 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 { // TODO: Do this with less memory allocation int endCallIndex = StringUtils.indexOfIgnoreCase(this.originalSql, "CALL "); //$NON-NLS-1$ int offset = 5; if (endCallIndex == -1) { endCallIndex = StringUtils.indexOfIgnoreCase(this.originalSql, "SELECT "); offset = 7; } if (endCallIndex != -1) { StringBuffer nameBuf = new StringBuffer(); String trimmedStatement = this.originalSql.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 new SQLException(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. */ private String fixParameterName(String paramNameIn) throws SQLException { if ((paramNameIn == null) || (paramNameIn.length() == 0)) { throw new SQLException( ((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$ } 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet 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 { ResultSet rs = getOutputParameters(0); // definitely not going to be // from ?=
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -