KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mysql > jdbc > CallableStatement


1 /*
2  Copyright (C) 2002-2004 MySQL AB
3
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of version 2 of the GNU General Public License as
6  published by the Free Software Foundation.
7
8  There are special exceptions to the terms and conditions of the GPL
9  as it is applied to this software. View the full text of the
10  exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
11  software distribution.
12
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22
23
24  */

25 package com.mysql.jdbc;
26
27 import java.io.InputStream JavaDoc;
28 import java.io.Reader JavaDoc;
29
30 import java.math.BigDecimal JavaDoc;
31
32 import java.net.URL JavaDoc;
33
34 import java.sql.Array JavaDoc;
35 import java.sql.Blob JavaDoc;
36 import java.sql.Clob JavaDoc;
37 import java.sql.Date JavaDoc;
38 import java.sql.ParameterMetaData JavaDoc;
39 import java.sql.Ref JavaDoc;
40 import java.sql.SQLException JavaDoc;
41 import java.sql.Time JavaDoc;
42 import java.sql.Timestamp JavaDoc;
43 import java.sql.Types JavaDoc;
44
45 import java.util.ArrayList JavaDoc;
46 import java.util.Calendar JavaDoc;
47 import java.util.HashMap JavaDoc;
48 import java.util.Iterator JavaDoc;
49 import java.util.List JavaDoc;
50 import java.util.Locale JavaDoc;
51 import java.util.Map JavaDoc;
52
53 /**
54  * Representation of stored procedures for JDBC
55  *
56  * @author Mark Matthews
57  * @version $Id: CallableStatement.java,v 1.1.2.1 2005/05/13 18:58:38 mmatthews
58  * Exp $
59  */

60 public class CallableStatement extends PreparedStatement implements
61         java.sql.CallableStatement JavaDoc {
62     class CallableStatementParam {
63         int desiredJdbcType;
64
65         int index;
66
67         boolean isIn;
68
69         boolean isOut;
70
71         String JavaDoc paramName;
72
73         int jdbcType;
74         String JavaDoc typeName;
75         int precision;
76         int scale;
77         short nullability;
78         int inOutModifier;
79         
80         CallableStatementParam(String JavaDoc name, int idx, boolean in,
81                 boolean out, int jdbcType, String JavaDoc typeName,
82                 int precision, int scale, short nullability,
83                 int inOutModifier) {
84             this.paramName = name;
85             this.isIn = in;
86             this.isOut = out;
87             this.index = idx;
88             
89             this.jdbcType = jdbcType;
90             this.typeName = typeName;
91             this.precision = precision;
92             this.scale = scale;
93             this.nullability = nullability;
94             this.inOutModifier = inOutModifier;
95         }
96
97         /*
98          * (non-Javadoc)
99          *
100          * @see java.lang.Object#clone()
101          */

102         protected Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
103             return super.clone();
104         }
105     }
106
107     class CallableStatementParamInfo implements ParameterMetaData JavaDoc {
108         String JavaDoc catalogInUse;
109
110         boolean isFunctionCall;
111
112         String JavaDoc nativeSql;
113
114         int numParameters;
115
116         List JavaDoc parameterList;
117
118         Map JavaDoc parameterMap;
119
120         CallableStatementParamInfo(java.sql.ResultSet JavaDoc paramTypesRs)
121                 throws SQLException JavaDoc {
122             boolean hadRows = paramTypesRs.last();
123
124             this.nativeSql = originalSql;
125             this.catalogInUse = currentCatalog;
126             isFunctionCall = callingStoredFunction;
127
128             if (hadRows) {
129                 this.numParameters = paramTypesRs.getRow();
130
131                 this.parameterList = new ArrayList JavaDoc(this.numParameters);
132                 this.parameterMap = new HashMap JavaDoc(this.numParameters);
133
134                 paramTypesRs.beforeFirst();
135
136                 addParametersFromDBMD(paramTypesRs);
137             } else {
138                 this.numParameters = 0;
139             }
140         }
141
142         private void addParametersFromDBMD(java.sql.ResultSet JavaDoc paramTypesRs)
143                 throws SQLException JavaDoc {
144             int i = 0;
145
146             if (isFunctionCall) {
147                 // first row will be return value parameter
148
paramTypesRs.next();
149             }
150             
151             while (paramTypesRs.next()) {
152                 String JavaDoc paramName = paramTypesRs.getString(4);
153                 int inOutModifier = paramTypesRs.getInt(5);
154
155                 boolean isOutParameter = false;
156                 boolean isInParameter = false;
157
158                 if (inOutModifier == DatabaseMetaData.procedureColumnInOut) {
159                     isOutParameter = true;
160                     isInParameter = true;
161                 } else if (inOutModifier == DatabaseMetaData.procedureColumnIn) {
162                     isOutParameter = false;
163                     isInParameter = true;
164                 } else if (inOutModifier == DatabaseMetaData.procedureColumnOut) {
165                     isOutParameter = true;
166                     isInParameter = false;
167                 }
168                 
169                 int jdbcType = paramTypesRs.getInt(6);
170                 String JavaDoc typeName = paramTypesRs.getString(7);
171                 int precision = paramTypesRs.getInt(8);
172                 int scale = paramTypesRs.getInt(10);
173                 short nullability = paramTypesRs.getShort(12);
174
175                 CallableStatementParam paramInfoToAdd = new CallableStatementParam(
176                         paramName, i++, isInParameter, isOutParameter,
177                         jdbcType, typeName, precision, scale, nullability,
178                         inOutModifier);
179
180                 this.parameterList.add(paramInfoToAdd);
181                 this.parameterMap.put(paramName, paramInfoToAdd);
182             }
183         }
184
185         /*
186          * (non-Javadoc)
187          *
188          * @see java.lang.Object#clone()
189          */

190         protected Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
191             // TODO Auto-generated method stub
192
return super.clone();
193         }
194
195         CallableStatementParam getParameter(int index) {
196             return (CallableStatementParam) this.parameterList.get(index);
197         }
198
199         CallableStatementParam getParameter(String JavaDoc name) {
200             return (CallableStatementParam) this.parameterMap.get(name);
201         }
202
203         Iterator JavaDoc iterator() {
204             return this.parameterList.iterator();
205         }
206
207         int numberOfParameters() {
208             return this.numParameters;
209         }
210
211         public int getParameterCount() throws SQLException JavaDoc {
212             return this.parameterList.size();
213         }
214
215         public int isNullable(int arg0) throws SQLException JavaDoc {
216             checkBounds(arg0);
217             
218             return getParameter(arg0 - 1).nullability;
219         }
220
221         public boolean isSigned(int arg0) throws SQLException JavaDoc {
222             checkBounds(arg0);
223
224             return false;
225         }
226
227         public int getPrecision(int arg0) throws SQLException JavaDoc {
228             checkBounds(arg0);
229             
230             return getParameter(arg0 - 1).precision;
231         }
232
233         public int getScale(int arg0) throws SQLException JavaDoc {
234             checkBounds(arg0);
235             
236             return getParameter(arg0 - 1).scale;
237         }
238
239         public int getParameterType(int arg0) throws SQLException JavaDoc {
240             checkBounds(arg0);
241             
242             return getParameter(arg0 - 1).jdbcType;
243         }
244
245         public String JavaDoc getParameterTypeName(int arg0) throws SQLException JavaDoc {
246             checkBounds(arg0);
247             
248             return getParameter(arg0 - 1).typeName;
249         }
250
251         public String JavaDoc getParameterClassName(int arg0) throws SQLException JavaDoc {
252             // TODO Auto-generated method stub
253
return null;
254         }
255
256         public int getParameterMode(int arg0) throws SQLException JavaDoc {
257             checkBounds(arg0);
258             
259             return getParameter(arg0 - 1).inOutModifier;
260         }
261
262         protected void checkBounds(int paramIndex) throws SQLException JavaDoc {
263             int localParamIndex = paramIndex - 1;
264
265             if ((paramIndex < 0)
266                     || (localParamIndex >= this.numParameters)) {
267                 throw new SQLException JavaDoc(
268                         Messages.getString("CallableStatement.11") + paramIndex //$NON-NLS-1$
269
+ Messages.getString("CallableStatement.12") + numParameters //$NON-NLS-1$
270
+ Messages.getString("CallableStatement.13"), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$
271
}
272         }
273     }
274     
275     private final static int NOT_OUTPUT_PARAMETER_INDICATOR = Integer.MIN_VALUE;
276
277     private final static String JavaDoc PARAMETER_NAMESPACE_PREFIX = "@com_mysql_jdbc_outparam_"; //$NON-NLS-1$
278

