1 | /* |
2 | Copyright (C) 2002-2005 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 | package com.mysql.jdbc; |
24 | |
25 | import java.io.InputStream; |
26 | import java.io.Reader; |
27 | |
28 | import java.math.BigDecimal; |
29 | |
30 | import java.net.URL; |
31 | |
32 | import java.sql.Array; |
33 | import java.sql.Blob; |
34 | import java.sql.Clob; |
35 | import java.sql.Date; |
36 | import java.sql.ParameterMetaData; |
37 | import java.sql.Ref; |
38 | import java.sql.SQLException; |
39 | import java.sql.Time; |
40 | import java.sql.Timestamp; |
41 | import java.sql.Types; |
42 | |
43 | import java.util.ArrayList; |
44 | import java.util.Calendar; |
45 | import java.util.HashMap; |
46 | import java.util.Iterator; |
47 | import java.util.List; |
48 | import java.util.Locale; |
49 | import java.util.Map; |
50 | |
51 | /** |
52 | * Representation of stored procedures for JDBC |
53 | * |
54 | * @author Mark Matthews |
55 | * @version $Id: CallableStatement.java,v 1.1.2.1 2005/05/13 18:58:38 mmatthews |
56 | * Exp $ |
57 | */ |
58 | public class CallableStatement extends PreparedStatement implements |
59 | java.sql.CallableStatement { |
60 | class CallableStatementParam { |
61 | int desiredJdbcType; |
62 | |
63 | int index; |
64 | |
65 | int inOutModifier; |
66 | |
67 | boolean isIn; |
68 | |
69 | boolean isOut; |
70 | |
71 | int jdbcType; |
72 | |
73 | short nullability; |
74 | |
75 | String paramName; |
76 | |
77 | int precision; |
78 | |
79 | int scale; |
80 | |
81 | String typeName; |
82 | |
83 | CallableStatementParam(String name, int idx, boolean in, boolean out, |
84 | int jdbcType, String typeName, int precision, int scale, |
85 | short nullability, int inOutModifier) { |
86 | this.paramName = name; |
87 | this.isIn = in; |
88 | this.isOut = out; |
89 | this.index = idx; |
90 | |
91 | this.jdbcType = jdbcType; |
92 | this.typeName = typeName; |
93 | this.precision = precision; |
94 | this.scale = scale; |
95 | this.nullability = nullability; |
96 | this.inOutModifier = inOutModifier; |
97 | } |
98 | |
99 | /* |
100 | * (non-Javadoc) |
101 | * |
102 | * @see java.lang.Object#clone() |
103 | */ |
104 | protected Object clone() throws CloneNotSupportedException { |
105 | return super.clone(); |
106 | } |
107 | } |
108 | |
109 | class CallableStatementParamInfo { |
110 | String catalogInUse; |
111 | |
112 | boolean isFunctionCall; |
113 | |
114 | String nativeSql; |
115 | |
116 | int numParameters; |
117 | |
118 | List parameterList; |
119 | |
120 | Map parameterMap; |
121 | |
122 | CallableStatementParamInfo(java.sql.ResultSet paramTypesRs) |
123 | throws SQLException { |
124 | boolean hadRows = paramTypesRs.last(); |
125 | |
126 | this.nativeSql = originalSql; |
127 | this.catalogInUse = currentCatalog; |
128 | isFunctionCall = callingStoredFunction; |
129 | |
130 | if (hadRows) { |
131 | this.numParameters = paramTypesRs.getRow(); |
132 | |
133 | this.parameterList = new ArrayList(this.numParameters); |
134 | this.parameterMap = new HashMap(this.numParameters); |
135 | |
136 | paramTypesRs.beforeFirst(); |
137 | |
138 | addParametersFromDBMD(paramTypesRs); |
139 | } else { |
140 | this.numParameters = 0; |
141 | } |
142 | } |
143 | |
144 | private void addParametersFromDBMD(java.sql.ResultSet paramTypesRs) |
145 | throws SQLException { |
146 | int i = 0; |
147 | |
148 | if (isFunctionCall) { |
149 | // first row will be return value parameter |
150 | paramTypesRs.next(); |
151 | } |
152 | |
153 | while (paramTypesRs.next()) { |
154 | String paramName = paramTypesRs.getString(4); |
155 | int inOutModifier = paramTypesRs.getInt(5); |
156 | |
157 | boolean isOutParameter = false; |
158 | boolean isInParameter = false; |
159 | |
160 | if (inOutModifier == DatabaseMetaData.procedureColumnInOut) { |
161 | isOutParameter = true; |
162 | isInParameter = true; |
163 | } else if (inOutModifier == DatabaseMetaData.procedureColumnIn) { |
164 | isOutParameter = false; |
165 | isInParameter = true; |
166 | } else if (inOutModifier == DatabaseMetaData.procedureColumnOut) { |
167 | isOutParameter = true; |
168 | isInParameter = false; |
169 | } |
170 | |
171 | int jdbcType = paramTypesRs.getInt(6); |
172 | String typeName = paramTypesRs.getString(7); |
173 | int precision = paramTypesRs.getInt(8); |
174 | int scale = paramTypesRs.getInt(10); |
175 | short nullability = paramTypesRs.getShort(12); |
176 | |
177 | CallableStatementParam paramInfoToAdd = new CallableStatementParam( |
178 | paramName, i++, isInParameter, isOutParameter, |
179 | jdbcType, typeName, precision, scale, nullability, |
180 | inOutModifier); |
181 | |
182 | this.parameterList.add(paramInfoToAdd); |
183 | this.parameterMap.put(paramName, paramInfoToAdd); |
184 | } |
185 | } |
186 | |
187 | protected void checkBounds(int paramIndex) throws SQLException { |
188 | int localParamIndex = paramIndex - 1; |
189 | |
190 | if ((paramIndex < 0) || (localParamIndex >= this.numParameters)) { |
191 | throw SQLError.createSQLException( |
192 | Messages.getString("CallableStatement.11") + paramIndex //$NON-NLS-1$ |
193 | + Messages.getString("CallableStatement.12") + numParameters //$NON-NLS-1$ |
194 | + Messages.getString("CallableStatement.13"), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ |
195 | } |
196 | } |
197 | |
198 | /* |
199 | * (non-Javadoc) |
200 | * |
201 | * @see java.lang.Object#clone() |
202 | */ |
203 | protected Object clone() throws CloneNotSupportedException { |
204 | // TODO Auto-generated method stub |
205 | return super.clone(); |
206 | } |
207 | |
208 | CallableStatementParam getParameter(int index) { |
209 | return (CallableStatementParam) this.parameterList.get(index); |
210 | } |
211 | |
212 | CallableStatementParam getParameter(String name) { |
213 | return (CallableStatementParam) this.parameterMap.get(name); |
214 | } |
215 | |
216 | public String getParameterClassName(int arg0) throws SQLException { |
217 | String mysqlTypeName = getParameterTypeName(arg0); |
218 | |
219 | boolean isBinaryOrBlob = StringUtils.indexOfIgnoreCase(mysqlTypeName, "BLOB") != -1 || |
220 | StringUtils.indexOfIgnoreCase(mysqlTypeName, "BINARY") != -1; |
221 | |
222 | boolean isUnsigned = StringUtils.indexOfIgnoreCase(mysqlTypeName, "UNSIGNED") != -1; |
223 | |
224 | int mysqlTypeIfKnown = 0; |
225 | |
226 | if (StringUtils.startsWithIgnoreCase(mysqlTypeName, "MEDIUMINT")) { |
227 | mysqlTypeIfKnown = MysqlDefs.FIELD_TYPE_INT24; |
228 | } |
229 | |
230 | return ResultSetMetaData.getClassNameForJavaType(getParameterType(arg0), |
231 | isUnsigned, mysqlTypeIfKnown, isBinaryOrBlob, false); |
232 | } |
233 | |
234 | public int getParameterCount() throws SQLException { |
235 | if (this.parameterList == null) { |
236 | return 0; |
237 | } |
238 | |
239 | return this.parameterList.size(); |
240 | } |
241 | |
242 | public int getParameterMode(int arg0) throws SQLException { |
243 | checkBounds(arg0); |
244 | |
245 | return getParameter(arg0 - 1).inOutModifier; |
246 | } |
247 | |
248 | public int getParameterType(int arg0) throws SQLException { |
249 | checkBounds(arg0); |
250 | |
251 | return getParameter(arg0 - 1).jdbcType; |
252 | } |
253 | |
254 | public String getParameterTypeName(int arg0) throws SQLException { |
255 | checkBounds(arg0); |
256 | |
257 | return getParameter(arg0 - 1).typeName; |
258 | } |
259 | |
260 | public int getPrecision(int arg0) throws SQLException { |
261 | checkBounds(arg0); |
262 | |
263 | return getParameter(arg0 - 1).precision; |
264 | } |
265 | |
266 | public int getScale(int arg0) throws SQLException { |
267 | checkBounds(arg0); |
268 | |
269 | return getParameter(arg0 - 1).scale; |
270 | } |
271 | |
272 | public int isNullable(int arg0) throws SQLException { |
273 | checkBounds(arg0); |
274 | |
275 | return getParameter(arg0 - 1).nullability; |
276 | } |
277 | |
278 | public boolean isSigned(int arg0) throws SQLException { |
279 | checkBounds(arg0); |
280 | |
281 | return false; |
282 | } |
283 | |
284 | Iterator iterator() { |
285 | return this.parameterList.iterator(); |
286 | } |
287 | |
288 | int numberOfParameters() { |
289 | return this.numParameters; |
290 | } |
291 | } |
292 | |
293 | /** |
294 | * Can't implement this directly, as then you can't use callable statements |
295 | * on JDK-1.3.1, which unfortunately isn't EOL'd yet, and still present |
296 | * quite a bit out there in the wild (Websphere, FreeBSD, anyone?) |
297 | */ |
298 | |
299 | class CallableStatementParamInfoJDBC3 extends CallableStatementParamInfo |
300 | implements ParameterMetaData { |
301 | |
302 | CallableStatementParamInfoJDBC3(java.sql.ResultSet paramTypesRs) |
303 | throws SQLException { |
304 | super(paramTypesRs); |
305 | } |
306 | } |
307 | |
308 | private final static int NOT_OUTPUT_PARAMETER_INDICATOR = Integer.MIN_VALUE; |
309 | |
310 | private final static String PARAMETER_NAMESPACE_PREFIX = "@com_mysql_jdbc_outparam_"; //$NON-NLS-1$ |
311 | |
312 | private static String mangleParameterName(String origParameterName) { |
313 | if (origParameterName == null) { |
314 | return null; |
315 | } |
316 | |
317 | int offset = 0; |
318 | |
319 | if (origParameterName.length() > 0 |
320 | && origParameterName.charAt(0) == '@') { |
321 | offset = 1; |
322 | } |
323 | |
324 | StringBuffer paramNameBuf = new StringBuffer(PARAMETER_NAMESPACE_PREFIX |
325 | .length() |
326 | + origParameterName.length()); |
327 | paramNameBuf.append(PARAMETER_NAMESPACE_PREFIX); |
328 | paramNameBuf.append(origParameterName.substring(offset)); |
329 | |
330 | return paramNameBuf.toString(); |
331 | } |
332 | |
333 | private boolean callingStoredFunction = false; |
334 | |
335 | private ResultSet functionReturnValueResults; |
336 | |
337 | private boolean hasOutputParams = false; |
338 | |
339 | // private List parameterList; |
340 | // private Map parameterMap; |
341 | private ResultSet outputParameterResults; |
342 | |
343 | private boolean outputParamWasNull = false; |
344 | |
345 | private int[] parameterIndexToRsIndex; |
346 | |
347 | protected CallableStatementParamInfo paramInfo; |
348 | |
349 | private CallableStatementParam returnValueParam; |
350 | |
351 | /** |
352 | * Creates a new CallableStatement |
353 | * |
354 | * @param conn |
355 | * the connection creating this statement |
356 | * @param paramInfo |
357 | * the SQL to prepare |
358 | * |
359 | * @throws SQLException |
360 | * if an error occurs |
361 | */ |
362 | public CallableStatement(Connection conn, |
363 | CallableStatementParamInfo paramInfo) throws SQLException { |
364 | super(conn, paramInfo.nativeSql, paramInfo.catalogInUse); |
365 | |
366 | this.paramInfo = paramInfo; |
367 | this.callingStoredFunction = this.paramInfo.isFunctionCall; |
368 | } |
369 | |
370 | /** |
371 | * Creates a new CallableStatement |
372 | * |
373 | * @param conn |
374 | * the connection creating this statement |
375 | * @param catalog |
376 | * catalog the current catalog |
377 | * |
378 | * @throws SQLException |
379 | * if an error occurs |
380 | */ |
381 | public CallableStatement(Connection conn, String catalog) |
382 | throws SQLException { |
383 | super(conn, catalog, null); |
384 | |
385 | determineParameterTypes(); |
386 | generateParameterMap(); |
387 | } |
388 | |
389 | private int[] placeholderToParameterIndexMap; |
390 | |
391 | private void generateParameterMap() throws SQLException { |
392 | // if the user specified some parameters as literals, we need to |
393 | // provide a map from the specified placeholders to the actual |
394 | // parameter numbers |
395 | |
396 | if (this.paramInfo != null && |
397 | this.parameterCount != this.paramInfo.getParameterCount()) { |
398 | this.placeholderToParameterIndexMap = new int[this.parameterCount]; |
399 | |
400 | int startPos = StringUtils.indexOfIgnoreCase(this.originalSql, |
401 | "CALL"); |
402 | if (startPos != -1) { |
403 | int parenOpenPos = this.originalSql.indexOf('(', startPos + 4); |
404 | |
405 | if (parenOpenPos != -1) { |
406 | int parenClosePos = StringUtils.indexOfIgnoreCaseRespectQuotes(parenOpenPos, |
407 | this.originalSql, ")", '\'', true); |
408 | |
409 | if (parenClosePos != -1) { |
410 | List parsedParameters = StringUtils.split(this.originalSql.substring(parenOpenPos + 1, parenClosePos), ",", "'\"", "'\"", true); |
411 | |
412 | int numParsedParameters = parsedParameters.size(); |
413 | |
414 | // sanity check |
415 | |
416 | if (numParsedParameters != this.parameterCount) { |
417 | // bail? |
418 | } |
419 | |
420 | int placeholderCount = 0; |
421 | |
422 | for (int i = 0; i < numParsedParameters; i++) { |
423 | if (((String)parsedParameters.get(i)).equals("?")) { |
424 | this.placeholderToParameterIndexMap[placeholderCount++] = i; |
425 | } |
426 | } |
427 | } |
428 | } |
429 | } |
430 | } |
431 | } |
432 | |
433 | /** |
434 | * Creates a new CallableStatement |
435 | * |
436 | * @param conn |
437 | * the connection creating this statement |
438 | * @param sql |
439 | * the SQL to prepare |
440 | * @param catalog |
441 | * the current catalog |
442 | * |
443 | * @throws SQLException |
444 | * if an error occurs |
445 | */ |
446 | public CallableStatement(Connection conn, String sql, String catalog, |
447 | boolean isFunctionCall) throws SQLException { |
448 | super(conn, sql, catalog); |
449 | |
450 | this.callingStoredFunction = isFunctionCall; |
451 | |
452 | determineParameterTypes(); |
453 | generateParameterMap(); |
454 | } |
455 | |
456 | /* |
457 | * (non-Javadoc) |
458 | * |
459 | * @see java.sql.PreparedStatement#addBatch() |
460 | */ |
461 | public void addBatch() throws SQLException { |
462 | setOutParams(); |
463 | |
464 | super.addBatch(); |
465 | } |
466 | |
467 | private CallableStatementParam checkIsOutputParam(int paramIndex) |
468 | throws SQLException { |
469 | |
470 | if (this.callingStoredFunction) { |
471 | if (paramIndex == 1) { |
472 | |
473 | if (this.returnValueParam == null) { |
474 | this.returnValueParam = new CallableStatementParam("", 0, |
475 | false, true, Types.VARCHAR, "VARCHAR", 0, 0, |
476 | DatabaseMetaData.attributeNullableUnknown, |
477 | DatabaseMetaData.procedureColumnReturn); |
478 | } |
479 | |
480 | return this.returnValueParam; |
481 | } |
482 | |
483 | // Move to position in output result set |
484 | paramIndex--; |
485 | } |
486 | |
487 | checkParameterIndexBounds(paramIndex); |
488 | |
489 | int localParamIndex = paramIndex - 1; |
490 | |
491 | if (this.placeholderToParameterIndexMap != null) { |
492 | localParamIndex = this.placeholderToParameterIndexMap[localParamIndex]; |
493 | } |
494 | |
495 | CallableStatementParam paramDescriptor = this.paramInfo |
496 | .getParameter(localParamIndex); |
497 | |
498 | if (!paramDescriptor.isOut) { |
499 | throw SQLError.createSQLException( |
500 | Messages.getString("CallableStatement.9") + paramIndex //$NON-NLS-1$ |
501 | + Messages.getString("CallableStatement.10"), //$NON-NLS-1$ |
502 | SQLError.SQL_STATE_ILLEGAL_ARGUMENT); |
503 | } |
504 | |
505 | this.hasOutputParams = true; |
506 | |
507 | return paramDescriptor; |
508 | } |
509 | |
510 | /** |
511 | * DOCUMENT ME! |
512 | * |
513 | * @param paramIndex |
514 | * |
515 | * @throws SQLException |
516 | */ |
517 | private void checkParameterIndexBounds(int paramIndex) throws SQLException { |
518 | this.paramInfo.checkBounds(paramIndex); |
519 | } |
520 | |
521 | /** |
522 | * Checks whether or not this statement is supposed to be providing |
523 | * streamable result sets...If output parameters are registered, the driver |
524 | * can not stream the results. |
525 | * |
526 | * @throws SQLException |
527 | * DOCUMENT ME! |
528 | */ |
529 | private void checkStreamability() throws SQLException { |
530 | if (this.hasOutputParams && createStreamingResultSet()) { |
531 | throw SQLError.createSQLException(Messages.getString("CallableStatement.14"), //$NON-NLS-1$ |
532 | SQLError.SQL_STATE_DRIVER_NOT_CAPABLE); |
533 | } |
534 | } |
535 | |
536 | public synchronized void clearParameters() throws SQLException { |
537 | super.clearParameters(); |
538 | |
539 | try { |
540 | if (this.outputParameterResults != null) { |
541 | this.outputParameterResults.close(); |
542 | } |
543 | } finally { |
544 | this.outputParameterResults = null; |
545 | } |
546 | } |
547 | |
548 | private void determineParameterTypes() throws SQLException { |
549 | java.sql.ResultSet paramTypesRs = null; |
550 | |
551 | try { |
552 | String procName = extractProcedureName(); |
553 | |
554 | java.sql.DatabaseMetaData dbmd = this.connection.getMetaData(); |
555 | |
556 | boolean useCatalog = false; |
557 | |
558 | if (procName.indexOf(".") == -1) { |
559 | useCatalog = true; |
560 | } |
561 | |
562 | paramTypesRs = dbmd.getProcedureColumns(this.connection |
563 | .versionMeetsMinimum(5, 0, 2) |
564 | & useCatalog ? this.currentCatalog : null, null, procName, |
565 | "%"); //$NON-NLS-1$ |
566 | |
567 | if (!this.connection.isRunningOnJDK13()) { |
568 | this.paramInfo = new CallableStatementParamInfoJDBC3( |
569 | paramTypesRs); |
570 | } else { |
571 | this.paramInfo = new CallableStatementParamInfo(paramTypesRs); |
572 | } |
573 | } finally { |
574 | SQLException sqlExRethrow = null; |
575 | |
576 | if (paramTypesRs != null) { |
577 | try { |
578 | paramTypesRs.close(); |
579 | } catch (SQLException sqlEx) { |
580 | sqlExRethrow = sqlEx; |
581 | } |
582 | |
583 | paramTypesRs = null; |
584 | } |
585 | |
586 | if (sqlExRethrow != null) { |
587 | throw sqlExRethrow; |
588 | } |
589 | } |
590 | } |
591 | |
592 | /* |
593 | * (non-Javadoc) |
594 | * |
595 | * @see java.sql.PreparedStatement#execute() |
596 | */ |
597 | public boolean execute() throws SQLException { |
598 | boolean returnVal = false; |
599 | |
600 | checkClosed(); |
601 | |
602 | checkStreamability(); |
603 | |
604 | synchronized (this.connection.getMutex()) { |
605 | setInOutParamsOnServer(); |
606 | setOutParams(); |
607 | |
608 | returnVal = super.execute(); |
609 | |
610 | if (this.callingStoredFunction) { |
611 | this.functionReturnValueResults = this.results; |
612 | this.functionReturnValueResults.next(); |
613 | this.results = null; |
614 | } |
615 | |
616 | retrieveOutParams(); |
617 | } |
618 | |
619 | if (!this.callingStoredFunction) { |
620 | return returnVal; |
621 | } |
622 | |
623 | // Functions can't return results |
624 | return false; |
625 | } |
626 | |
627 | /* |
628 | * (non-Javadoc) |
629 | * |
630 | * @see java.sql.PreparedStatement#executeQuery() |
631 | */ |
632 | public java.sql.ResultSet executeQuery() throws SQLException { |
633 | checkClosed(); |
634 | |
635 | checkStreamability(); |
636 | |
637 | java.sql.ResultSet execResults = null; |
638 | |
639 | synchronized (this.connection.getMutex()) { |
640 | setInOutParamsOnServer(); |
641 | setOutParams(); |
642 | |
643 | execResults = super.executeQuery(); |
644 | |
645 | retrieveOutParams(); |
646 | } |
647 | |
648 | return execResults; |
649 | } |
650 | |
651 | /* |
652 | * (non-Javadoc) |
653 | * |
654 | * @see java.sql.PreparedStatement#executeUpdate() |
655 | */ |
656 | public int executeUpdate() throws SQLException { |
657 | int returnVal = -1; |
658 | |
659 | checkClosed(); |
660 | |
661 | checkStreamability(); |
662 | |
663 | if (this.callingStoredFunction) { |
664 | execute(); |
665 | |
666 | return -1; |
667 | } |
668 | |
669 | synchronized (this.connection.getMutex()) { |
670 | setInOutParamsOnServer(); |
671 | setOutParams(); |
672 | |
673 | returnVal = super.executeUpdate(); |
674 | |
675 | retrieveOutParams(); |
676 | } |
677 | |
678 | return returnVal; |
679 | } |
680 | |
681 | private String extractProcedureName() throws SQLException { |
682 | // TODO: Do this with less memory allocation |
683 | int endCallIndex = StringUtils.indexOfIgnoreCase(this.originalSql, |
684 | "CALL "); //$NON-NLS-1$ |
685 | int offset = 5; |
686 | |
687 | if (endCallIndex == -1) { |
688 | endCallIndex = StringUtils.indexOfIgnoreCase(this.originalSql, |
689 | "SELECT "); |
690 | offset = 7; |
691 | } |
692 | |
693 | if (endCallIndex != -1) { |
694 | StringBuffer nameBuf = new StringBuffer(); |
695 | |
696 | String trimmedStatement = this.originalSql.substring( |
697 | endCallIndex + offset).trim(); |
698 | |
699 | int statementLength = trimmedStatement.length(); |
700 | |
701 | for (int i = 0; i < statementLength; i++) { |
702 | char c = trimmedStatement.charAt(i); |
703 | |
704 | if (Character.isWhitespace(c) || (c == '(') || (c == '?')) { |
705 | break; |
706 | } |
707 | nameBuf.append(c); |
708 | |
709 | } |
710 | |
711 | return nameBuf.toString(); |
712 | } |
713 | throw SQLError.createSQLException(Messages.getString("CallableStatement.1"), //$NON-NLS-1$ |
714 | SQLError.SQL_STATE_GENERAL_ERROR); |
715 | |
716 | } |
717 | |
718 | /** |
719 | * Adds 'at' symbol to beginning of parameter names if needed. |
720 | * |
721 | * @param paramNameIn |
722 | * the parameter name to 'fix' |
723 | * |
724 | * @return the parameter name with an 'a' prepended, if needed |
725 | * |
726 | * @throws SQLException |
727 | * if the parameter name is null or empty. |
728 | */ |
729 | private String fixParameterName(String paramNameIn) throws SQLException { |
730 | if ((paramNameIn == null) || (paramNameIn.length() == 0)) { |
731 | throw SQLError.createSQLException( |
732 | ((Messages.getString("CallableStatement.0") + paramNameIn) == null) //$NON-NLS-1$ |
733 | ? Messages.getString("CallableStatement.15") : Messages.getString("CallableStatement.16"), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ //$NON-NLS-2$ |
734 | } |
735 | |
736 | return mangleParameterName(paramNameIn); |
737 | |
738 | /* |
739 | * if (paramNameIn.startsWith("@")) { return paramNameIn; } else { |
740 | * StringBuffer paramNameBuf = new StringBuffer("@"); |
741 | * paramNameBuf.append(paramNameIn); |
742 | * |
743 | * return paramNameBuf.toString(); } |
744 | */ |
745 | } |
746 | |
747 | /** |
748 | * @see java.sql.CallableStatement#getArray(int) |
749 | */ |
750 | public synchronized Array getArray(int i) throws SQLException { |
751 | ResultSet rs = getOutputParameters(i); |
752 | |
753 | Array retValue = rs.getArray(mapOutputParameterIndexToRsIndex(i)); |
754 | |
755 | this.outputParamWasNull = rs.wasNull(); |
756 | |
757 | return retValue; |
758 | } |
759 | |
760 | /** |
761 | * @see java.sql.CallableStatement#getArray(java.lang.String) |
762 | */ |
763 | public synchronized Array getArray(String parameterName) |
764 | throws SQLException { |
765 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
766 | // from ?= |
767 | |
768 | Array retValue = rs.getArray(fixParameterName(parameterName)); |
769 | |
770 | this.outputParamWasNull = rs.wasNull(); |
771 | |
772 | return retValue; |
773 | } |
774 | |
775 | /** |
776 | * @see java.sql.CallableStatement#getBigDecimal(int) |
777 | */ |
778 | public synchronized BigDecimal getBigDecimal(int parameterIndex) |
779 | throws SQLException { |
780 | ResultSet rs = getOutputParameters(parameterIndex); |
781 | |
782 | BigDecimal retValue = rs |
783 | .getBigDecimal(mapOutputParameterIndexToRsIndex(parameterIndex)); |
784 | |
785 | this.outputParamWasNull = rs.wasNull(); |
786 | |
787 | return retValue; |
788 | } |
789 | |
790 | /** |
791 | * DOCUMENT ME! |
792 | * |
793 | * @param parameterIndex |
794 | * DOCUMENT ME! |
795 | * @param scale |
796 | * DOCUMENT ME! |
797 | * |
798 | * @return DOCUMENT ME! |
799 | * |
800 | * @throws SQLException |
801 | * DOCUMENT ME! |
802 | * |
803 | * @see java.sql.CallableStatement#getBigDecimal(int, int) |
804 | * @deprecated |
805 | */ |
806 | public synchronized BigDecimal getBigDecimal(int parameterIndex, int scale) |
807 | throws SQLException { |
808 | ResultSet rs = getOutputParameters(parameterIndex); |
809 | |
810 | BigDecimal retValue = rs.getBigDecimal( |
811 | mapOutputParameterIndexToRsIndex(parameterIndex), scale); |
812 | |
813 | this.outputParamWasNull = rs.wasNull(); |
814 | |
815 | return retValue; |
816 | } |
817 | |
818 | /** |
819 | * @see java.sql.CallableStatement#getBigDecimal(java.lang.String) |
820 | */ |
821 | public synchronized BigDecimal getBigDecimal(String parameterName) |
822 | throws SQLException { |
823 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
824 | // from ?= |
825 | |
826 | BigDecimal retValue = rs.getBigDecimal(fixParameterName(parameterName)); |
827 | |
828 | this.outputParamWasNull = rs.wasNull(); |
829 | |
830 | return retValue; |
831 | } |
832 | |
833 | /** |
834 | * @see java.sql.CallableStatement#getBlob(int) |
835 | */ |
836 | public synchronized Blob getBlob(int parameterIndex) throws SQLException { |
837 | ResultSet rs = getOutputParameters(parameterIndex); |
838 | |
839 | Blob retValue = rs |
840 | .getBlob(mapOutputParameterIndexToRsIndex(parameterIndex)); |
841 | |
842 | this.outputParamWasNull = rs.wasNull(); |
843 | |
844 | return retValue; |
845 | } |
846 | |
847 | /** |
848 | * @see java.sql.CallableStatement#getBlob(java.lang.String) |
849 | */ |
850 | public synchronized Blob getBlob(String parameterName) throws SQLException { |
851 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
852 | // from ?= |
853 | |
854 | Blob retValue = rs.getBlob(fixParameterName(parameterName)); |
855 | |
856 | this.outputParamWasNull = rs.wasNull(); |
857 | |
858 | return retValue; |
859 | } |
860 | |
861 | /** |
862 | * @see java.sql.CallableStatement#getBoolean(int) |
863 | */ |
864 | public synchronized boolean getBoolean(int parameterIndex) |
865 | throws SQLException { |
866 | ResultSet rs = getOutputParameters(parameterIndex); |
867 | |
868 | boolean retValue = rs |
869 | .getBoolean(mapOutputParameterIndexToRsIndex(parameterIndex)); |
870 | |
871 | this.outputParamWasNull = rs.wasNull(); |
872 | |
873 | return retValue; |
874 | } |
875 | |
876 | /** |
877 | * @see java.sql.CallableStatement#getBoolean(java.lang.String) |
878 | */ |
879 | public synchronized boolean getBoolean(String parameterName) |
880 | throws SQLException { |
881 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
882 | // from ?= |
883 | |
884 | boolean retValue = rs.getBoolean(fixParameterName(parameterName)); |
885 | |
886 | this.outputParamWasNull = rs.wasNull(); |
887 | |
888 | return retValue; |
889 | } |
890 | |
891 | /** |
892 | * @see java.sql.CallableStatement#getByte(int) |
893 | */ |
894 | public synchronized byte getByte(int parameterIndex) throws SQLException { |
895 | ResultSet rs = getOutputParameters(parameterIndex); |
896 | |
897 | byte retValue = rs |
898 | .getByte(mapOutputParameterIndexToRsIndex(parameterIndex)); |
899 | |
900 | this.outputParamWasNull = rs.wasNull(); |
901 | |
902 | return retValue; |
903 | } |
904 | |
905 | /** |
906 | * @see java.sql.CallableStatement#getByte(java.lang.String) |
907 | */ |
908 | public synchronized byte getByte(String parameterName) throws SQLException { |
909 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
910 | // from ?= |
911 | |
912 | byte retValue = rs.getByte(fixParameterName(parameterName)); |
913 | |
914 | this.outputParamWasNull = rs.wasNull(); |
915 | |
916 | return retValue; |
917 | } |
918 | |
919 | /** |
920 | * @see java.sql.CallableStatement#getBytes(int) |
921 | */ |
922 | public synchronized byte[] getBytes(int parameterIndex) throws SQLException { |
923 | ResultSet rs = getOutputParameters(parameterIndex); |
924 | |
925 | byte[] retValue = rs |
926 | .getBytes(mapOutputParameterIndexToRsIndex(parameterIndex)); |
927 | |
928 | this.outputParamWasNull = rs.wasNull(); |
929 | |
930 | return retValue; |
931 | } |
932 | |
933 | /** |
934 | * @see java.sql.CallableStatement#getBytes(java.lang.String) |
935 | */ |
936 | public synchronized byte[] getBytes(String parameterName) |
937 | throws SQLException { |
938 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
939 | // from ?= |
940 | |
941 | byte[] retValue = rs.getBytes(fixParameterName(parameterName)); |
942 | |
943 | this.outputParamWasNull = rs.wasNull(); |
944 | |
945 | return retValue; |
946 | } |
947 | |
948 | /** |
949 | * @see java.sql.CallableStatement#getClob(int) |
950 | */ |
951 | public synchronized Clob getClob(int parameterIndex) throws SQLException { |
952 | ResultSet rs = getOutputParameters(parameterIndex); |
953 | |
954 | Clob retValue = rs |
955 | .getClob(mapOutputParameterIndexToRsIndex(parameterIndex)); |
956 | |
957 | this.outputParamWasNull = rs.wasNull(); |
958 | |
959 | return retValue; |
960 | } |
961 | |
962 | /** |
963 | * @see java.sql.CallableStatement#getClob(java.lang.String) |
964 | */ |
965 | public synchronized Clob getClob(String parameterName) throws SQLException { |
966 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
967 | // from ?= |
968 | |
969 | Clob retValue = rs.getClob(fixParameterName(parameterName)); |
970 | |
971 | this.outputParamWasNull = rs.wasNull(); |
972 | |
973 | return retValue; |
974 | } |
975 | |
976 | /** |
977 | * @see java.sql.CallableStatement#getDate(int) |
978 | */ |
979 | public synchronized Date getDate(int parameterIndex) throws SQLException { |
980 | ResultSet rs = getOutputParameters(parameterIndex); |
981 | |
982 | Date retValue = rs |
983 | .getDate(mapOutputParameterIndexToRsIndex(parameterIndex)); |
984 | |
985 | this.outputParamWasNull = rs.wasNull(); |
986 | |
987 | return retValue; |
988 | } |
989 | |
990 | /** |
991 | * @see java.sql.CallableStatement#getDate(int, java.util.Calendar) |
992 | */ |
993 | public synchronized Date getDate(int parameterIndex, Calendar cal) |
994 | throws SQLException { |
995 | ResultSet rs = getOutputParameters(parameterIndex); |
996 | |
997 | Date retValue = rs.getDate( |
998 | mapOutputParameterIndexToRsIndex(parameterIndex), cal); |
999 | |
1000 | this.outputParamWasNull = rs.wasNull(); |
1001 | |
1002 | return retValue; |
1003 | } |
1004 | |
1005 | /** |
1006 | * @see java.sql.CallableStatement#getDate(java.lang.String) |
1007 | */ |
1008 | public synchronized Date getDate(String parameterName) throws SQLException { |
1009 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1010 | // from ?= |
1011 | |
1012 | Date retValue = rs.getDate(fixParameterName(parameterName)); |
1013 | |
1014 | this.outputParamWasNull = rs.wasNull(); |
1015 | |
1016 | return retValue; |
1017 | } |
1018 | |
1019 | /** |
1020 | * @see java.sql.CallableStatement#getDate(java.lang.String, |
1021 | * java.util.Calendar) |
1022 | */ |
1023 | public synchronized Date getDate(String parameterName, Calendar cal) |
1024 | throws SQLException { |
1025 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1026 | // from ?= |
1027 | |
1028 | Date retValue = rs.getDate(fixParameterName(parameterName), cal); |
1029 | |
1030 | this.outputParamWasNull = rs.wasNull(); |
1031 | |
1032 | return retValue; |
1033 | } |
1034 | |
1035 | /** |
1036 | * @see java.sql.CallableStatement#getDouble(int) |
1037 | */ |
1038 | public synchronized double getDouble(int parameterIndex) |
1039 | throws SQLException { |
1040 | ResultSet rs = getOutputParameters(parameterIndex); |
1041 | |
1042 | double retValue = rs |
1043 | .getDouble(mapOutputParameterIndexToRsIndex(parameterIndex)); |
1044 | |
1045 | this.outputParamWasNull = rs.wasNull(); |
1046 | |
1047 | return retValue; |
1048 | } |
1049 | |
1050 | /** |
1051 | * @see java.sql.CallableStatement#getDouble(java.lang.String) |
1052 | */ |
1053 | public synchronized double getDouble(String parameterName) |
1054 | throws SQLException { |
1055 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1056 | // from ?= |
1057 | |
1058 | double retValue = rs.getDouble(fixParameterName(parameterName)); |
1059 | |
1060 | this.outputParamWasNull = rs.wasNull(); |
1061 | |
1062 | return retValue; |
1063 | } |
1064 | |
1065 | /** |
1066 | * @see java.sql.CallableStatement#getFloat(int) |
1067 | */ |
1068 | public synchronized float getFloat(int parameterIndex) throws SQLException { |
1069 | ResultSet rs = getOutputParameters(parameterIndex); |
1070 | |
1071 | float retValue = rs |
1072 | .getFloat(mapOutputParameterIndexToRsIndex(parameterIndex)); |
1073 | |
1074 | this.outputParamWasNull = rs.wasNull(); |
1075 | |
1076 | return retValue; |
1077 | } |
1078 | |
1079 | /** |
1080 | * @see java.sql.CallableStatement#getFloat(java.lang.String) |
1081 | */ |
1082 | public synchronized float getFloat(String parameterName) |
1083 | throws SQLException { |
1084 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1085 | // from ?= |
1086 | |
1087 | float retValue = rs.getFloat(fixParameterName(parameterName)); |
1088 | |
1089 | this.outputParamWasNull = rs.wasNull(); |
1090 | |
1091 | return retValue; |
1092 | } |
1093 | |
1094 | /** |
1095 | * @see java.sql.CallableStatement#getInt(int) |
1096 | */ |
1097 | public synchronized int getInt(int parameterIndex) throws SQLException { |
1098 | ResultSet rs = getOutputParameters(parameterIndex); |
1099 | |
1100 | int retValue = rs |
1101 | .getInt(mapOutputParameterIndexToRsIndex(parameterIndex)); |
1102 | |
1103 | this.outputParamWasNull = rs.wasNull(); |
1104 | |
1105 | return retValue; |
1106 | } |
1107 | |
1108 | /** |
1109 | * @see java.sql.CallableStatement#getInt(java.lang.String) |
1110 | */ |
1111 | public synchronized int getInt(String parameterName) throws SQLException { |
1112 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1113 | // from ?= |
1114 | |
1115 | int retValue = rs.getInt(fixParameterName(parameterName)); |
1116 | |
1117 | this.outputParamWasNull = rs.wasNull(); |
1118 | |
1119 | return retValue; |
1120 | } |
1121 | |
1122 | /** |
1123 | * @see java.sql.CallableStatement#getLong(int) |
1124 | */ |
1125 | public synchronized long getLong(int parameterIndex) throws SQLException { |
1126 | ResultSet rs = getOutputParameters(parameterIndex); |
1127 | |
1128 | long retValue = rs |
1129 | .getLong(mapOutputParameterIndexToRsIndex(parameterIndex)); |
1130 | |
1131 | this.outputParamWasNull = rs.wasNull(); |
1132 | |
1133 | return retValue; |
1134 | } |
1135 | |
1136 | /** |
1137 | * @see java.sql.CallableStatement#getLong(java.lang.String) |
1138 | */ |
1139 | public synchronized long getLong(String parameterName) throws SQLException { |
1140 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1141 | // from ?= |
1142 | |
1143 | long retValue = rs.getLong(fixParameterName(parameterName)); |
1144 | |
1145 | this.outputParamWasNull = rs.wasNull(); |
1146 | |
1147 | return retValue; |
1148 | } |
1149 | |
1150 | private int getNamedParamIndex(String paramName, boolean forOut) |
1151 | throws SQLException { |
1152 | if ((paramName == null) || (paramName.length() == 0)) { |
1153 | throw SQLError.createSQLException(Messages.getString("CallableStatement.2"), //$NON-NLS-1$ |
1154 | SQLError.SQL_STATE_ILLEGAL_ARGUMENT); |
1155 | } |
1156 | |
1157 | CallableStatementParam namedParamInfo = this.paramInfo |
1158 | .getParameter(paramName); |
1159 | |
1160 | if (this.paramInfo == null) { |
1161 | throw SQLError.createSQLException( |
1162 | Messages.getString("CallableStatement.3") + paramName + Messages.getString("CallableStatement.4"), //$NON-NLS-1$ //$NON-NLS-2$ |
1163 | SQLError.SQL_STATE_ILLEGAL_ARGUMENT); |
1164 | } |
1165 | |
1166 | if (forOut && !namedParamInfo.isOut) { |
1167 | throw SQLError.createSQLException( |
1168 | Messages.getString("CallableStatement.5") + paramName //$NON-NLS-1$ |
1169 | + Messages.getString("CallableStatement.6"), //$NON-NLS-1$ |
1170 | SQLError.SQL_STATE_ILLEGAL_ARGUMENT); |
1171 | } |
1172 | |
1173 | |
1174 | if (this.placeholderToParameterIndexMap == null) { |
1175 | return namedParamInfo.index + 1; // JDBC indices are 1-based |
1176 | } |
1177 | |
1178 | for (int i = 0; i < this.placeholderToParameterIndexMap.length; i++) { |
1179 | if (this.placeholderToParameterIndexMap[i] == namedParamInfo.index) { |
1180 | return i + 1; |
1181 | } |
1182 | } |
1183 | |
1184 | throw SQLError.createSQLException("Can't find local placeholder mapping for parameter named \"" + |
1185 | paramName + "\".", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); |
1186 | } |
1187 | |
1188 | /** |
1189 | * @see java.sql.CallableStatement#getObject(int) |
1190 | */ |
1191 | public synchronized Object getObject(int parameterIndex) |
1192 | throws SQLException { |
1193 | CallableStatementParam paramDescriptor = checkIsOutputParam(parameterIndex); |
1194 | |
1195 | ResultSet rs = getOutputParameters(parameterIndex); |
1196 | |
1197 | Object retVal = rs.getObjectStoredProc( |
1198 | mapOutputParameterIndexToRsIndex(parameterIndex), |
1199 | paramDescriptor.desiredJdbcType); |
1200 | |
1201 | this.outputParamWasNull = rs.wasNull(); |
1202 | |
1203 | return retVal; |
1204 | } |
1205 | |
1206 | /** |
1207 | * @see java.sql.CallableStatement#getObject(int, java.util.Map) |
1208 | */ |
1209 | public synchronized Object getObject(int parameterIndex, Map map) |
1210 | throws SQLException { |
1211 | ResultSet rs = getOutputParameters(parameterIndex); |
1212 | |
1213 | Object retVal = rs.getObject( |
1214 | mapOutputParameterIndexToRsIndex(parameterIndex), map); |
1215 | |
1216 | this.outputParamWasNull = rs.wasNull(); |
1217 | |
1218 | return retVal; |
1219 | } |
1220 | |
1221 | /** |
1222 | * @see java.sql.CallableStatement#getObject(java.lang.String) |
1223 | */ |
1224 | public synchronized Object getObject(String parameterName) |
1225 | throws SQLException { |
1226 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1227 | // from ?= |
1228 | |
1229 | Object retValue = rs.getObject(fixParameterName(parameterName)); |
1230 | |
1231 | this.outputParamWasNull = rs.wasNull(); |
1232 | |
1233 | return retValue; |
1234 | } |
1235 | |
1236 | /** |
1237 | * @see java.sql.CallableStatement#getObject(java.lang.String, |
1238 | * java.util.Map) |
1239 | */ |
1240 | public synchronized Object getObject(String parameterName, Map map) |
1241 | throws SQLException { |
1242 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1243 | // from ?= |
1244 | |
1245 | Object retValue = rs.getObject(fixParameterName(parameterName), map); |
1246 | |
1247 | this.outputParamWasNull = rs.wasNull(); |
1248 | |
1249 | return retValue; |
1250 | } |
1251 | |
1252 | /** |
1253 | * Returns the ResultSet that holds the output parameters, or throws an |
1254 | * appropriate exception if none exist, or they weren't returned. |
1255 | * |
1256 | * @return the ResultSet that holds the output parameters |
1257 | * |
1258 | * @throws SQLException |
1259 | * if no output parameters were defined, or if no output |
1260 | * parameters were returned. |
1261 | */ |
1262 | private ResultSet getOutputParameters(int paramIndex) throws SQLException { |
1263 | this.outputParamWasNull = false; |
1264 | |
1265 | if (paramIndex == 1 && this.callingStoredFunction |
1266 | && this.returnValueParam != null) { |
1267 | return this.functionReturnValueResults; |
1268 | } |
1269 | |
1270 | if (this.outputParameterResults == null) { |
1271 | if (this.paramInfo.numberOfParameters() == 0) { |
1272 | throw SQLError.createSQLException(Messages |
1273 | .getString("CallableStatement.7"), //$NON-NLS-1$ |
1274 | SQLError.SQL_STATE_ILLEGAL_ARGUMENT); |
1275 | } |
1276 | throw SQLError.createSQLException(Messages.getString("CallableStatement.8"), //$NON-NLS-1$ |
1277 | SQLError.SQL_STATE_GENERAL_ERROR); |
1278 | } |
1279 | |
1280 | return this.outputParameterResults; |
1281 | |
1282 | } |
1283 | |
1284 | public synchronized ParameterMetaData getParameterMetaData() |
1285 | throws SQLException { |
1286 | return (CallableStatementParamInfoJDBC3) this.paramInfo; |
1287 | } |
1288 | |
1289 | /** |
1290 | * @see java.sql.CallableStatement#getRef(int) |
1291 | */ |
1292 | public synchronized Ref getRef(int parameterIndex) throws SQLException { |
1293 | ResultSet rs = getOutputParameters(parameterIndex); |
1294 | |
1295 | Ref retValue = rs |
1296 | .getRef(mapOutputParameterIndexToRsIndex(parameterIndex)); |
1297 | |
1298 | this.outputParamWasNull = rs.wasNull(); |
1299 | |
1300 | return retValue; |
1301 | } |
1302 | |
1303 | /** |
1304 | * @see java.sql.CallableStatement#getRef(java.lang.String) |
1305 | */ |
1306 | public synchronized Ref getRef(String parameterName) throws SQLException { |
1307 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1308 | // from ?= |
1309 | |
1310 | Ref retValue = rs.getRef(fixParameterName(parameterName)); |
1311 | |
1312 | this.outputParamWasNull = rs.wasNull(); |
1313 | |
1314 | return retValue; |
1315 | } |
1316 | |
1317 | /** |
1318 | * @see java.sql.CallableStatement#getShort(int) |
1319 | */ |
1320 | public synchronized short getShort(int parameterIndex) throws SQLException { |
1321 | ResultSet rs = getOutputParameters(parameterIndex); |
1322 | |
1323 | short retValue = rs |
1324 | .getShort(mapOutputParameterIndexToRsIndex(parameterIndex)); |
1325 | |
1326 | this.outputParamWasNull = rs.wasNull(); |
1327 | |
1328 | return retValue; |
1329 | } |
1330 | |
1331 | /** |
1332 | * @see java.sql.CallableStatement#getShort(java.lang.String) |
1333 | */ |
1334 | public synchronized short getShort(String parameterName) |
1335 | throws SQLException { |
1336 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1337 | // from ?= |
1338 | |
1339 | short retValue = rs.getShort(fixParameterName(parameterName)); |
1340 | |
1341 | this.outputParamWasNull = rs.wasNull(); |
1342 | |
1343 | return retValue; |
1344 | } |
1345 | |
1346 | /** |
1347 | * @see java.sql.CallableStatement#getString(int) |
1348 | */ |
1349 | public synchronized String getString(int parameterIndex) |
1350 | throws SQLException { |
1351 | ResultSet rs = getOutputParameters(parameterIndex); |
1352 | |
1353 | String retValue = rs |
1354 | .getString(mapOutputParameterIndexToRsIndex(parameterIndex)); |
1355 | |
1356 | this.outputParamWasNull = rs.wasNull(); |
1357 | |
1358 | return retValue; |
1359 | } |
1360 | |
1361 | /** |
1362 | * @see java.sql.CallableStatement#getString(java.lang.String) |
1363 | */ |
1364 | public synchronized String getString(String parameterName) |
1365 | throws SQLException { |
1366 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1367 | // from ?= |
1368 | |
1369 | String retValue = rs.getString(fixParameterName(parameterName)); |
1370 | |
1371 | this.outputParamWasNull = rs.wasNull(); |
1372 | |
1373 | return retValue; |
1374 | } |
1375 | |
1376 | /** |
1377 | * @see java.sql.CallableStatement#getTime(int) |
1378 | */ |
1379 | public synchronized Time getTime(int parameterIndex) throws SQLException { |
1380 | ResultSet rs = getOutputParameters(parameterIndex); |
1381 | |
1382 | Time retValue = rs |
1383 | .getTime(mapOutputParameterIndexToRsIndex(parameterIndex)); |
1384 | |
1385 | this.outputParamWasNull = rs.wasNull(); |
1386 | |
1387 | return retValue; |
1388 | } |
1389 | |
1390 | /** |
1391 | * @see java.sql.CallableStatement#getTime(int, java.util.Calendar) |
1392 | */ |
1393 | public synchronized Time getTime(int parameterIndex, Calendar cal) |
1394 | throws SQLException { |
1395 | ResultSet rs = getOutputParameters(parameterIndex); |
1396 | |
1397 | Time retValue = rs.getTime( |
1398 | mapOutputParameterIndexToRsIndex(parameterIndex), cal); |
1399 | |
1400 | this.outputParamWasNull = rs.wasNull(); |
1401 | |
1402 | return retValue; |
1403 | } |
1404 | |
1405 | /** |
1406 | * @see java.sql.CallableStatement#getTime(java.lang.String) |
1407 | */ |
1408 | public synchronized Time getTime(String parameterName) throws SQLException { |
1409 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1410 | // from ?= |
1411 | |
1412 | Time retValue = rs.getTime(fixParameterName(parameterName)); |
1413 | |
1414 | this.outputParamWasNull = rs.wasNull(); |
1415 | |
1416 | return retValue; |
1417 | } |
1418 | |
1419 | /** |
1420 | * @see java.sql.CallableStatement#getTime(java.lang.String, |
1421 | * java.util.Calendar) |
1422 | */ |
1423 | public synchronized Time getTime(String parameterName, Calendar cal) |
1424 | throws SQLException { |
1425 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1426 | // from ?= |
1427 | |
1428 | Time retValue = rs.getTime(fixParameterName(parameterName), cal); |
1429 | |
1430 | this.outputParamWasNull = rs.wasNull(); |
1431 | |
1432 | return retValue; |
1433 | } |
1434 | |
1435 | /** |
1436 | * @see java.sql.CallableStatement#getTimestamp(int) |
1437 | */ |
1438 | public synchronized Timestamp getTimestamp(int parameterIndex) |
1439 | throws SQLException { |
1440 | ResultSet rs = getOutputParameters(parameterIndex); |
1441 | |
1442 | Timestamp retValue = rs |
1443 | .getTimestamp(mapOutputParameterIndexToRsIndex(parameterIndex)); |
1444 | |
1445 | this.outputParamWasNull = rs.wasNull(); |
1446 | |
1447 | return retValue; |
1448 | } |
1449 | |
1450 | /** |
1451 | * @see java.sql.CallableStatement#getTimestamp(int, java.util.Calendar) |
1452 | */ |
1453 | public synchronized Timestamp getTimestamp(int parameterIndex, Calendar cal) |
1454 | throws SQLException { |
1455 | ResultSet rs = getOutputParameters(parameterIndex); |
1456 | |
1457 | Timestamp retValue = rs.getTimestamp( |
1458 | mapOutputParameterIndexToRsIndex(parameterIndex), cal); |
1459 | |
1460 | this.outputParamWasNull = rs.wasNull(); |
1461 | |
1462 | return retValue; |
1463 | } |
1464 | |
1465 | /** |
1466 | * @see java.sql.CallableStatement#getTimestamp(java.lang.String) |
1467 | */ |
1468 | public synchronized Timestamp getTimestamp(String parameterName) |
1469 | throws SQLException { |
1470 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1471 | // from ?= |
1472 | |
1473 | Timestamp retValue = rs.getTimestamp(fixParameterName(parameterName)); |
1474 | |
1475 | this.outputParamWasNull = rs.wasNull(); |
1476 | |
1477 | return retValue; |
1478 | } |
1479 | |
1480 | /** |
1481 | * @see java.sql.CallableStatement#getTimestamp(java.lang.String, |
1482 | * java.util.Calendar) |
1483 | */ |
1484 | public synchronized Timestamp getTimestamp(String parameterName, |
1485 | Calendar cal) throws SQLException { |
1486 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1487 | // from ?= |
1488 | |
1489 | Timestamp retValue = rs.getTimestamp(fixParameterName(parameterName), |
1490 | cal); |
1491 | |
1492 | this.outputParamWasNull = rs.wasNull(); |
1493 | |
1494 | return retValue; |
1495 | } |
1496 | |
1497 | /** |
1498 | * @see java.sql.CallableStatement#getURL(int) |
1499 | */ |
1500 | public synchronized URL getURL(int parameterIndex) throws SQLException { |
1501 | ResultSet rs = getOutputParameters(parameterIndex); |
1502 | |
1503 | URL retValue = rs |
1504 | .getURL(mapOutputParameterIndexToRsIndex(parameterIndex)); |
1505 | |
1506 | this.outputParamWasNull = rs.wasNull(); |
1507 | |
1508 | return retValue; |
1509 | } |
1510 | |
1511 | /** |
1512 | * @see java.sql.CallableStatement#getURL(java.lang.String) |
1513 | */ |
1514 | public synchronized URL getURL(String parameterName) throws SQLException { |
1515 | ResultSet rs = getOutputParameters(0); // definitely not going to be |
1516 | // from ?= |
1517 | |
1518 | URL retValue = rs.getURL(fixParameterName(parameterName)); |
1519 | |
1520 | this.outputParamWasNull = rs.wasNull(); |
1521 | |
1522 | return retValue; |
1523 | } |
1524 | |
1525 | private int mapOutputParameterIndexToRsIndex(int paramIndex) |
1526 | throws SQLException { |
1527 | |
1528 | if (this.returnValueParam != null && paramIndex == 1) { |
1529 | return 1; |
1530 | } |
1531 | |
1532 | checkParameterIndexBounds(paramIndex); |
1533 | |
1534 | int localParamIndex = paramIndex - 1; |
1535 | |
1536 | if (this.placeholderToParameterIndexMap != null) { |
1537 | localParamIndex = this.placeholderToParameterIndexMap[localParamIndex]; |
1538 | } |
1539 | |
1540 | int rsIndex = this.parameterIndexToRsIndex[localParamIndex]; |
1541 | |
1542 | if (rsIndex == NOT_OUTPUT_PARAMETER_INDICATOR) { |
1543 | throw SQLError.createSQLException( |
1544 | Messages.getString("CallableStatement.21") + paramIndex //$NON-NLS-1$ |
1545 | + Messages.getString("CallableStatement.22"), //$NON-NLS-1$ |
1546 | SQLError.SQL_STATE_ILLEGAL_ARGUMENT); |
1547 | } |
1548 | |
1549 | return rsIndex + 1; |
1550 | } |
1551 | |
1552 | /** |
1553 | * @see java.sql.CallableStatement#registerOutParameter(int, int) |
1554 | */ |
1555 | public void registerOutParameter(int parameterIndex, int sqlType) |
1556 | throws SQLException { |
1557 | CallableStatementParam paramDescriptor = checkIsOutputParam(parameterIndex); |
1558 | paramDescriptor.desiredJdbcType = sqlType; |
1559 | } |
1560 | |
1561 | /** |
1562 | * @see java.sql.CallableStatement#registerOutParameter(int, int, int) |
1563 | */ |
1564 | public void registerOutParameter(int parameterIndex, int sqlType, int scale) |
1565 | throws SQLException { |
1566 | registerOutParameter(parameterIndex, sqlType); |
1567 | } |
1568 | |
1569 | /** |
1570 | * @see java.sql.CallableStatement#registerOutParameter(int, int, |
1571 | * java.lang.String) |
1572 | */ |
1573 | public void registerOutParameter(int parameterIndex, int sqlType, |
1574 | String typeName) throws SQLException { |
1575 | checkIsOutputParam(parameterIndex); |
1576 | } |
1577 | |
1578 | /** |
1579 | * @see java.sql.CallableStatement#registerOutParameter(java.lang.String, |
1580 | * int) |
1581 | */ |
1582 | public synchronized void registerOutParameter(String parameterName, |
1583 | int sqlType) throws SQLException { |
1584 | registerOutParameter(getNamedParamIndex(parameterName, true), sqlType); |
1585 | } |
1586 | |
1587 | /** |
1588 | * @see java.sql.CallableStatement#registerOutParameter(java.lang.String, |
1589 | * int, int) |
1590 | */ |
1591 | public void registerOutParameter(String parameterName, int sqlType, |
1592 | int scale) throws SQLException { |
1593 | registerOutParameter(getNamedParamIndex(parameterName, true), sqlType); |
1594 | } |
1595 | |
1596 | /** |
1597 | * @see java.sql.CallableStatement#registerOutParameter(java.lang.String, |
1598 | * int, java.lang.String) |
1599 | */ |
1600 | public void registerOutParameter(String parameterName, int sqlType, |
1601 | String typeName) throws SQLException { |
1602 | registerOutParameter(getNamedParamIndex(parameterName, true), sqlType, |
1603 | typeName); |
1604 | } |
1605 | |
1606 | /** |
1607 | * Issues a second query to retrieve all output parameters. |
1608 | * |
1609 | * @throws SQLException |
1610 | * if an error occurs. |
1611 | */ |
1612 | private void retrieveOutParams() throws SQLException { |
1613 | int numParameters = this.paramInfo.numberOfParameters(); |
1614 | |
1615 | this.parameterIndexToRsIndex = new int[numParameters]; |
1616 | |
1617 | for (int i = 0; i < numParameters; i++) { |
1618 | this.parameterIndexToRsIndex[i] = NOT_OUTPUT_PARAMETER_INDICATOR; |
1619 | } |
1620 | |
1621 | int localParamIndex = 0; |
1622 | |
1623 | if (numParameters > 0) { |
1624 | StringBuffer outParameterQuery = new StringBuffer("SELECT "); //$NON-NLS-1$ |
1625 | |
1626 | boolean firstParam = true; |
1627 | boolean hadOutputParams = false; |
1628 | |
1629 | for (Iterator paramIter = this.paramInfo.iterator(); paramIter |
1630 | .hasNext();) { |
1631 | CallableStatementParam retrParamInfo = (CallableStatementParam) paramIter |
1632 | .next(); |
1633 | |
1634 | if (retrParamInfo.isOut) { |
1635 | hadOutputParams = true; |
1636 | |
1637 | this.parameterIndexToRsIndex[retrParamInfo.index] = localParamIndex++; |
1638 | |
1639 | String outParameterName = mangleParameterName(retrParamInfo.paramName); |
1640 | |
1641 | if (!firstParam) { |
1642 | outParameterQuery.append(","); //$NON-NLS-1$ |
1643 | } else { |
1644 | firstParam = false; |
1645 | } |
1646 | |
1647 | if (!outParameterName.startsWith("@")) { //$NON-NLS-1$ |
1648 | outParameterQuery.append('@'); |
1649 | } |
1650 | |
1651 | outParameterQuery.append(outParameterName); |
1652 | } |
1653 | } |
1654 | |
1655 | if (hadOutputParams) { |
1656 | // We can't use 'ourself' to execute this query, or any |
1657 | // pending result sets would be overwritten |
1658 | java.sql.Statement outParameterStmt = null; |
1659 | java.sql.ResultSet outParamRs = null; |
1660 | |
1661 | try { |
1662 | outParameterStmt = this.connection.createStatement(); |
1663 | outParamRs = outParameterStmt |
1664 | .executeQuery(outParameterQuery.toString()); |
1665 | this.outputParameterResults = ((com.mysql.jdbc.ResultSet) outParamRs) |
1666 | .copy(); |
1667 | |
1668 | if (!this.outputParameterResults.next()) { |
1669 | this.outputParameterResults.close(); |
1670 | this.outputParameterResults = null; |
1671 | } |
1672 | } finally { |
1673 | if (outParameterStmt != null) { |
1674 | outParameterStmt.close(); |
1675 | } |
1676 | } |
1677 | } else { |
1678 | this.outputParameterResults = null; |
1679 | } |
1680 | } else { |
1681 | this.outputParameterResults = null; |
1682 | } |
1683 | } |
1684 | |
1685 | /** |
1686 | * @see java.sql.CallableStatement#setAsciiStream(java.lang.String, |
1687 | * java.io.InputStream, int) |
1688 | */ |
1689 | public void setAsciiStream(String parameterName, InputStream x, int length) |
1690 | throws SQLException { |
1691 | setAsciiStream(getNamedParamIndex(parameterName, false), x, length); |
1692 | } |
1693 | |
1694 | /** |
1695 | * @see java.sql.CallableStatement#setBigDecimal(java.lang.String, |
1696 | * java.math.BigDecimal) |
1697 | */ |
1698 | public void setBigDecimal(String parameterName, BigDecimal x) |
1699 | throws SQLException { |
1700 | setBigDecimal(getNamedParamIndex(parameterName, false), x); |
1701 | } |
1702 | |
1703 | /** |
1704 | * @see java.sql.CallableStatement#setBinaryStream(java.lang.String, |
1705 | * java.io.InputStream, int) |
1706 | */ |
1707 | public void setBinaryStream(String parameterName, InputStream x, int length) |
1708 | throws SQLException { |
1709 | setBinaryStream(getNamedParamIndex(parameterName, false), x, length); |
1710 | } |
1711 | |
1712 | /** |
1713 | * @see java.sql.CallableStatement#setBoolean(java.lang.String, boolean) |
1714 | */ |
1715 | public void setBoolean(String parameterName, boolean x) throws SQLException { |
1716 | setBoolean(getNamedParamIndex(parameterName, false), x); |
1717 | } |
1718 | |
1719 | /** |
1720 | * @see java.sql.CallableStatement#setByte(java.lang.String, byte) |
1721 | */ |
1722 | public void setByte(String parameterName, byte x) throws SQLException { |
1723 | setByte(getNamedParamIndex(parameterName, false), x); |
1724 | } |
1725 | |
1726 | /** |
1727 | * @see java.sql.CallableStatement#setBytes(java.lang.String, byte[]) |
1728 | */ |
1729 | public void setBytes(String parameterName, byte[] x) throws SQLException { |
1730 | setBytes(getNamedParamIndex(parameterName, false), x); |
1731 | } |
1732 | |
1733 | /** |
1734 | * @see java.sql.CallableStatement#setCharacterStream(java.lang.String, |
1735 | * java.io.Reader, int) |
1736 | */ |
1737 | public void setCharacterStream(String parameterName, Reader reader, |
1738 | int length) throws SQLException { |
1739 | setCharacterStream(getNamedParamIndex(parameterName, false), reader, |
1740 | length); |
1741 | } |
1742 | |
1743 | /** |
1744 | * @see java.sql.CallableStatement#setDate(java.lang.String, java.sql.Date) |
1745 | */ |
1746 | public void setDate(String parameterName, Date x) throws SQLException { |
1747 | setDate(getNamedParamIndex(parameterName, false), x); |
1748 | } |
1749 | |
1750 | /** |
1751 | * @see java.sql.CallableStatement#setDate(java.lang.String, java.sql.Date, |
1752 | * java.util.Calendar) |
1753 | */ |
1754 | public void setDate(String parameterName, Date x, Calendar cal) |
1755 | throws SQLException { |
1756 | setDate(getNamedParamIndex(parameterName, false), x, cal); |
1757 | } |
1758 | |
1759 | /** |
1760 | * @see java.sql.CallableStatement#setDouble(java.lang.String, double) |
1761 | */ |
1762 | public void setDouble(String parameterName, double x) throws SQLException { |
1763 | setDouble(getNamedParamIndex(parameterName, false), x); |
1764 | } |
1765 | |
1766 | /** |
1767 | * @see java.sql.CallableStatement#setFloat(java.lang.String, float) |
1768 | */ |
1769 | public void setFloat(String parameterName, float x) throws SQLException { |
1770 | setFloat(getNamedParamIndex(parameterName, false), x); |
1771 | } |
1772 | |
1773 | /** |
1774 | * |
1775 | */ |
1776 | private void setInOutParamsOnServer() throws SQLException { |
1777 | if (this.paramInfo.numParameters > 0) { |
1778 | int parameterIndex = 0; |
1779 | |
1780 | for (Iterator paramIter = this.paramInfo.iterator(); paramIter |
1781 | .hasNext();) { |
1782 | |
1783 | CallableStatementParam inParamInfo = (CallableStatementParam) paramIter |
1784 | .next(); |
1785 | |
1786 | if (inParamInfo.isOut && inParamInfo.isIn) { |
1787 | String inOutParameterName = mangleParameterName(inParamInfo.paramName); |
1788 | StringBuffer queryBuf = new StringBuffer( |
1789 | 4 + inOutParameterName.length() + 1 + 1); |
1790 | queryBuf.append("SET "); //$NON-NLS-1$ |
1791 | queryBuf.append(inOutParameterName); |
1792 | queryBuf.append("=?"); //$NON-NLS-1$ |
1793 | |
1794 | PreparedStatement setPstmt = null; |
1795 | |
1796 | try { |
1797 | setPstmt = this.connection |
1798 | .clientPrepareStatement(queryBuf.toString()); |
1799 | |
1800 | byte[] parameterAsBytes = this |
1801 | .getBytesRepresentation(inParamInfo.index); |
1802 | |
1803 | if (parameterAsBytes != null) { |
1804 | if (parameterAsBytes.length > 8 |
1805 | && parameterAsBytes[0] == '_' |
1806 | && parameterAsBytes[1] == 'b' |
1807 | && parameterAsBytes[2] == 'i' |
1808 | && parameterAsBytes[3] == 'n' |
1809 | && parameterAsBytes[4] == 'a' |
1810 | && parameterAsBytes[5] == 'r' |
1811 | && parameterAsBytes[6] == 'y' |
1812 | && parameterAsBytes[7] == '\'') { |
1813 | setPstmt.setBytesNoEscapeNoQuotes(1, |
1814 | parameterAsBytes); |
1815 | } else { |
1816 | setPstmt.setBytes(1, parameterAsBytes); |
1817 | } |
1818 | } else { |
1819 | setPstmt.setNull(1, Types.NULL); |
1820 | } |
1821 | |
1822 | setPstmt.executeUpdate(); |
1823 | } finally { |
1824 | if (setPstmt != null) { |
1825 | setPstmt.close(); |
1826 | } |
1827 | } |
1828 | } |
1829 | |
1830 | parameterIndex++; |
1831 | } |
1832 | } |
1833 | } |
1834 | |
1835 | /** |
1836 | * @see java.sql.CallableStatement#setInt(java.lang.String, int) |
1837 | */ |
1838 | public void setInt(String parameterName, int x) throws SQLException { |
1839 | setInt(getNamedParamIndex(parameterName, false), x); |
1840 | } |
1841 | |
1842 | /** |
1843 | * @see java.sql.CallableStatement#setLong(java.lang.String, long) |
1844 | */ |
1845 | public void setLong(String parameterName, long x) throws SQLException { |
1846 | setLong(getNamedParamIndex(parameterName, false), x); |
1847 | } |
1848 | |
1849 | /** |
1850 | * @see java.sql.CallableStatement#setNull(java.lang.String, int) |
1851 | */ |
1852 | public void setNull(String parameterName, int sqlType) throws SQLException { |
1853 | setNull(getNamedParamIndex(parameterName, false), sqlType); |
1854 | } |
1855 | |
1856 | /** |
1857 | * @see java.sql.CallableStatement#setNull(java.lang.String, int, |
1858 | * java.lang.String) |
1859 | */ |
1860 | public void setNull(String parameterName, int sqlType, String typeName) |
1861 | throws SQLException { |
1862 | setNull(getNamedParamIndex(parameterName, false), sqlType, typeName); |
1863 | } |
1864 | |
1865 | /** |
1866 | * @see java.sql.CallableStatement#setObject(java.lang.String, |
1867 | * java.lang.Object) |
1868 | */ |
1869 | public void setObject(String parameterName, Object x) throws SQLException { |
1870 | setObject(getNamedParamIndex(parameterName, false), x); |
1871 | } |
1872 | |
1873 | /** |
1874 | * @see java.sql.CallableStatement#setObject(java.lang.String, |
1875 | * java.lang.Object, int) |
1876 | */ |
1877 | public void setObject(String parameterName, Object x, int targetSqlType) |
1878 | throws SQLException { |
1879 | setObject(getNamedParamIndex(parameterName, false), x, targetSqlType); |
1880 | } |
1881 | |
1882 | /** |
1883 | * @see java.sql.CallableStatement#setObject(java.lang.String, |
1884 | * java.lang.Object, int, int) |
1885 | */ |
1886 | public void setObject(String parameterName, Object x, int targetSqlType, |
1887 | int scale) throws SQLException { |
1888 | } |
1889 | |
1890 | private void setOutParams() throws SQLException { |
1891 | if (this.paramInfo.numParameters > 0) { |
1892 | for (Iterator paramIter = this.paramInfo.iterator(); paramIter |
1893 | .hasNext();) { |
1894 | CallableStatementParam outParamInfo = (CallableStatementParam) paramIter |
1895 | .next(); |
1896 | |
1897 | if (outParamInfo.isOut) { |
1898 | String outParameterName = mangleParameterName(outParamInfo.paramName); |
1899 | |
1900 | int outParamIndex; |
1901 | |
1902 | if (this.placeholderToParameterIndexMap == null) { |
1903 | outParamIndex = outParamInfo.index + 1; |
1904 | } else { |
1905 | outParamIndex = this.placeholderToParameterIndexMap[outParamInfo.index - 1 /* JDBC is 1-based */]; |
1906 | } |
1907 | |
1908 | this.setBytesNoEscapeNoQuotes(outParamIndex, |
1909 | StringUtils.getBytes(outParameterName, |
1910 | this.charConverter, this.charEncoding, |
1911 | this.connection |
1912 | .getServerCharacterEncoding(), |
1913 | this.connection.parserKnowsUnicode())); |
1914 | } |
1915 | } |
1916 | } |
1917 | } |
1918 | |
1919 | /** |
1920 | * @see java.sql.CallableStatement#setShort(java.lang.String, short) |
1921 | */ |
1922 | public void setShort(String parameterName, short x) throws SQLException { |
1923 | setShort(getNamedParamIndex(parameterName, false), x); |
1924 | } |
1925 | |
1926 | /** |
1927 | * @see java.sql.CallableStatement#setString(java.lang.String, |
1928 | * java.lang.String) |
1929 | */ |
1930 | public void setString(String parameterName, String x) throws SQLException { |
1931 | setString(getNamedParamIndex(parameterName, false), x); |
1932 | } |
1933 | |
1934 | /** |
1935 | * @see java.sql.CallableStatement#setTime(java.lang.String, java.sql.Time) |
1936 | */ |
1937 | public void setTime(String parameterName, Time x) throws SQLException { |
1938 | setTime(getNamedParamIndex(parameterName, false), x); |
1939 | } |
1940 | |
1941 | /** |
1942 | * @see java.sql.CallableStatement#setTime(java.lang.String, java.sql.Time, |
1943 | * java.util.Calendar) |
1944 | */ |
1945 | public void setTime(String parameterName, Time x, Calendar cal) |
1946 | throws SQLException { |
1947 | setTime(getNamedParamIndex(parameterName, false), x, cal); |
1948 | } |
1949 | |
1950 | /** |
1951 | * @see java.sql.CallableStatement#setTimestamp(java.lang.String, |
1952 | * java.sql.Timestamp) |
1953 | */ |
1954 | public void setTimestamp(String parameterName, Timestamp x) |
1955 | throws SQLException { |
1956 | setTimestamp(getNamedParamIndex(parameterName, false), x); |
1957 | } |
1958 | |
1959 | /** |
1960 | * @see java.sql.CallableStatement#setTimestamp(java.lang.String, |
1961 | * java.sql.Timestamp, java.util.Calendar) |
1962 | */ |
1963 | public void setTimestamp(String parameterName, Timestamp x, Calendar cal) |
1964 | throws SQLException { |
1965 | setTimestamp(getNamedParamIndex(parameterName, false), x, cal); |
1966 | } |
1967 | |
1968 | /** |
1969 | * @see java.sql.CallableStatement#setURL(java.lang.String, java.net.URL) |
1970 | */ |
1971 | public void setURL(String parameterName, URL val) throws SQLException { |
1972 | setURL(getNamedParamIndex(parameterName, false), val); |
1973 | } |
1974 | |
1975 | /** |
1976 | * @see java.sql.CallableStatement#wasNull() |
1977 | */ |
1978 | public synchronized boolean wasNull() throws SQLException { |
1979 | return this.outputParamWasNull; |
1980 | } |
1981 | |
1982 | public int[] executeBatch() throws SQLException { |
1983 | if (this.hasOutputParams) { |
1984 | throw SQLError.createSQLException("Can't call executeBatch() on CallableStatement with OUTPUT parameters", |
1985 | SQLError.SQL_STATE_ILLEGAL_ARGUMENT); |
1986 | } |
1987 | |
1988 | return super.executeBatch(); |
1989 | } |
1990 | } |