279     private static String JavaDoc mangleParameterName(String JavaDoc origParameterName) {
280         if (origParameterName == null) {
281             return null;
282         }
283
284         int offset = 0;
285
286         if (origParameterName.length() > 0
287                 && origParameterName.charAt(0) == '@') {
288             offset = 1;
289         }
290
291         StringBuffer JavaDoc paramNameBuf = new StringBuffer JavaDoc(PARAMETER_NAMESPACE_PREFIX
292                 .length()
293                 + origParameterName.length());
294         paramNameBuf.append(PARAMETER_NAMESPACE_PREFIX);
295         paramNameBuf.append(origParameterName.substring(offset));
296
297         return paramNameBuf.toString();
298     }
299
300     private boolean callingStoredFunction = false;
301
302     private ResultSet functionReturnValueResults;
303
304     private boolean hasOutputParams = false;
305
306     // private List parameterList;
307
// private Map parameterMap;
308
private ResultSet outputParameterResults;
309
310     private boolean outputParamWasNull = false;
311
312     private int[] parameterIndexToRsIndex;
313
314     protected CallableStatementParamInfo paramInfo;
315
316     private CallableStatementParam returnValueParam;
317
318     /**
319      * Creates a new CallableStatement
320      *
321      * @param conn
322      * the connection creating this statement
323      * @param paramInfo
324      * the SQL to prepare
325      *
326      * @throws SQLException
327      * if an error occurs
328      */

329     public CallableStatement(Connection conn,
330             CallableStatementParamInfo paramInfo) throws SQLException JavaDoc {
331         super(conn, paramInfo.nativeSql, paramInfo.catalogInUse);
332
333         this.paramInfo = paramInfo;
334         this.callingStoredFunction = this.paramInfo.isFunctionCall;
335     }
336
337     /**
338      * Creates a new CallableStatement
339      *
340      * @param conn
341      * the connection creating this statement
342      * @param catalog
343      * catalog the current catalog
344      *
345      * @throws SQLException
346      * if an error occurs
347      */

348     public CallableStatement(Connection conn, String JavaDoc catalog)
349             throws SQLException JavaDoc {
350         super(conn, catalog, null);
351
352         determineParameterTypes();
353     }
354
355     /**
356      * Creates a new CallableStatement
357      *
358      * @param conn
359      * the connection creating this statement
360      * @param sql
361      * the SQL to prepare
362      * @param catalog
363      * the current catalog
364      *
365      * @throws SQLException
366      * if an error occurs
367      */

368     public CallableStatement(Connection conn, String JavaDoc sql, String JavaDoc catalog,
369             boolean isFunctionCall) throws SQLException JavaDoc {
370         super(conn, sql, catalog);
371
372         this.callingStoredFunction = isFunctionCall;
373
374         determineParameterTypes();
375     }
376
377     /*
378      * (non-Javadoc)
379      *
380      * @see java.sql.PreparedStatement#addBatch()
381      */

382     public void addBatch() throws SQLException JavaDoc {
383         setOutParams();
384
385         super.addBatch();
386     }
387
388     private CallableStatementParam checkIsOutputParam(int paramIndex)
389             throws SQLException JavaDoc {
390
391         if (this.callingStoredFunction) {
392             if (paramIndex == 1) {
393
394                 if (this.returnValueParam == null) {
395                     this.returnValueParam = new CallableStatementParam("", 0,
396                             false, true, Types.VARCHAR, "VARCHAR", 0, 0,
397                             DatabaseMetaData.attributeNullableUnknown,
398                             DatabaseMetaData.procedureColumnReturn);
399                 }
400
401                 return this.returnValueParam;
402             }
403
404             // Move to position in output result set
405
paramIndex--;
406         }
407
408         checkParameterIndexBounds(paramIndex);
409
410         int localParamIndex = paramIndex - 1;
411
412         CallableStatementParam paramDescriptor = this.paramInfo
413                 .getParameter(localParamIndex);
414
415         if (!paramDescriptor.isOut) {
416             throw new SQLException JavaDoc(
417                     Messages.getString("CallableStatement.9") + paramIndex //$NON-NLS-1$
418
+ Messages.getString("CallableStatement.10"), //$NON-NLS-1$
419
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
420         }
421
422         this.hasOutputParams = true;
423
424         return paramDescriptor;
425     }
426
427     /**
428      * DOCUMENT ME!
429      *
430      * @param paramIndex
431      *
432      * @throws SQLException
433      */

434     private void checkParameterIndexBounds(int paramIndex) throws SQLException JavaDoc {
435         this.paramInfo.checkBounds(paramIndex);
436     }
437
438     /**
439      * Checks whether or not this statement is supposed to be providing
440      * streamable result sets...If output parameters are registered, the driver
441      * can not stream the results.
442      *
443      * @throws SQLException
444      * DOCUMENT ME!
445      */

446     private void checkStreamability() throws SQLException JavaDoc {
447         if (this.hasOutputParams && createStreamingResultSet()) {
448             throw new SQLException JavaDoc(Messages.getString("CallableStatement.14"), //$NON-NLS-1$
449
SQLError.SQL_STATE_DRIVER_NOT_CAPABLE);
450         }
451     }
452
453     private void determineParameterTypes() throws SQLException JavaDoc {
454         java.sql.ResultSet JavaDoc paramTypesRs = null;
455
456         try {
457             String JavaDoc procName = extractProcedureName();
458
459             java.sql.DatabaseMetaData JavaDoc dbmd = this.connection.getMetaData();
460
461             boolean useCatalog = false;
462
463             if (procName.indexOf(".") == -1) {
464                 useCatalog = true;
465             }
466
467             paramTypesRs = dbmd.getProcedureColumns(this.connection
468                     .versionMeetsMinimum(5, 0, 2)
469                     & useCatalog ? this.currentCatalog : null, null, procName,
470                     "%"); //$NON-NLS-1$
471

472             this.paramInfo = new CallableStatementParamInfo(paramTypesRs);
473         } finally {
474             SQLException JavaDoc sqlExRethrow = null;
475
476             if (paramTypesRs != null) {
477                 try {
478                     paramTypesRs.close();
479                 } catch (SQLException JavaDoc sqlEx) {
480                     sqlExRethrow = sqlEx;
481                 }
482
483                 paramTypesRs = null;
484             }
485
486             if (sqlExRethrow != null) {
487                 throw sqlExRethrow;
488             }
489         }
490     }
491
492     /*
493      * (non-Javadoc)
494      *
495      * @see java.sql.PreparedStatement#execute()
496      */

497     public boolean execute() throws SQLException JavaDoc {
498         boolean returnVal = false;
499
500         checkClosed();
501
502         checkStreamability();
503
504         synchronized (this.connection.getMutex()) {
505             setInOutParamsOnServer();
506             setOutParams();
507
508             returnVal = super.execute();
509
510             if (this.callingStoredFunction) {
511                 this.functionReturnValueResults = this.results;
512                 this.functionReturnValueResults.next();
513                 this.results = null;
514             }
515
516             retrieveOutParams();
517         }
518
519         if (!this.callingStoredFunction) {
520             return returnVal;
521         }
522
523         // Functions can't return results
524
return false;
525     }
526
527     /*
528      * (non-Javadoc)
529      *
530      * @see java.sql.PreparedStatement#executeQuery()
531      */

532     public synchronized java.sql.ResultSet JavaDoc executeQuery() throws SQLException JavaDoc {
533         checkClosed();
534
535         checkStreamability();
536
537         java.sql.ResultSet JavaDoc execResults = null;
538
539         synchronized (this.connection.getMutex()) {
540             setInOutParamsOnServer();
541             setOutParams();
542
543             execResults = super.executeQuery();
544
545             retrieveOutParams();
546         }
547
548         return execResults;
549     }
550
551     /*
552      * (non-Javadoc)
553      *
554      * @see java.sql.PreparedStatement#executeUpdate()
555      */

556     public synchronized int executeUpdate() throws SQLException JavaDoc {
557         int returnVal = -1;
558
559         checkClosed();
560
561         checkStreamability();
562
563         if (this.callingStoredFunction) {
564             execute();
565
566             return -1;
567         }
568
569         synchronized (this.connection.getMutex()) {
570             setInOutParamsOnServer();
571             setOutParams();
572
573             returnVal = super.executeUpdate();
574
575             retrieveOutParams();
576         }
577
578         return returnVal;
579     }
580
581     private String JavaDoc extractProcedureName() throws SQLException JavaDoc {
582         // TODO: Do this with less memory allocation
583
int endCallIndex = StringUtils.indexOfIgnoreCase(this.originalSql,
584                 "CALL "); //$NON-NLS-1$
585
int offset = 5;
586
587         if (endCallIndex == -1) {
588             endCallIndex = StringUtils.indexOfIgnoreCase(this.originalSql,
589                     "SELECT ");
590             offset = 7;
591         }
592
593         if (endCallIndex != -1) {
594             StringBuffer JavaDoc nameBuf = new StringBuffer JavaDoc();
595
596             String JavaDoc trimmedStatement = this.originalSql.substring(
597                     endCallIndex + offset).trim();
598
599             int statementLength = trimmedStatement.length();
600
601             for (int i = 0; i < statementLength; i++) {
602                 char c = trimmedStatement.charAt(i);
603
604                 if (Character.isWhitespace(c) || (c == '(') || (c == '?')) {
605                     break;
606                 }
607                 nameBuf.append(c);
608
609             }
610
611             return nameBuf.toString();
612         }
613         throw new SQLException JavaDoc(Messages.getString("CallableStatement.1"), //$NON-NLS-1$
614
SQLError.SQL_STATE_GENERAL_ERROR);
615
616     }
617
618     /**
619      * Adds 'at' symbol to beginning of parameter names if needed.
620      *
621      * @param paramNameIn
622      * the parameter name to 'fix'
623      *
624      * @return the parameter name with an 'a' prepended, if needed
625      *
626      * @throws SQLException
627      * if the parameter name is null or empty.
628      */

629     private String JavaDoc fixParameterName(String JavaDoc paramNameIn) throws SQLException JavaDoc {
630         if ((paramNameIn == null) || (paramNameIn.length() == 0)) {
631             throw new SQLException JavaDoc(
632                     ((Messages.getString("CallableStatement.0") + paramNameIn) == null) //$NON-NLS-1$
633
? Messages.getString("CallableStatement.15") : Messages.getString("CallableStatement.16"), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ //$NON-NLS-2$
634
}
635
636         return mangleParameterName(paramNameIn);
637
638         /*
639          * if (paramNameIn.startsWith("@")) { return paramNameIn; } else {
640          * StringBuffer paramNameBuf = new StringBuffer("@");
641          * paramNameBuf.append(paramNameIn);
642          *
643          * return paramNameBuf.toString(); }
644          */

645     }
646
647     /**
648      * @see java.sql.CallableStatement#getArray(int)
649      */

650     public synchronized Array JavaDoc getArray(int i) throws SQLException JavaDoc {
651         ResultSet rs = getOutputParameters(i);
652
653         Array JavaDoc retValue = rs.getArray(mapOutputParameterIndexToRsIndex(i));
654
655         this.outputParamWasNull = rs.wasNull();
656
657         return retValue;
658     }
659
660     /**
661      * @see java.sql.CallableStatement#getArray(java.lang.String)
662      */

663     public synchronized Array JavaDoc getArray(String JavaDoc parameterName)
664             throws SQLException JavaDoc {
665         ResultSet rs = getOutputParameters(0); // definitely not going to be
666
// from ?=
667

668         Array JavaDoc retValue = rs.getArray(fixParameterName(parameterName));
669
670         this.outputParamWasNull = rs.wasNull();
671
672         return retValue;
673     }
674
675     /**
676      * @see java.sql.CallableStatement#getBigDecimal(int)
677      */

678     public synchronized BigDecimal JavaDoc getBigDecimal(int parameterIndex)
679             throws SQLException JavaDoc {
680         ResultSet rs = getOutputParameters(parameterIndex);
681
682         BigDecimal JavaDoc retValue = rs
683                 .getBigDecimal(mapOutputParameterIndexToRsIndex(parameterIndex));
684
685         this.outputParamWasNull = rs.wasNull();
686
687         return retValue;
688     }
689
690     /**
691      * DOCUMENT ME!
692      *
693      * @param parameterIndex
694      * DOCUMENT ME!
695      * @param scale
696      * DOCUMENT ME!
697      *
698      * @return DOCUMENT ME!
699      *
700      * @throws SQLException
701      * DOCUMENT ME!
702      *
703      * @see java.sql.CallableStatement#getBigDecimal(int, int)
704      * @deprecated
705      */

706     public synchronized BigDecimal JavaDoc getBigDecimal(int parameterIndex, int scale)
707             throws SQLException JavaDoc {
708         ResultSet rs = getOutputParameters(parameterIndex);
709
710         BigDecimal JavaDoc retValue = rs.getBigDecimal(
711                 mapOutputParameterIndexToRsIndex(parameterIndex), scale);
712
713         this.outputParamWasNull = rs.wasNull();
714
715         return retValue;
716     }
717
718     /**
719      * @see java.sql.CallableStatement#getBigDecimal(java.lang.String)
720      */

721     public synchronized BigDecimal JavaDoc getBigDecimal(String JavaDoc parameterName)
722             throws SQLException JavaDoc {
723         ResultSet rs = getOutputParameters(0); // definitely not going to be
724
// from ?=
725

726         BigDecimal JavaDoc retValue = rs.getBigDecimal(fixParameterName(parameterName));
727
728         this.outputParamWasNull = rs.wasNull();
729
730         return retValue;
731     }
732
733     /**
734      * @see java.sql.CallableStatement#getBlob(int)
735      */

736     public synchronized Blob getBlob(int parameterIndex) throws SQLException JavaDoc {
737         ResultSet rs = getOutputParameters(parameterIndex);
738
739         Blob retValue = rs
740                 .getBlob(mapOutputParameterIndexToRsIndex(parameterIndex));
741
742         this.outputParamWasNull = rs.wasNull();
743
744         return retValue;
745     }
746
747     /**
748      * @see java.sql.CallableStatement#getBlob(java.lang.String)
749      */

750     public synchronized Blob getBlob(String JavaDoc parameterName) throws SQLException JavaDoc {
751         ResultSet rs = getOutputParameters(0); // definitely not going to be
752
// from ?=
753

754         Blob retValue = rs.getBlob(fixParameterName(parameterName));
755
756         this.outputParamWasNull = rs.wasNull();
757
758         return retValue;
759     }
760
761     /**
762      * @see java.sql.CallableStatement#getBoolean(int)
763      */

764     public synchronized boolean getBoolean(int parameterIndex)
765             throws SQLException JavaDoc {
766         ResultSet rs = getOutputParameters(parameterIndex);
767
768         boolean retValue = rs
769                 .getBoolean(mapOutputParameterIndexToRsIndex(parameterIndex));
770
771         this.outputParamWasNull = rs.wasNull();
772
773         return retValue;
774     }
775
776     /**
777      * @see java.sql.CallableStatement#getBoolean(java.lang.String)
778      */

779     public synchronized boolean getBoolean(String JavaDoc parameterName)
780             throws SQLException JavaDoc {
781         ResultSet rs = getOutputParameters(0); // definitely not going to be
782
// from ?=
783

784         boolean retValue = rs.getBoolean(fixParameterName(parameterName));
785
786         this.outputParamWasNull = rs.wasNull();
787
788         return retValue;
789     }
790
791     /**
792      * @see java.sql.CallableStatement#getByte(int)
793      */

794     public synchronized byte getByte(int parameterIndex) throws SQLException JavaDoc {
795         ResultSet rs = getOutputParameters(parameterIndex);
796
797         byte retValue = rs
798                 .getByte(mapOutputParameterIndexToRsIndex(parameterIndex));
799
800         this.outputParamWasNull = rs.wasNull();
801
802         return retValue;
803     }
804
805     /**
806      * @see java.sql.CallableStatement#getByte(java.lang.String)
807      */

808     public synchronized byte getByte(String JavaDoc parameterName) throws SQLException JavaDoc {
809         ResultSet rs = getOutputParameters(0); // definitely not going to be
810
// from ?=
811

812         byte retValue = rs.getByte(fixParameterName(parameterName));
813
814         this.outputParamWasNull = rs.wasNull();
815
816         return retValue;
817     }
818
819     /**
820      * @see java.sql.CallableStatement#getBytes(int)
821      */

822     public synchronized byte[] getBytes(int parameterIndex) throws SQLException JavaDoc {
823         ResultSet rs = getOutputParameters(parameterIndex);
824
825         byte[] retValue = rs
826                 .getBytes(mapOutputParameterIndexToRsIndex(parameterIndex));
827
828         this.outputParamWasNull = rs.wasNull();
829
830         return retValue;
831     }
832
833     /**
834      * @see java.sql.CallableStatement#getBytes(java.lang.String)
835      */

836     public synchronized byte[] getBytes(String JavaDoc parameterName)
837             throws SQLException JavaDoc {
838         ResultSet rs = getOutputParameters(0); // definitely not going to be
839
// from ?=
840

841         byte[] retValue = rs.getBytes(fixParameterName(parameterName));
842
843         this.outputParamWasNull = rs.wasNull();
844
845         return retValue;
846     }
847
848     /**
849      * @see java.sql.CallableStatement#getClob(int)
850      */

851     public synchronized Clob getClob(int parameterIndex) throws SQLException JavaDoc {
852         ResultSet rs = getOutputParameters(parameterIndex);
853
854         Clob retValue = rs
855                 .getClob(mapOutputParameterIndexToRsIndex(parameterIndex));
856
857         this.outputParamWasNull = rs.wasNull();
858
859         return retValue;
860     }
861
862     /**
863      * @see java.sql.CallableStatement#getClob(java.lang.String)
864      */

865     public synchronized Clob getClob(String JavaDoc parameterName) throws SQLException JavaDoc {
866         ResultSet rs = getOutputParameters(0); // definitely not going to be
867
// from ?=
868

869         Clob retValue = rs.getClob(fixParameterName(parameterName));
870
871         this.outputParamWasNull = rs.wasNull();
872
873         return retValue;
874     }
875
876     /**
877      * @see java.sql.CallableStatement#getDate(int)
878      */

879     public synchronized Date JavaDoc getDate(int parameterIndex) throws SQLException JavaDoc {
880         ResultSet rs = getOutputParameters(parameterIndex);
881
882         Date JavaDoc retValue = rs
883                 .getDate(mapOutputParameterIndexToRsIndex(parameterIndex));
884
885         this.outputParamWasNull = rs.wasNull();
886
887         return retValue;
888     }
889
890     /**
891      * @see java.sql.CallableStatement#getDate(int, java.util.Calendar)
892      */

893     public synchronized Date JavaDoc getDate(int parameterIndex, Calendar JavaDoc cal)
894             throws SQLException JavaDoc {
895         ResultSet rs = getOutputParameters(parameterIndex);
896
897         Date JavaDoc retValue = rs.getDate(
898                 mapOutputParameterIndexToRsIndex(parameterIndex), cal);
899
900         this.outputParamWasNull = rs.wasNull();
901
902         return retValue;
903     }
904
905     /**
906      * @see java.sql.CallableStatement#getDate(java.lang.String)
907      */

908     public synchronized Date JavaDoc getDate(String JavaDoc parameterName) throws SQLException JavaDoc {
909         ResultSet rs = getOutputParameters(0); // definitely not going to be
910
// from ?=
911

912         Date JavaDoc retValue = rs.getDate(fixParameterName(parameterName));
913
914         this.outputParamWasNull = rs.wasNull();
915
916         return retValue;
917     }
918
919     /**
920      * @see java.sql.CallableStatement#getDate(java.lang.String,
921      * java.util.Calendar)
922      */

923     public synchronized Date JavaDoc getDate(String JavaDoc parameterName, Calendar JavaDoc cal)
924             throws SQLException JavaDoc {
925         ResultSet rs = getOutputParameters(0); // definitely not going to be
926
// from ?=
927

928         Date JavaDoc retValue = rs.getDate(fixParameterName(parameterName), cal);
929
930         this.outputParamWasNull = rs.wasNull();
931
932         return retValue;
933     }
934
935     /**
936      * @see java.sql.CallableStatement#getDouble(int)
937      */

938     public synchronized double getDouble(int parameterIndex)
939             throws SQLException JavaDoc {
940         ResultSet rs = getOutputParameters(parameterIndex);
941
942         double retValue = rs
943                 .getDouble(mapOutputParameterIndexToRsIndex(parameterIndex));
944
945         this.outputParamWasNull = rs.wasNull();
946
947         return retValue;
948     }
949
950     /**
951      * @see java.sql.CallableStatement#getDouble(java.lang.String)
952      */

953     public synchronized double getDouble(String JavaDoc parameterName)
954             throws SQLException JavaDoc {
955         ResultSet rs = getOutputParameters(0); // definitely not going to be
956
// from ?=
957

958         double retValue = rs.getDouble(fixParameterName(parameterName));
959
960         this.outputParamWasNull = rs.wasNull();
961
962         return retValue;
963     }
964
965     /**
966      * @see java.sql.CallableStatement#getFloat(int)
967      */

968     public synchronized float getFloat(int parameterIndex) throws SQLException JavaDoc {
969         ResultSet rs = getOutputParameters(parameterIndex);
970
971         float retValue = rs
972                 .getFloat(mapOutputParameterIndexToRsIndex(parameterIndex));
973
974         this.outputParamWasNull = rs.wasNull();
975
976         return retValue;
977     }
978
979     /**
980      * @see java.sql.CallableStatement#getFloat(java.lang.String)
981      */

982     public synchronized float getFloat(String JavaDoc parameterName)
983             throws SQLException JavaDoc {
984         ResultSet rs = getOutputParameters(0); // definitely not going to be
985
// from ?=
986

987         float retValue = rs.getFloat(fixParameterName(parameterName));
988
989         this.outputParamWasNull = rs.wasNull();
990
991         return retValue;
992     }
993
994     /**
995      * @see java.sql.CallableStatement#getInt(int)
996      */

997     public synchronized int getInt(int parameterIndex) throws SQLException JavaDoc {
998         ResultSet rs = getOutputParameters(parameterIndex);
999
1000        int retValue = rs
1001                .getInt(mapOutputParameterIndexToRsIndex(parameterIndex));
1002
1003        this.outputParamWasNull = rs.wasNull();
1004
1005        return retValue;
1006    }
1007
1008    /**
1009     * @see java.sql.CallableStatement#getInt(java.lang.String)
1010     */

1011    public synchronized int getInt(String JavaDoc parameterName) throws SQLException JavaDoc {
1012        ResultSet rs = getOutputParameters(0); // definitely not going to be
1013
// from ?=
1014

1015        int retValue = rs.getInt(fixParameterName(parameterName));
1016
1017        this.outputParamWasNull = rs.wasNull();
1018
1019        return retValue;
1020    }
1021
1022    /**
1023     * @see java.sql.CallableStatement#getLong(int)
1024     */

1025    public synchronized long getLong(int parameterIndex) throws SQLException JavaDoc {
1026        ResultSet rs = getOutputParameters(parameterIndex);
1027
1028        long retValue = rs
1029                .getLong(mapOutputParameterIndexToRsIndex(parameterIndex));
1030
1031        this.outputParamWasNull = rs.wasNull();
1032
1033        return retValue;
1034    }
1035
1036    /**
1037     * @see java.sql.CallableStatement#getLong(java.lang.String)
1038     */

1039    public synchronized long getLong(String JavaDoc parameterName) throws SQLException JavaDoc {
1040        ResultSet rs = getOutputParameters(0); // definitely not going to be
1041
// from ?=
1042

1043        long retValue = rs.getLong(fixParameterName(parameterName));
1044
1045        this.outputParamWasNull = rs.wasNull();
1046
1047        return retValue;
1048    }
1049
1050    private int getNamedParamIndex(String JavaDoc paramName, boolean forOut)
1051            throws SQLException JavaDoc {
1052        if ((paramName == null) || (paramName.length() == 0)) {
1053            throw new SQLException JavaDoc(Messages.getString("CallableStatement.2"), //$NON-NLS-1$
1054
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1055        }
1056
1057        CallableStatementParam namedParamInfo = this.paramInfo
1058                .getParameter(paramName);
1059
1060        if (this.paramInfo == null) {
1061            throw new SQLException JavaDoc(
1062                    Messages.getString("CallableStatement.3") + paramName + Messages.getString("CallableStatement.4"), //$NON-NLS-1$ //$NON-NLS-2$
1063
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1064        }
1065
1066        if (forOut && !namedParamInfo.isOut) {
1067            throw new SQLException JavaDoc(
1068                    Messages.getString("CallableStatement.5") + paramName //$NON-NLS-1$
1069
+ Messages.getString("CallableStatement.6"), //$NON-NLS-1$
1070
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1071        }
1072
1073        return namedParamInfo.index + 1; // JDBC indices are 1-based
1074
}
1075
1076    /**
1077     * @see java.sql.CallableStatement#getObject(int)
1078     */

1079    public synchronized Object JavaDoc getObject(int parameterIndex)
1080            throws SQLException JavaDoc {
1081        CallableStatementParam paramDescriptor = checkIsOutputParam(parameterIndex);
1082
1083        ResultSet rs = getOutputParameters(parameterIndex);
1084
1085        Object JavaDoc retVal = rs.getObjectStoredProc(
1086                mapOutputParameterIndexToRsIndex(parameterIndex),
1087                paramDescriptor.desiredJdbcType);
1088
1089        this.outputParamWasNull = rs.wasNull();
1090
1091        return retVal;
1092    }
1093
1094    /**
1095     * @see java.sql.CallableStatement#getObject(int, java.util.Map)
1096     */

1097    public synchronized Object JavaDoc getObject(int parameterIndex, Map JavaDoc map)
1098            throws SQLException JavaDoc {
1099        ResultSet rs = getOutputParameters(parameterIndex);
1100
1101        Object JavaDoc retVal = rs.getObject(
1102                mapOutputParameterIndexToRsIndex(parameterIndex), map);
1103
1104        this.outputParamWasNull = rs.wasNull();
1105
1106        return retVal;
1107    }
1108
1109    /**
1110     * @see java.sql.CallableStatement#getObject(java.lang.String)
1111     */

1112    public synchronized Object JavaDoc getObject(String JavaDoc parameterName)
1113            throws SQLException JavaDoc {
1114        ResultSet rs = getOutputParameters(0); // definitely not going to be
1115
// from ?=
1116

1117        Object JavaDoc retValue = rs.getObject(fixParameterName(parameterName));
1118
1119        this.outputParamWasNull = rs.wasNull();
1120
1121        return retValue;
1122    }
1123
1124    /**
1125     * @see java.sql.CallableStatement#getObject(java.lang.String,
1126     * java.util.Map)
1127     */

1128    public synchronized Object JavaDoc getObject(String JavaDoc parameterName, Map JavaDoc map)
1129            throws SQLException JavaDoc {
1130        ResultSet rs = getOutputParameters(0); // definitely not going to be
1131
// from ?=
1132

1133        Object JavaDoc retValue = rs.getObject(fixParameterName(parameterName), map);
1134
1135        this.outputParamWasNull = rs.wasNull();
1136
1137        return retValue;
1138    }
1139
1140    /**
1141     * Returns the ResultSet that holds the output parameters, or throws an
1142     * appropriate exception if none exist, or they weren't returned.
1143     *
1144     * @return the ResultSet that holds the output parameters
1145     *
1146     * @throws SQLException
1147     * if no output parameters were defined, or if no output
1148     * parameters were returned.
1149     */

1150    private ResultSet getOutputParameters(int paramIndex) throws SQLException JavaDoc {
1151        this.outputParamWasNull = false;
1152
1153        if (paramIndex == 1 && this.callingStoredFunction
1154                && this.returnValueParam != null) {
1155            return this.functionReturnValueResults;
1156        }
1157
1158        if (this.outputParameterResults == null) {
1159            if (this.paramInfo.numberOfParameters() == 0) {
1160                throw new SQLException JavaDoc(Messages
1161                        .getString("CallableStatement.7"), //$NON-NLS-1$
1162
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1163            }
1164            throw new SQLException JavaDoc(Messages.getString("CallableStatement.8"), //$NON-NLS-1$
1165
SQLError.SQL_STATE_GENERAL_ERROR);
1166        }
1167
1168        return this.outputParameterResults;
1169
1170    }
1171
1172    /**
1173     * @see java.sql.CallableStatement#getRef(int)
1174     */

1175    public synchronized Ref JavaDoc getRef(int parameterIndex) throws SQLException JavaDoc {
1176        ResultSet rs = getOutputParameters(parameterIndex);
1177
1178        Ref JavaDoc retValue = rs
1179                .getRef(mapOutputParameterIndexToRsIndex(parameterIndex));
1180
1181        this.outputParamWasNull = rs.wasNull();
1182
1183        return retValue;
1184    }
1185
1186    /**
1187     * @see java.sql.CallableStatement#getRef(java.lang.String)
1188     */

1189    public synchronized Ref JavaDoc getRef(String JavaDoc parameterName) throws SQLException JavaDoc {
1190        ResultSet rs = getOutputParameters(0); // definitely not going to be
1191
// from ?=
1192

1193        Ref JavaDoc retValue = rs.getRef(fixParameterName(parameterName));
1194
1195        this.outputParamWasNull = rs.wasNull();
1196
1197        return retValue;
1198    }
1199
1200    /**
1201     * @see java.sql.CallableStatement#getShort(int)
1202     */

1203    public synchronized short getShort(int parameterIndex) throws SQLException JavaDoc {
1204        ResultSet rs = getOutputParameters(parameterIndex);
1205
1206        short retValue = rs
1207                .getShort(mapOutputParameterIndexToRsIndex(parameterIndex));
1208
1209        this.outputParamWasNull = rs.wasNull();
1210
1211        return retValue;
1212    }
1213
1214    /**
1215     * @see java.sql.CallableStatement#getShort(java.lang.String)
1216     */

1217    public synchronized short getShort(String JavaDoc parameterName)
1218            throws SQLException JavaDoc {
1219        ResultSet rs = getOutputParameters(0); // definitely not going to be
1220
// from ?=
1221

1222        short retValue = rs.getShort(fixParameterName(parameterName));
1223
1224        this.outputParamWasNull = rs.wasNull();
1225
1226        return retValue;
1227    }
1228
1229    /**
1230     * @see java.sql.CallableStatement#getString(int)
1231     */

1232    public synchronized String JavaDoc getString(int parameterIndex)
1233            throws SQLException JavaDoc {
1234        ResultSet rs = getOutputParameters(parameterIndex);
1235
1236        String JavaDoc retValue = rs
1237                .getString(mapOutputParameterIndexToRsIndex(parameterIndex));
1238
1239        this.outputParamWasNull = rs.wasNull();
1240
1241        return retValue;
1242    }
1243
1244    /**
1245     * @see java.sql.CallableStatement#getString(java.lang.String)
1246     */

1247    public synchronized String JavaDoc getString(String JavaDoc parameterName)
1248            throws SQLException JavaDoc {
1249        ResultSet rs = getOutputParameters(0); // definitely not going to be
1250
// from ?=
1251

1252        String JavaDoc retValue = rs.getString(fixParameterName(parameterName));
1253
1254        this.outputParamWasNull = rs.wasNull();
1255
1256        return retValue;
1257    }
1258
1259    /**
1260     * @see java.sql.CallableStatement#getTime(int)
1261     */

1262    public synchronized Time JavaDoc getTime(int parameterIndex) throws SQLException JavaDoc {
1263        ResultSet rs = getOutputParameters(parameterIndex);
1264
1265        Time JavaDoc retValue = rs
1266                .getTime(mapOutputParameterIndexToRsIndex(parameterIndex));
1267
1268        this.outputParamWasNull = rs.wasNull();
1269
1270        return retValue;
1271    }
1272
1273    /**
1274     * @see java.sql.CallableStatement#getTime(int, java.util.Calendar)
1275     */

1276    public synchronized Time JavaDoc getTime(int parameterIndex, Calendar JavaDoc cal)
1277            throws SQLException JavaDoc {
1278        ResultSet rs = getOutputParameters(parameterIndex);
1279
1280        Time JavaDoc retValue = rs.getTime(
1281                mapOutputParameterIndexToRsIndex(parameterIndex), cal);
1282
1283        this.outputParamWasNull = rs.wasNull();
1284
1285        return retValue;
1286    }
1287
1288    /**
1289     * @see java.sql.CallableStatement#getTime(java.lang.String)
1290     */

1291    public synchronized Time JavaDoc getTime(String JavaDoc parameterName) throws SQLException JavaDoc {
1292        ResultSet rs = getOutputParameters(0); // definitely not going to be
1293
// from ?=
1294

1295        Time JavaDoc retValue = rs.getTime(fixParameterName(parameterName));
1296
1297        this.outputParamWasNull = rs.wasNull();
1298
1299        return retValue;
1300    }
1301
1302    /**
1303     * @see java.sql.CallableStatement#getTime(java.lang.String,
1304     * java.util.Calendar)
1305     */

1306    public synchronized Time JavaDoc getTime(String JavaDoc parameterName, Calendar JavaDoc cal)
1307            throws SQLException JavaDoc {
1308        ResultSet rs = getOutputParameters(0); // definitely not going to be
1309
// from ?=
1310

1311        Time JavaDoc retValue = rs.getTime(fixParameterName(parameterName), cal);
1312
1313        this.outputParamWasNull = rs.wasNull();
1314
1315        return retValue;
1316    }
1317
1318    /**
1319     * @see java.sql.CallableStatement#getTimestamp(int)
1320     */

1321    public synchronized Timestamp JavaDoc getTimestamp(int parameterIndex)
1322            throws SQLException JavaDoc {
1323        ResultSet rs = getOutputParameters(parameterIndex);
1324
1325        Timestamp JavaDoc retValue = rs
1326                .getTimestamp(mapOutputParameterIndexToRsIndex(parameterIndex));
1327
1328        this.outputParamWasNull = rs.wasNull();
1329
1330        return retValue;
1331    }
1332
1333    /**
1334     * @see java.sql.CallableStatement#getTimestamp(int, java.util.Calendar)
1335     */

1336    public synchronized Timestamp JavaDoc getTimestamp(int parameterIndex, Calendar JavaDoc cal)
1337            throws SQLException JavaDoc {
1338        ResultSet rs = getOutputParameters(parameterIndex);
1339
1340        Timestamp JavaDoc retValue = rs.getTimestamp(
1341                mapOutputParameterIndexToRsIndex(parameterIndex), cal);
1342
1343        this.outputParamWasNull = rs.wasNull();
1344
1345        return retValue;
1346    }
1347
1348    /**
1349     * @see java.sql.CallableStatement#getTimestamp(java.lang.String)
1350     */

1351    public synchronized Timestamp JavaDoc getTimestamp(String JavaDoc parameterName)
1352            throws SQLException JavaDoc {
1353        ResultSet rs = getOutputParameters(0); // definitely not going to be
1354
// from ?=
1355

1356        Timestamp JavaDoc retValue = rs.getTimestamp(fixParameterName(parameterName));
1357
1358        this.outputParamWasNull = rs.wasNull();
1359
1360        return retValue;
1361    }
1362
1363    /**
1364     * @see java.sql.CallableStatement#getTimestamp(java.lang.String,
1365     * java.util.Calendar)
1366     */

1367    public synchronized Timestamp JavaDoc getTimestamp(String JavaDoc parameterName,
1368            Calendar JavaDoc cal) throws SQLException JavaDoc {
1369        ResultSet rs = getOutputParameters(0); // definitely not going to be
1370
// from ?=
1371

1372        Timestamp JavaDoc retValue = rs.getTimestamp(fixParameterName(parameterName),
1373                cal);
1374
1375        this.outputParamWasNull = rs.wasNull();
1376
1377        return retValue;
1378    }
1379
1380    /**
1381     * @see java.sql.CallableStatement#getURL(int)
1382     */

1383    public synchronized URL JavaDoc getURL(int parameterIndex) throws SQLException JavaDoc {
1384        ResultSet rs = getOutputParameters(parameterIndex);
1385
1386        URL JavaDoc retValue = rs
1387                .getURL(mapOutputParameterIndexToRsIndex(parameterIndex));
1388
1389        this.outputParamWasNull = rs.wasNull();
1390
1391        return retValue;
1392    }
1393
1394    /**
1395     * @see java.sql.CallableStatement#getURL(java.lang.String)
1396     */

1397    public synchronized URL JavaDoc getURL(String JavaDoc parameterName) throws SQLException JavaDoc {
1398        ResultSet rs = getOutputParameters(0); // definitely not going to be
1399
// from ?=
1400

1401        URL JavaDoc retValue = rs.getURL(fixParameterName(parameterName));
1402
1403        this.outputParamWasNull = rs.wasNull();
1404
1405        return retValue;
1406    }
1407
1408    private int mapOutputParameterIndexToRsIndex(int paramIndex)
1409            throws SQLException JavaDoc {
1410
1411        if (this.returnValueParam != null && paramIndex == 1) {
1412            return 1;
1413        }
1414
1415        checkParameterIndexBounds(paramIndex);
1416
1417        int localParamIndex = paramIndex - 1;
1418
1419        int rsIndex = this.parameterIndexToRsIndex[localParamIndex];
1420
1421        if (rsIndex == NOT_OUTPUT_PARAMETER_INDICATOR) {
1422            throw new SQLException JavaDoc(
1423                    Messages.getString("CallableStatement.21") + paramIndex //$NON-NLS-1$
1424
+ Messages.getString("CallableStatement.22"), //$NON-NLS-1$
1425
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1426        }
1427
1428        return rsIndex + 1;
1429    }
1430
1431    /**
1432     * @see java.sql.CallableStatement#registerOutParameter(int, int)
1433     */

1434    public void registerOutParameter(int parameterIndex, int sqlType)
1435            throws SQLException JavaDoc {
1436        CallableStatementParam paramDescriptor = checkIsOutputParam(parameterIndex);
1437        paramDescriptor.desiredJdbcType = sqlType;
1438    }
1439
1440    /**
1441     * @see java.sql.CallableStatement#registerOutParameter(int, int, int)
1442     */

1443    public void registerOutParameter(int parameterIndex, int sqlType, int scale)
1444            throws SQLException JavaDoc {
1445        registerOutParameter(parameterIndex, sqlType);
1446    }
1447
1448    /**
1449     * @see java.sql.CallableStatement#registerOutParameter(int, int,
1450     * java.lang.String)
1451     */

1452    public void registerOutParameter(int parameterIndex, int sqlType,
1453            String JavaDoc typeName) throws SQLException JavaDoc {
1454        checkIsOutputParam(parameterIndex);
1455    }
1456
1457    /**
1458     * @see java.sql.CallableStatement#registerOutParameter(java.lang.String,
1459     * int)
1460     */

1461    public synchronized void registerOutParameter(String JavaDoc parameterName,
1462            int sqlType) throws SQLException JavaDoc {
1463        registerOutParameter(getNamedParamIndex(parameterName, true), sqlType);
1464    }
1465
1466    /**
1467     * @see java.sql.CallableStatement#registerOutParameter(java.lang.String,
1468     * int, int)
1469     */

1470    public void registerOutParameter(String JavaDoc parameterName, int sqlType,
1471            int scale) throws SQLException JavaDoc {
1472        registerOutParameter(getNamedParamIndex(parameterName, true), sqlType);
1473    }
1474
1475    /**
1476     * @see java.sql.CallableStatement#registerOutParameter(java.lang.String,
1477     * int, java.lang.String)
1478     */

1479    public void registerOutParameter(String JavaDoc parameterName, int sqlType,
1480            String JavaDoc typeName) throws SQLException JavaDoc {
1481        registerOutParameter(getNamedParamIndex(parameterName, true), sqlType,
1482                typeName);
1483    }
1484
1485    /**
1486     * Issues a second query to retrieve all output parameters.
1487     *
1488     * @throws SQLException
1489     * if an error occurs.
1490     */

1491    private void retrieveOutParams() throws SQLException JavaDoc {
1492        int numParameters = this.paramInfo.numberOfParameters();
1493
1494        this.parameterIndexToRsIndex = new int[numParameters];
1495
1496        for (int i = 0; i < numParameters; i++) {
1497            this.parameterIndexToRsIndex[i] = NOT_OUTPUT_PARAMETER_INDICATOR;
1498        }
1499
1500        int localParamIndex = 0;
1501
1502        if (numParameters > 0) {
1503            StringBuffer JavaDoc outParameterQuery = new StringBuffer JavaDoc("SELECT "); //$NON-NLS-1$
1504

1505            boolean firstParam = true;
1506            boolean hadOutputParams = false;
1507
1508            for (Iterator JavaDoc paramIter = this.paramInfo.iterator(); paramIter
1509                    .hasNext();) {
1510                CallableStatementParam retrParamInfo = (CallableStatementParam) paramIter
1511                        .next();
1512
1513                if (retrParamInfo.isOut) {
1514                    hadOutputParams = true;
1515
1516                    this.parameterIndexToRsIndex[retrParamInfo.index] = localParamIndex++;
1517
1518                    String JavaDoc outParameterName = mangleParameterName(retrParamInfo.paramName);
1519
1520                    if (!firstParam) {
1521                        outParameterQuery.append(","); //$NON-NLS-1$
1522
} else {
1523                        firstParam = false;
1524                    }
1525
1526                    if (!outParameterName.startsWith("@")) { //$NON-NLS-1$
1527
outParameterQuery.append('@');
1528                    }
1529
1530                    outParameterQuery.append(outParameterName);
1531                }
1532            }
1533
1534            if (hadOutputParams) {
1535                // We can't use 'ourself' to execute this query, or any
1536
// pending result sets would be overwritten
1537
java.sql.Statement JavaDoc outParameterStmt = null;
1538                java.sql.ResultSet JavaDoc outParamRs = null;
1539
1540                try {
1541                    outParameterStmt = this.connection.createStatement();
1542                    outParamRs = outParameterStmt
1543                            .executeQuery(outParameterQuery.toString());
1544                    this.outputParameterResults = ((com.mysql.jdbc.ResultSet) outParamRs)
1545                            .copy();
1546
1547                    if (!this.outputParameterResults.next()) {
1548                        this.outputParameterResults.close();
1549                        this.outputParameterResults = null;
1550                    }
1551                } finally {
1552                    if (outParameterStmt != null) {
1553                        outParameterStmt.close();
1554                    }
1555                }
1556            } else {
1557                this.outputParameterResults = null;
1558            }
1559        } else {
1560            this.outputParameterResults = null;
1561        }
1562    }
1563
1564    /**
1565     * @see java.sql.CallableStatement#setAsciiStream(java.lang.String,
1566     * java.io.InputStream, int)
1567     */

1568    public void setAsciiStream(String JavaDoc parameterName, InputStream JavaDoc x, int length)
1569            throws SQLException JavaDoc {
1570        setAsciiStream(getNamedParamIndex(parameterName, false), x, length);
1571    }
1572
1573    /**
1574     * @see java.sql.CallableStatement#setBigDecimal(java.lang.String,
1575     * java.math.BigDecimal)
1576     */

1577    public void setBigDecimal(String JavaDoc parameterName, BigDecimal JavaDoc x)
1578            throws SQLException JavaDoc {
1579        setBigDecimal(getNamedParamIndex(parameterName, false), x);
1580    }
1581
1582    /**
1583     * @see java.sql.CallableStatement#setBinaryStream(java.lang.String,
1584     * java.io.InputStream, int)
1585     */

1586    public void setBinaryStream(String JavaDoc parameterName, InputStream JavaDoc x, int length)
1587            throws SQLException JavaDoc {
1588        setBinaryStream(getNamedParamIndex(parameterName, false), x, length);
1589    }
1590
1591    /**
1592     * @see java.sql.CallableStatement#setBoolean(java.lang.String, boolean)
1593     */

1594    public void setBoolean(String JavaDoc parameterName, boolean x) throws SQLException JavaDoc {
1595        setBoolean(getNamedParamIndex(parameterName, false), x);
1596    }
1597
1598    /**
1599     * @see java.sql.CallableStatement#setByte(java.lang.String, byte)
1600     */

1601    public void setByte(String JavaDoc parameterName, byte x) throws SQLException JavaDoc {
1602        setByte(getNamedParamIndex(parameterName, false), x);
1603    }
1604
1605    /**
1606     * @see java.sql.CallableStatement#setBytes(java.lang.String, byte[])
1607     */

1608    public void setBytes(String JavaDoc parameterName, byte[] x) throws SQLException JavaDoc {
1609        setBytes(getNamedParamIndex(parameterName, false), x);
1610    }
1611
1612    /**
1613     * @see java.sql.CallableStatement#setCharacterStream(java.lang.String,
1614     * java.io.Reader, int)
1615     */

1616    public void setCharacterStream(String JavaDoc parameterName, Reader JavaDoc reader,
1617            int length) throws SQLException JavaDoc {
1618        setCharacterStream(getNamedParamIndex(parameterName, false), reader,
1619                length);
1620    }
1621
1622    /**
1623     * @see java.sql.CallableStatement#setDate(java.lang.String, java.sql.Date)
1624     */

1625    public void setDate(String JavaDoc parameterName, Date JavaDoc x) throws SQLException JavaDoc {
1626        setDate(getNamedParamIndex(parameterName, false), x);
1627    }
1628
1629    /**
1630     * @see java.sql.CallableStatement#setDate(java.lang.String, java.sql.Date,
1631     * java.util.Calendar)
1632     */

1633    public void setDate(String JavaDoc parameterName, Date JavaDoc x, Calendar JavaDoc cal)
1634            throws SQLException JavaDoc {
1635        setDate(getNamedParamIndex(parameterName, false), x, cal);
1636    }
1637
1638    /**
1639     * @see java.sql.CallableStatement#setDouble(java.lang.String, double)
1640     */

1641    public void setDouble(String JavaDoc parameterName, double x) throws SQLException JavaDoc {
1642        setDouble(getNamedParamIndex(parameterName, false), x);
1643    }
1644
1645    /**
1646     * @see java.sql.CallableStatement#setFloat(java.lang.String, float)
1647     */

1648    public void setFloat(String JavaDoc parameterName, float x) throws SQLException JavaDoc {
1649        setFloat(getNamedParamIndex(parameterName, false), x);
1650    }
1651
1652    /**
1653     *
1654     */

1655    private void setInOutParamsOnServer() throws SQLException JavaDoc {
1656        if (this.paramInfo.numParameters > 0) {
1657            int parameterIndex = 0;
1658
1659            for (Iterator JavaDoc paramIter = this.paramInfo.iterator(); paramIter
1660                    .hasNext();) {
1661
1662                CallableStatementParam inParamInfo = (CallableStatementParam) paramIter
1663                        .next();
1664
1665                if (inParamInfo.isOut && inParamInfo.isIn) {
1666                    String JavaDoc inOutParameterName = mangleParameterName(inParamInfo.paramName);
1667                    StringBuffer JavaDoc queryBuf = new StringBuffer JavaDoc(
1668                            4 + inOutParameterName.length() + 1 + 1);
1669                    queryBuf.append("SET "); //$NON-NLS-1$
1670
queryBuf.append(inOutParameterName);
1671                    queryBuf.append("=?"); //$NON-NLS-1$
1672

1673                    PreparedStatement setPstmt = null;
1674
1675                    try {
1676                        setPstmt = this.connection
1677                                .clientPrepareStatement(queryBuf.toString());
1678
1679                        byte[] parameterAsBytes = this
1680                                .getBytesRepresentation(parameterIndex);
1681
1682                        if (parameterAsBytes != null) {
1683                            if (parameterAsBytes.length > 8
1684                                    && parameterAsBytes[0] == '_'
1685                                    && parameterAsBytes[1] == 'b'
1686                                    && parameterAsBytes[2] == 'i'
1687                                    && parameterAsBytes[3] == 'n'
1688                                    && parameterAsBytes[4] == 'a'
1689                                    && parameterAsBytes[5] == 'r'
1690                                    && parameterAsBytes[6] == 'y'
1691                                    && parameterAsBytes[7] == '\'') {
1692                                setPstmt.setBytesNoEscapeNoQuotes(1,
1693                                        parameterAsBytes);
1694                            } else {
1695                                setPstmt.setBytes(1, parameterAsBytes);
1696                            }
1697                        } else {
1698                            setPstmt.setNull(1, Types.NULL);
1699                        }
1700
1701                        setPstmt.executeUpdate();
1702                    } finally {
1703                        if (setPstmt != null) {
1704                            setPstmt.close();
1705                        }
1706                    }
1707
1708                    // StringBuffer fullName = new StringBuffer("@");
1709
// fullName.append(outParameterName);
1710
/*
1711                     * this.setBytesNoEscapeNoQuotes(paramInfo.index + 1,
1712                     * StringUtils.getBytes(outParameterName,
1713                     * this.charConverter, this.charEncoding,
1714                     * this.connection.getServerCharacterEncoding(),
1715                     * this.connection.parserKnowsUnicode()));
1716                     */

1717                }
1718            }
1719
1720            parameterIndex++;
1721        }
1722
1723    }
1724
1725    /**
1726     * @see java.sql.CallableStatement#setInt(java.lang.String, int)
1727     */

1728    public void setInt(String JavaDoc parameterName, int x) throws SQLException JavaDoc {
1729        setInt(getNamedParamIndex(parameterName, false), x);
1730    }
1731
1732    /**
1733     * @see java.sql.CallableStatement#setLong(java.lang.String, long)
1734     */

1735    public void setLong(String JavaDoc parameterName, long x) throws SQLException JavaDoc {
1736    }
1737
1738    /**
1739     * @see java.sql.CallableStatement#setNull(java.lang.String, int)
1740     */

1741    public void setNull(String JavaDoc parameterName, int sqlType) throws SQLException JavaDoc {
1742    }
1743
1744    /**
1745     * @see java.sql.CallableStatement#setNull(java.lang.String, int,
1746     * java.lang.String)
1747     */

1748    public void setNull(String JavaDoc parameterName, int sqlType, String JavaDoc typeName)
1749            throws SQLException JavaDoc {
1750    }
1751
1752    /**
1753     * @see java.sql.CallableStatement#setObject(java.lang.String,
1754     * java.lang.Object)
1755     */

1756    public void setObject(String JavaDoc parameterName, Object JavaDoc x) throws SQLException JavaDoc {
1757        setObject(getNamedParamIndex(parameterName, false), x);
1758    }
1759
1760    /**
1761     * @see java.sql.CallableStatement#setObject(java.lang.String,
1762     * java.lang.Object, int)
1763     */

1764    public void setObject(String JavaDoc parameterName, Object JavaDoc x, int targetSqlType)
1765            throws SQLException JavaDoc {
1766        setObject(getNamedParamIndex(parameterName, false), x, targetSqlType);
1767    }
1768
1769    /**
1770     * @see java.sql.CallableStatement#setObject(java.lang.String,
1771     * java.lang.Object, int, int)
1772     */

1773    public void setObject(String JavaDoc parameterName, Object JavaDoc x, int targetSqlType,
1774            int scale) throws SQLException JavaDoc {
1775    }
1776
1777    private void setOutParams() throws SQLException JavaDoc {
1778        if (this.paramInfo.numParameters > 0) {
1779            for (Iterator JavaDoc paramIter = this.paramInfo.iterator(); paramIter
1780                    .hasNext();) {
1781                CallableStatementParam outParamInfo = (CallableStatementParam) paramIter
1782                        .next();
1783
1784                if (outParamInfo.isOut) {
1785                    String JavaDoc outParameterName = mangleParameterName(outParamInfo.paramName);
1786
1787                    this.setBytesNoEscapeNoQuotes(outParamInfo.index + 1,
1788                            StringUtils.getBytes(outParameterName,
1789                                    this.charConverter, this.charEncoding,
1790                                    this.connection
1791                                            .getServerCharacterEncoding(),
1792                                    this.connection.parserKnowsUnicode()));
1793                }
1794            }
1795        }
1796    }
1797
1798    /**
1799     * @see java.sql.CallableStatement#setShort(java.lang.String, short)
1800     */

1801    public void setShort(String JavaDoc parameterName, short x) throws SQLException JavaDoc {
1802        setShort(getNamedParamIndex(parameterName, false), x);
1803    }
1804
1805    /**
1806     * @see java.sql.CallableStatement#setString(java.lang.String,
1807     * java.lang.String)
1808     */

1809    public void setString(String JavaDoc parameterName, String JavaDoc x) throws SQLException JavaDoc {
1810        setString(getNamedParamIndex(parameterName, false), x);
1811    }
1812
1813    /**
1814     * @see java.sql.CallableStatement#setTime(java.lang.String, java.sql.Time)
1815     */

1816    public void setTime(String JavaDoc parameterName, Time JavaDoc x) throws SQLException JavaDoc {
1817        setTime(getNamedParamIndex(parameterName, false), x);
1818    }
1819
1820    /**
1821     * @see java.sql.CallableStatement#setTime(java.lang.String, java.sql.Time,
1822     * java.util.Calendar)
1823     */

1824    public void setTime(String JavaDoc parameterName, Time JavaDoc x, Calendar JavaDoc cal)
1825            throws SQLException JavaDoc {
1826        setTime(getNamedParamIndex(parameterName, false), x, cal);
1827    }
1828
1829    /**
1830     * @see java.sql.CallableStatement#setTimestamp(java.lang.String,
1831     * java.sql.Timestamp)
1832     */

1833    public void setTimestamp(String JavaDoc parameterName, Timestamp JavaDoc x)
1834            throws SQLException JavaDoc {
1835        setTimestamp(getNamedParamIndex(parameterName, false), x);
1836    }
1837
1838    /**
1839     * @see java.sql.CallableStatement#setTimestamp(java.lang.String,
1840     * java.sql.Timestamp, java.util.Calendar)
1841     */

1842    public void setTimestamp(String JavaDoc parameterName, Timestamp JavaDoc x, Calendar JavaDoc cal)
1843            throws SQLException JavaDoc {
1844        setTimestamp(getNamedParamIndex(parameterName, false), x, cal);
1845    }
1846
1847    /**
1848     * @see java.sql.CallableStatement#setURL(java.lang.String, java.net.URL)
1849     */

1850    public void setURL(String JavaDoc parameterName, URL JavaDoc val) throws SQLException JavaDoc {
1851        setURL(getNamedParamIndex(parameterName, false), val);
1852    }
1853
1854    /**
1855     * @see java.sql.CallableStatement#wasNull()
1856     */

1857    public synchronized boolean wasNull() throws SQLException JavaDoc {
1858        return this.outputParamWasNull;
1859    }
1860}
1861
Popular Tags