Source Code Cross Referenced for CallableStatement.java in  » Database-JDBC-Connection-Pool » sequoia-2.10.9 » org » continuent » sequoia » driver » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » sequoia 2.10.9 » org.continuent.sequoia.driver 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * Sequoia: Database clustering technology.
0003:         * Copyright (C) 2002-2004 French National Institute For Research In Computer
0004:         * Science And Control (INRIA).
0005:         * Copyright (C) 2005 Continuent, Inc.
0006:         * Contact: sequoia@continuent.org
0007:         * 
0008:         * Licensed under the Apache License, Version 2.0 (the "License");
0009:         * you may not use this file except in compliance with the License.
0010:         * You may obtain a copy of the License at
0011:         * 
0012:         * http://www.apache.org/licenses/LICENSE-2.0
0013:         * 
0014:         * Unless required by applicable law or agreed to in writing, software
0015:         * distributed under the License is distributed on an "AS IS" BASIS,
0016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017:         * See the License for the specific language governing permissions and
0018:         * limitations under the License. 
0019:         *
0020:         * Initial developer(s): Emmanuel Cecchet.
0021:         * Contributor(s): ______________________________________.
0022:         */package org.continuent.sequoia.driver;
0023:
0024:        import java.io.ByteArrayOutputStream;
0025:        import java.io.IOException;
0026:        import java.io.InputStream;
0027:        import java.io.ObjectOutputStream;
0028:        import java.io.Reader;
0029:        import java.io.Serializable;
0030:        import java.math.BigDecimal;
0031:        import java.net.URL;
0032:        import java.sql.Array;
0033:        import java.sql.BatchUpdateException;
0034:        import java.sql.Blob;
0035:        import java.sql.Clob;
0036:        import java.sql.Date;
0037:        import java.sql.Ref;
0038:        import java.sql.ResultSet;
0039:        import java.sql.SQLException;
0040:        import java.sql.SQLWarning;
0041:        import java.sql.Time;
0042:        import java.sql.Timestamp;
0043:        import java.sql.Types;
0044:        import java.util.Calendar;
0045:        import java.util.HashMap;
0046:        import java.util.Iterator;
0047:        import java.util.LinkedList;
0048:        import java.util.List;
0049:        import java.util.Map;
0050:
0051:        import org.continuent.sequoia.common.exceptions.NotImplementedException;
0052:        import org.continuent.sequoia.common.protocol.PreparedStatementSerialization;
0053:        import org.continuent.sequoia.common.sql.Request;
0054:        import org.continuent.sequoia.common.sql.RequestWithResultSetParameters;
0055:        import org.continuent.sequoia.common.sql.filters.AbstractBlobFilter;
0056:        import org.continuent.sequoia.common.util.Strings;
0057:
0058:        /**
0059:         * This class is used to execute SQL stored procedures. The JDBC API provides a
0060:         * stored procedure SQL escape syntax that allows stored procedures to be called
0061:         * in a standard way for all RDBMSs. The syntax accepted by this implementation
0062:         * is as follows:
0063:         * 
0064:         * <pre>
0065:         *  {call &lt;procedure-name&gt;[&lt;arg1&gt;,&lt;arg2&gt;, ...]}
0066:         * </pre>
0067:         * 
0068:         * or (since Sequoia 2.7)
0069:         * 
0070:         * <pre>
0071:         *  {?= call &lt;procedure-name&gt;[&lt;arg1&gt;,&lt;arg2&gt;, ...]}
0072:         * </pre>
0073:         * 
0074:         * Parameters are referred to sequentially, by number, with the first parameter
0075:         * being 1. IN parameter values are set using the <code>set</code> methods
0076:         * inherited from {@link PreparedStatement}.
0077:         * <p>
0078:         * OUT and JDBC 3 named parameters are implemented in this class.
0079:         * <p>
0080:         * A <code>CallableStatement</code> can return one {@link DriverResultSet}
0081:         * object or multiple <code>ResultSet</code> objects. Multiple
0082:         * <code>ResultSet</code> objects are handled using operations inherited from
0083:         * {@link Statement}.
0084:         * 
0085:         * @see org.continuent.sequoia.driver.Connection#prepareCall(String)
0086:         * @see DriverResultSet
0087:         * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
0088:         * @version 1.0
0089:         */
0090:        public class CallableStatement extends PreparedStatement implements 
0091:                java.sql.CallableStatement {
0092:            // Values returned by out parameters
0093:            private HashMap outParameters = null;
0094:            // Out and named parameter types set by the application
0095:            private HashMap outAndNamedParameterTypes = null;
0096:            // Named parameter returned values
0097:            private HashMap namedParameterValues = null;
0098:            private int lastOutParameterIndex = -1;
0099:
0100:            /**
0101:             * <code>CallableStatements</code> syntax is {call procedure_name[(?, ?,
0102:             * ...)]}. Note that {? = call ...} is not supported by this implementation.
0103:             * 
0104:             * @param connection the instanatiating connection
0105:             * @param sql the SQL statement with ? for IN markers
0106:             * @param driver the Driver used to create connections
0107:             */
0108:            public CallableStatement(Connection connection, String sql,
0109:                    Driver driver) {
0110:                super (connection, sql, driver);
0111:            }
0112:
0113:            /**
0114:             * Add names parameters at the end of regular parameters.
0115:             * 
0116:             * @see PreparedStatement#compileParameters(boolean)
0117:             */
0118:            protected synchronized String compileParameters()
0119:                    throws SQLException {
0120:                // Call PreparedStatement.compileParameters()
0121:                String parameters = super .compileParameters(true);
0122:
0123:                if (outAndNamedParameterTypes == null)
0124:                    return parameters;
0125:
0126:                // Append named parameters but reuse sbuf set by super.compileParameters()
0127:                // for more efficiency
0128:                for (Iterator iter = outAndNamedParameterTypes.values()
0129:                        .iterator(); iter.hasNext();) {
0130:                    String namedParam = (String) iter.next();
0131:                    sbuf.append(namedParam);
0132:                }
0133:                return trimStringBuffer();
0134:            }
0135:
0136:            /**
0137:             * @see org.continuent.sequoia.driver.PreparedStatement#execute()
0138:             */
0139:            public boolean execute() throws SQLException {
0140:                if (isClosed()) {
0141:                    throw new SQLException(
0142:                            "Unable to execute query on a closed statement");
0143:                }
0144:                RequestWithResultSetParameters proc = new RequestWithResultSetParameters(
0145:                        sql, compileParameters(), escapeProcessing, timeout);
0146:                setReadRequestParameters(proc);
0147:                ResultAndWarnings result = connection
0148:                        .callableStatementExecute(proc);
0149:                warnings = result.getStatementWarnings();
0150:                List resultWithParameters = result.getResultList();
0151:                resultList = (LinkedList) resultWithParameters.get(0);
0152:                resultListIterator = resultList.iterator();
0153:                outParameters = (HashMap) resultWithParameters.get(1);
0154:                namedParameterValues = (HashMap) resultWithParameters.get(2);
0155:
0156:                return getMoreResults();
0157:            }
0158:
0159:            /**
0160:             * Execute a batch of commands
0161:             * 
0162:             * @return an array containing update count that corresponding to the commands
0163:             *         that executed successfully
0164:             * @exception BatchUpdateException if an error occurs on one statement (the
0165:             *              number of updated rows for the successfully executed
0166:             *              statements can be found in
0167:             *              BatchUpdateException.getUpdateCounts())
0168:             */
0169:            public int[] executeBatch() throws BatchUpdateException {
0170:                if (batch == null || batch.isEmpty())
0171:                    return new int[0];
0172:
0173:                int size = batch.size();
0174:                int[] nbsRowsUpdated = new int[size];
0175:                int i = 0;
0176:                // must keep warning in a separate place otherwise they will be erased at
0177:                // each call to executeUpdate()
0178:                SQLWarning allWarnings = null;
0179:                try {
0180:                    for (i = 0; i < size; i++) {
0181:                        BatchElement be = (BatchElement) batch.elementAt(i);
0182:                        Request proc = new Request(be.getSqlTemplate(), be
0183:                                .getParameters(), escapeProcessing, timeout);
0184:
0185:                        ResultAndWarnings result = connection
0186:                                .callableStatementExecuteUpdate(proc);
0187:                        if (result.getStatementWarnings() != null)
0188:                            addWarningTo(result.getStatementWarnings(),
0189:                                    allWarnings);
0190:                        List resultWithParameters = result.getResultList();
0191:                        nbsRowsUpdated[i] = ((Integer) resultWithParameters
0192:                                .get(0)).intValue();
0193:                        // Not sure what to do with OUT and named parameters. Just keep them in
0194:                        // case someone wants to access the ones returned by the last executed
0195:                        // statement.
0196:                        outParameters = (HashMap) resultWithParameters.get(1);
0197:                        namedParameterValues = (HashMap) resultWithParameters
0198:                                .get(2);
0199:                    }
0200:                    // make one chain with all generated warnings
0201:                    warnings = allWarnings;
0202:                    return nbsRowsUpdated;
0203:                } catch (SQLException e) {
0204:                    String message = "Batch failed for request "
0205:                            + i
0206:                            + ": "
0207:                            + ((BatchElement) batch.elementAt(i))
0208:                                    .getSqlTemplate() + " (" + e + ")";
0209:
0210:                    // shrink the returned array
0211:                    int[] updateCounts = new int[i];
0212:                    System.arraycopy(nbsRowsUpdated, 0, updateCounts, 0, i);
0213:
0214:                    throw new BatchUpdateException(message, updateCounts);
0215:                } finally {
0216:                    batch.removeAllElements();
0217:                }
0218:            }
0219:
0220:            /**
0221:             * @see org.continuent.sequoia.driver.PreparedStatement#executeQuery()
0222:             */
0223:            public ResultSet executeQuery() throws SQLException {
0224:                if (isClosed()) {
0225:                    throw new SQLException(
0226:                            "Unable to execute query on a closed statement");
0227:                }
0228:                updateCount = -1; // invalidate the last write result
0229:                if (result != null) { // Discard the previous result
0230:                    result.close();
0231:                    result = null;
0232:                }
0233:
0234:                RequestWithResultSetParameters proc = new RequestWithResultSetParameters(
0235:                        sql, compileParameters(), escapeProcessing, timeout);
0236:                setReadRequestParameters(proc);
0237:                ResultAndWarnings res = connection
0238:                        .callableStatementExecuteQuery(proc);
0239:                warnings = res.getStatementWarnings();
0240:                List resultWithParameters = res.getResultList();
0241:                result = (ResultSet) resultWithParameters.get(0);
0242:                outParameters = (HashMap) resultWithParameters.get(1);
0243:                namedParameterValues = (HashMap) resultWithParameters.get(2);
0244:                if (result instanceof  DriverResultSet)
0245:                    ((DriverResultSet) result).setStatement(this );
0246:                return result;
0247:            }
0248:
0249:            /**
0250:             * @see org.continuent.sequoia.driver.PreparedStatement#executeUpdate()
0251:             */
0252:            public int executeUpdate() throws SQLException {
0253:                if (isClosed()) {
0254:                    throw new SQLException(
0255:                            "Unable to execute query on a closed statement");
0256:                }
0257:                if (result != null) { // Discard the previous result
0258:                    result.close();
0259:                    result = null;
0260:                }
0261:                Request proc = new Request(sql, compileParameters(),
0262:                        escapeProcessing, timeout);
0263:                ResultAndWarnings result = connection
0264:                        .callableStatementExecuteUpdate(proc);
0265:                this .warnings = result.getStatementWarnings();
0266:                List resultWithParameters = result.getResultList();
0267:                updateCount = ((Integer) resultWithParameters.get(0))
0268:                        .intValue();
0269:                outParameters = (HashMap) resultWithParameters.get(1);
0270:                namedParameterValues = (HashMap) resultWithParameters.get(2);
0271:
0272:                return updateCount;
0273:            }
0274:
0275:            /**
0276:             * Registers the OUT parameter in ordinal position <code>parameterIndex</code>
0277:             * to the JDBC type <code>sqlType</code>. All OUT parameters must be
0278:             * registered before a stored procedure is executed.
0279:             * <p>
0280:             * The JDBC type specified by <code>sqlType</code> for an OUT parameter
0281:             * determines the Java type that must be used in the <code>get</code> method
0282:             * to read the value of that parameter.
0283:             * <p>
0284:             * If the JDBC type expected to be returned to this output parameter is
0285:             * specific to this particular database, <code>sqlType</code> should be
0286:             * <code>java.sql.Types.OTHER</code>. The method {@link #getObject(int)}
0287:             * retrieves the value.
0288:             * 
0289:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0290:             * @param sqlType the JDBC type code defined by <code>java.sql.Types</code>.
0291:             *          If the parameter is of JDBC type <code>NUMERIC</code> or
0292:             *          <code>DECIMAL</code>, the version of
0293:             *          <code>registerOutParameter</code> that accepts a scale value
0294:             *          should be used.
0295:             * @exception SQLException if a database access error occurs
0296:             * @see java.sql.Types
0297:             */
0298:            public void registerOutParameter(int parameterIndex, int sqlType)
0299:                    throws SQLException {
0300:                setOutParameterWithTag(String.valueOf(parameterIndex),
0301:                        PreparedStatementSerialization.REGISTER_OUT_PARAMETER,
0302:                        String.valueOf(sqlType));
0303:            }
0304:
0305:            /**
0306:             * Registers the parameter in ordinal position <code>parameterIndex</code>
0307:             * to be of JDBC type <code>sqlType</code>. This method must be called
0308:             * before a stored procedure is executed.
0309:             * <p>
0310:             * The JDBC type specified by <code>sqlType</code> for an OUT parameter
0311:             * determines the Java type that must be used in the <code>get</code> method
0312:             * to read the value of that parameter.
0313:             * <p>
0314:             * This version of <code>registerOutParameter</code> should be used when the
0315:             * parameter is of JDBC type <code>NUMERIC</code> or <code>DECIMAL</code>.
0316:             * 
0317:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0318:             * @param sqlType the SQL type code defined by <code>java.sql.Types</code>.
0319:             * @param scale the desired number of digits to the right of the decimal
0320:             *          point. It must be greater than or equal to zero.
0321:             * @exception SQLException if a database access error occurs
0322:             * @see java.sql.Types
0323:             */
0324:            public void registerOutParameter(int parameterIndex, int sqlType,
0325:                    int scale) throws SQLException {
0326:                setOutParameterWithTag(
0327:                        String.valueOf(parameterIndex),
0328:                        PreparedStatementSerialization.REGISTER_OUT_PARAMETER_WITH_SCALE,
0329:                        sqlType + "," + scale);
0330:            }
0331:
0332:            /**
0333:             * Registers the designated output parameter. This version of the method
0334:             * <code>registerOutParameter</code> should be used for a user-defined or
0335:             * <code>REF</code> output parameter. Examples of user-defined types
0336:             * include: <code>STRUCT</code>,<code>DISTINCT</code>,
0337:             * <code>JAVA_OBJECT</code>, and named array types.
0338:             * <p>
0339:             * Before executing a stored procedure call, you must explicitly call
0340:             * <code>registerOutParameter</code> to register the type from
0341:             * <code>java.sql.Types</code> for each OUT parameter. For a user-defined
0342:             * parameter, the fully-qualified SQL type name of the parameter should also
0343:             * be given, while a <code>REF</code> parameter requires that the
0344:             * fully-qualified type name of the referenced type be given. A JDBC driver
0345:             * that does not need the type code and type name information may ignore it.
0346:             * To be portable, however, applications should always provide these values
0347:             * for user-defined and <code>REF</code> parameters.
0348:             * <p>
0349:             * Although it is intended for user-defined and <code>REF</code> parameters,
0350:             * this method may be used to register a parameter of any JDBC type. If the
0351:             * parameter does not have a user-defined or <code>REF</code> type, the
0352:             * <i>typeName </i> parameter is ignored.
0353:             * <p>
0354:             * <b>Note: </b> When reading the value of an out parameter, you must use the
0355:             * getter method whose Java type corresponds to the parameter's registered SQL
0356:             * type.
0357:             * 
0358:             * @param paramIndex the first parameter is 1, the second is 2,...
0359:             * @param sqlType a value from {@link java.sql.Types}
0360:             * @param typeName the fully-qualified name of an SQL structured type
0361:             * @exception SQLException if a database access error occurs
0362:             * @see java.sql.Types
0363:             * @since 1.2
0364:             */
0365:            public void registerOutParameter(int paramIndex, int sqlType,
0366:                    String typeName) throws SQLException {
0367:                setOutParameterWithTag(
0368:                        String.valueOf(paramIndex),
0369:                        PreparedStatementSerialization.REGISTER_OUT_PARAMETER_WITH_NAME,
0370:                        sqlType + "," + typeName);
0371:            }
0372:
0373:            /**
0374:             * Get the Java SQL type of an OUT parameter. Throws an SQLException if the
0375:             * parameter was not an OUT parameter.
0376:             * 
0377:             * @param parameterIndex parameter index
0378:             * @return Java SQL type
0379:             * @throws SQLException if the parameter is not an out parameter or an invalid
0380:             *           parameter
0381:             */
0382:            private int getOutParameterType(int parameterIndex)
0383:                    throws SQLException {
0384:                lastOutParameterIndex = -1;
0385:
0386:                if (outParameters == null)
0387:                    throw new SQLException("No OUT parameter has been returned");
0388:
0389:                lastOutParameterIndex = parameterIndex;
0390:
0391:                String type = (String) outAndNamedParameterTypes.get(Integer
0392:                        .toString(parameterIndex));
0393:                if (type != null) {
0394:                    int typeStart = PreparedStatementSerialization.START_PARAM_TAG
0395:                            .length();
0396:                    String paramType = type.substring(typeStart, typeStart
0397:                            + PreparedStatementSerialization.BOOLEAN_TAG
0398:                                    .length());
0399:                    String paramValue = type
0400:                            .substring(
0401:                                    typeStart
0402:                                            + PreparedStatementSerialization.BOOLEAN_TAG
0403:                                                    .length(),
0404:                                    type
0405:                                            .indexOf(PreparedStatementSerialization.END_PARAM_TAG));
0406:
0407:                    // paramType is a NAMED_PARAMETER_TAG
0408:
0409:                    // Value is composed of: paramName,paramTypeparamValue
0410:                    // paramName is equal to parameterIndex (just ignore it)
0411:                    // paramTypeparamValue should be the out parameter and its value
0412:                    int comma = paramValue.indexOf(",");
0413:                    paramValue = paramValue.substring(comma + 1);
0414:
0415:                    if (paramType
0416:                            .startsWith(PreparedStatementSerialization.REGISTER_OUT_PARAMETER))
0417:                        return Integer.parseInt(paramValue);
0418:                    if (paramType
0419:                            .startsWith(PreparedStatementSerialization.REGISTER_OUT_PARAMETER_WITH_NAME))
0420:                        return Integer.parseInt(paramValue.substring(0,
0421:                                paramValue.indexOf(',')));
0422:                    if (paramType
0423:                            .startsWith(PreparedStatementSerialization.REGISTER_OUT_PARAMETER_WITH_SCALE))
0424:                        return Integer.parseInt(paramValue.substring(0,
0425:                                paramValue.indexOf(',')));
0426:                }
0427:                throw new SQLException("Parameter " + parameterIndex
0428:                        + " is not a registered OUT parameter");
0429:            }
0430:
0431:            /**
0432:             * Retrieves whether the last OUT parameter read had the value of SQL
0433:             * <code>NULL</code>. Note that this method should be called only after
0434:             * calling a getter method; otherwise, there is no value to use in determining
0435:             * whether it is <code>null</code> or not.
0436:             * 
0437:             * @return <code>true</code> if the last parameter read was SQL
0438:             *         <code>NULL</code>;<code>false</code> otherwise
0439:             * @exception SQLException if a database access error occurs
0440:             */
0441:            public boolean wasNull() throws SQLException {
0442:                if (lastOutParameterIndex == -1)
0443:                    return false;
0444:                return (outParameters.get(new Integer(lastOutParameterIndex)) == null);
0445:            }
0446:
0447:            /**
0448:             * Retrieves the value of the designated JDBC <code>CHAR</code>,
0449:             * <code>VARCHAR</code>, or <code>LONGVARCHAR</code> parameter as a
0450:             * <code>String</code> in the Java programming language.
0451:             * <p>
0452:             * For the fixed-length type JDBC <code>CHAR</code>, the
0453:             * <code>String</code> object returned has exactly the same value the JDBC
0454:             * <code>CHAR</code> value had in the database, including any padding added
0455:             * by the database.
0456:             * 
0457:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0458:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0459:             *         result is <code>null</code>.
0460:             * @exception SQLException if a database access error occurs
0461:             * @see #setString
0462:             */
0463:            public String getString(int parameterIndex) throws SQLException {
0464:                int type = getOutParameterType(parameterIndex);
0465:                switch (type) {
0466:                case Types.CHAR:
0467:                case Types.VARCHAR:
0468:                case Types.LONGVARCHAR:
0469:                    return (String) outParameters.get(new Integer(
0470:                            parameterIndex));
0471:                default:
0472:                    throw new SQLException(
0473:                            "Cannot convert OUT parameter of type " + type
0474:                                    + " to the requested type.");
0475:                }
0476:            }
0477:
0478:            /**
0479:             * Retrieves the value of the designated JDBC <code>BIT</code> parameter as
0480:             * a <code>boolean</code> in the Java programming language.
0481:             * 
0482:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0483:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0484:             *         result is <code>false</code>.
0485:             * @exception SQLException if a database access error occurs
0486:             * @see #setBoolean
0487:             */
0488:            public boolean getBoolean(int parameterIndex) throws SQLException {
0489:                int type = getOutParameterType(parameterIndex);
0490:                switch (type) {
0491:                case Types.BIT:
0492:                    Boolean b = (Boolean) outParameters.get(new Integer(
0493:                            parameterIndex));
0494:                    if (b == null)
0495:                        return false;
0496:                    else
0497:                        return b.booleanValue();
0498:                default:
0499:                    throw new SQLException(
0500:                            "Cannot convert OUT parameter of type " + type
0501:                                    + " to the requested type.");
0502:                }
0503:            }
0504:
0505:            /**
0506:             * Retrieves the value of the designated JDBC <code>TINYINT</code> parameter
0507:             * as a <code>byte</code> in the Java programming language.
0508:             * 
0509:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0510:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0511:             *         result is <code>0</code>.
0512:             * @exception SQLException if a database access error occurs
0513:             * @see #setByte
0514:             */
0515:            public byte getByte(int parameterIndex) throws SQLException {
0516:                int type = getOutParameterType(parameterIndex);
0517:                switch (type) {
0518:                case Types.TINYINT:
0519:                    Number b = (Number) outParameters.get(new Integer(
0520:                            parameterIndex));
0521:                    if (b == null)
0522:                        return 0;
0523:                    else
0524:                        return b.byteValue();
0525:                default:
0526:                    throw new SQLException(
0527:                            "Cannot convert OUT parameter of type " + type
0528:                                    + " to the requested type.");
0529:                }
0530:            }
0531:
0532:            /**
0533:             * Retrieves the value of the designated JDBC <code>SMALLINT</code>
0534:             * parameter as a <code>short</code> in the Java programming language.
0535:             * 
0536:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0537:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0538:             *         result is <code>0</code>.
0539:             * @exception SQLException if a database access error occurs
0540:             * @see #setShort
0541:             */
0542:            public short getShort(int parameterIndex) throws SQLException {
0543:                int type = getOutParameterType(parameterIndex);
0544:                switch (type) {
0545:                case Types.SMALLINT:
0546:                    Number s = (Number) outParameters.get(new Integer(
0547:                            parameterIndex));
0548:                    if (s == null)
0549:                        return 0;
0550:                    else
0551:                        return s.shortValue();
0552:                default:
0553:                    throw new SQLException(
0554:                            "Cannot convert OUT parameter of type " + type
0555:                                    + " to the requested type.");
0556:                }
0557:            }
0558:
0559:            /**
0560:             * Retrieves the value of the designated JDBC <code>INTEGER</code> parameter
0561:             * as an <code>int</code> in the Java programming language.
0562:             * 
0563:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0564:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0565:             *         result is <code>0</code>.
0566:             * @exception SQLException if a database access error occurs
0567:             * @see #setInt
0568:             */
0569:            public int getInt(int parameterIndex) throws SQLException {
0570:                int type = getOutParameterType(parameterIndex);
0571:                switch (type) {
0572:                case Types.INTEGER:
0573:                    Integer i = (Integer) outParameters.get(new Integer(
0574:                            parameterIndex));
0575:                    if (i == null)
0576:                        return 0;
0577:                    else
0578:                        return i.intValue();
0579:                default:
0580:                    throw new SQLException(
0581:                            "Cannot convert OUT parameter of type " + type
0582:                                    + " to the requested type.");
0583:                }
0584:            }
0585:
0586:            /**
0587:             * Retrieves the value of the designated JDBC <code>BIGINT</code> parameter
0588:             * as a <code>long</code> in the Java programming language.
0589:             * 
0590:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0591:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0592:             *         result is <code>0</code>.
0593:             * @exception SQLException if a database access error occurs
0594:             * @see #setLong
0595:             */
0596:            public long getLong(int parameterIndex) throws SQLException {
0597:                int type = getOutParameterType(parameterIndex);
0598:                switch (type) {
0599:                case Types.BIGINT:
0600:                    Long l = (Long) outParameters.get(new Integer(
0601:                            parameterIndex));
0602:                    if (l == null)
0603:                        return 0;
0604:                    else
0605:                        return l.longValue();
0606:                default:
0607:                    throw new SQLException(
0608:                            "Cannot convert OUT parameter of type " + type
0609:                                    + " to the requested type.");
0610:                }
0611:            }
0612:
0613:            /**
0614:             * Retrieves the value of the designated JDBC <code>FLOAT</code> parameter
0615:             * as a <code>float</code> in the Java programming language.
0616:             * 
0617:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0618:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0619:             *         result is <code>0</code>.
0620:             * @exception SQLException if a database access error occurs
0621:             * @see #setFloat
0622:             */
0623:            public float getFloat(int parameterIndex) throws SQLException {
0624:                int type = getOutParameterType(parameterIndex);
0625:                switch (type) {
0626:                case Types.FLOAT:
0627:                case Types.REAL:
0628:                    Float f = (Float) outParameters.get(new Integer(
0629:                            parameterIndex));
0630:                    if (f == null)
0631:                        return 0;
0632:                    else
0633:                        return f.floatValue();
0634:                default:
0635:                    throw new SQLException(
0636:                            "Cannot convert OUT parameter of type " + type
0637:                                    + " to the requested type.");
0638:                }
0639:            }
0640:
0641:            /**
0642:             * Retrieves the value of the designated JDBC <code>DOUBLE</code> parameter
0643:             * as a <code>double</code> in the Java programming language.
0644:             * 
0645:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0646:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0647:             *         result is <code>0</code>.
0648:             * @exception SQLException if a database access error occurs
0649:             * @see #setDouble
0650:             */
0651:            public double getDouble(int parameterIndex) throws SQLException {
0652:                int type = getOutParameterType(parameterIndex);
0653:                switch (type) {
0654:                case Types.DOUBLE:
0655:                case Types.FLOAT:
0656:                    Double d = (Double) outParameters.get(new Integer(
0657:                            parameterIndex));
0658:                    if (d == null)
0659:                        return 0;
0660:                    else
0661:                        return d.doubleValue();
0662:                default:
0663:                    throw new SQLException(
0664:                            "Cannot convert OUT parameter of type " + type
0665:                                    + " to the requested type.");
0666:                }
0667:            }
0668:
0669:            /**
0670:             * Retrieves the value of the designated JDBC <code>NUMERIC</code> parameter
0671:             * as a <code>java.math.BigDecimal</code> object with <i>scale </i> digits
0672:             * to the right of the decimal point.
0673:             * 
0674:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0675:             * @param scale the number of digits to the right of the decimal point
0676:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0677:             *         result is <code>null</code>.
0678:             * @exception SQLException if a database access error occurs
0679:             * @deprecated use <code>getBigDecimal(int parameterIndex)</code> or
0680:             *             <code>getBigDecimal(String parameterName)</code>
0681:             * @see #setBigDecimal
0682:             */
0683:            public BigDecimal getBigDecimal(int parameterIndex, int scale)
0684:                    throws SQLException {
0685:                return getBigDecimal(parameterIndex);
0686:            }
0687:
0688:            /**
0689:             * Retrieves the value of the designated JDBC <code>BINARY</code> or
0690:             * <code>VARBINARY</code> parameter as an array of <code>byte</code>
0691:             * values in the Java programming language.
0692:             * 
0693:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0694:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0695:             *         result is <code>null</code>.
0696:             * @exception SQLException if a database access error occurs
0697:             * @see #setBytes
0698:             */
0699:            public byte[] getBytes(int parameterIndex) throws SQLException {
0700:                int type = getOutParameterType(parameterIndex);
0701:                switch (type) {
0702:                case Types.BINARY:
0703:                    return (byte[]) outParameters.get(new Integer(
0704:                            parameterIndex));
0705:                default:
0706:                    throw new SQLException(
0707:                            "Cannot convert OUT parameter of type " + type
0708:                                    + " to the requested type.");
0709:                }
0710:
0711:            }
0712:
0713:            /**
0714:             * Retrieves the value of the designated JDBC <code>DATE</code> parameter as
0715:             * a <code>java.sql.Date</code> object.
0716:             * 
0717:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0718:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0719:             *         result is <code>null</code>.
0720:             * @exception SQLException if a database access error occurs
0721:             * @see #setDate(String, Date)
0722:             */
0723:            public Date getDate(int parameterIndex) throws SQLException {
0724:                int type = getOutParameterType(parameterIndex);
0725:                switch (type) {
0726:                case Types.DATE:
0727:                    return (Date) outParameters
0728:                            .get(new Integer(parameterIndex));
0729:                default:
0730:                    throw new SQLException(
0731:                            "Cannot convert OUT parameter of type " + type
0732:                                    + " to the requested type.");
0733:                }
0734:            }
0735:
0736:            /**
0737:             * Retrieves the value of the designated JDBC <code>TIME</code> parameter as
0738:             * a <code>java.sql.Time</code> object.
0739:             * 
0740:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0741:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0742:             *         result is <code>null</code>.
0743:             * @exception SQLException if a database access error occurs
0744:             * @see #setTime(String, Time)
0745:             */
0746:            public Time getTime(int parameterIndex) throws SQLException {
0747:                int type = getOutParameterType(parameterIndex);
0748:                switch (type) {
0749:                case Types.TIME:
0750:                    return (Time) outParameters
0751:                            .get(new Integer(parameterIndex));
0752:                default:
0753:                    throw new SQLException(
0754:                            "Cannot convert OUT parameter of type " + type
0755:                                    + " to the requested type.");
0756:                }
0757:            }
0758:
0759:            /**
0760:             * Retrieves the value of the designated JDBC <code>TIMESTAMP</code>
0761:             * parameter as a <code>java.sql.Timestamp</code> object.
0762:             * 
0763:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0764:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0765:             *         result is <code>null</code>.
0766:             * @exception SQLException if a database access error occurs
0767:             * @see #setTimestamp(String, Timestamp)
0768:             */
0769:            public Timestamp getTimestamp(int parameterIndex)
0770:                    throws SQLException {
0771:                int type = getOutParameterType(parameterIndex);
0772:                switch (type) {
0773:                case Types.TIMESTAMP:
0774:                    return (Timestamp) outParameters.get(new Integer(
0775:                            parameterIndex));
0776:                default:
0777:                    throw new SQLException(
0778:                            "Cannot convert OUT parameter of type " + type
0779:                                    + " to the requested type.");
0780:                }
0781:            }
0782:
0783:            // ----------------------------------------------------------------------
0784:            // Advanced features:
0785:
0786:            /**
0787:             * Retrieves the value of the designated parameter as an <code>Object</code>
0788:             * in the Java programming language. If the value is an SQL <code>NULL</code>,
0789:             * the driver returns a Java <code>null</code>.
0790:             * <p>
0791:             * This method returns a Java object whose type corresponds to the JDBC type
0792:             * that was registered for this parameter using the method
0793:             * <code>registerOutParameter</code>. By registering the target JDBC type
0794:             * as <code>java.sql.Types.OTHER</code>, this method can be used to read
0795:             * database-specific abstract data types.
0796:             * 
0797:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0798:             * @return A <code>java.lang.Object</code> holding the OUT parameter value
0799:             * @exception SQLException if a database access error occurs
0800:             * @see java.sql.Types
0801:             * @see #setObject(String, Object)
0802:             */
0803:            public Object getObject(int parameterIndex) throws SQLException {
0804:                // Check type first (throw an exception if invalid)
0805:                getOutParameterType(parameterIndex);
0806:                return outParameters.get(new Integer(parameterIndex));
0807:            }
0808:
0809:            // --------------------------JDBC 2.0-----------------------------
0810:
0811:            /**
0812:             * Retrieves the value of the designated JDBC <code>NUMERIC</code> parameter
0813:             * as a <code>java.math.BigDecimal</code> object with as many digits to the
0814:             * right of the decimal point as the value contains.
0815:             * 
0816:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0817:             * @return the parameter value in full precision. If the value is SQL
0818:             *         <code>NULL</code>, the result is <code>null</code>.
0819:             * @exception SQLException if a database access error occurs
0820:             * @see #setBigDecimal
0821:             * @since 1.2
0822:             */
0823:            public BigDecimal getBigDecimal(int parameterIndex)
0824:                    throws SQLException {
0825:                int type = getOutParameterType(parameterIndex);
0826:                switch (type) {
0827:                case Types.NUMERIC:
0828:                case Types.DECIMAL:
0829:                    return (BigDecimal) outParameters.get(new Integer(
0830:                            parameterIndex));
0831:                default:
0832:                    throw new SQLException(
0833:                            "Cannot convert OUT parameter of type " + type
0834:                                    + " to the requested type.");
0835:                }
0836:            }
0837:
0838:            /**
0839:             * Returns an object representing the value of OUT parameter <code>i</code>
0840:             * and uses <code>map</code> for the custom mapping of the parameter value.
0841:             * <p>
0842:             * This method returns a Java object whose type corresponds to the JDBC type
0843:             * that was registered for this parameter using the method
0844:             * <code>registerOutParameter</code>. By registering the target JDBC type
0845:             * as <code>java.sql.Types.OTHER</code>, this method can be used to read
0846:             * database-specific abstract data types.
0847:             * 
0848:             * @param i the first parameter is 1, the second is 2, and so on
0849:             * @param map the mapping from SQL type names to Java classes
0850:             * @return a <code>java.lang.Object</code> holding the OUT parameter value
0851:             * @exception SQLException if a database access error occurs
0852:             * @see #setObject(String, Object)
0853:             * @since 1.2
0854:             */
0855:            public Object getObject(int i, Map map) throws SQLException {
0856:                throw new NotImplementedException("getObject");
0857:            }
0858:
0859:            /**
0860:             * Retrieves the value of the designated JDBC
0861:             * <code>REF(&lt;structured-type&gt;)</code> parameter as a <code>Ref</code>
0862:             * object in the Java programming language.
0863:             * 
0864:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0865:             * @return the parameter value as a <code>Ref</code> object in the Java
0866:             *         programming language. If the value was SQL <code>NULL</code>,
0867:             *         the value <code>null</code> is returned.
0868:             * @exception SQLException if a database access error occurs
0869:             * @since 1.2
0870:             */
0871:            public Ref getRef(int parameterIndex) throws SQLException {
0872:                int type = getOutParameterType(parameterIndex);
0873:                switch (type) {
0874:                case Types.REF:
0875:                    return (Ref) outParameters.get(new Integer(parameterIndex));
0876:                default:
0877:                    throw new SQLException(
0878:                            "Cannot convert OUT parameter of type " + type
0879:                                    + " to the requested type.");
0880:                }
0881:            }
0882:
0883:            /**
0884:             * Retrieves the value of the designated JDBC <code>BLOB</code> parameter as
0885:             * a {@link Blob}object in the Java programming language.
0886:             * 
0887:             * @param i the first parameter is 1, the second is 2, and so on
0888:             * @return the parameter value as a <code>Blob</code> object in the Java
0889:             *         programming language. If the value was SQL <code>NULL</code>,
0890:             *         the value <code>null</code> is returned.
0891:             * @exception SQLException if a database access error occurs
0892:             * @since 1.2
0893:             */
0894:            public Blob getBlob(int i) throws SQLException {
0895:                int type = getOutParameterType(i);
0896:                switch (type) {
0897:                case Types.BLOB:
0898:                    return (Blob) outParameters.get(new Integer(i));
0899:                default:
0900:                    throw new SQLException(
0901:                            "Cannot convert OUT parameter of type " + type
0902:                                    + " to the requested type.");
0903:                }
0904:            }
0905:
0906:            /**
0907:             * Retrieves the value of the designated JDBC <code>CLOB</code> parameter as
0908:             * a <code>Clob</code> object in the Java programming language.
0909:             * 
0910:             * @param i the first parameter is 1, the second is 2, and so on
0911:             * @return the parameter value as a <code>Clob</code> object in the Java
0912:             *         programming language. If the value was SQL <code>NULL</code>,
0913:             *         the value <code>null</code> is returned.
0914:             * @exception SQLException if a database access error occurs
0915:             * @since 1.2
0916:             */
0917:            public Clob getClob(int i) throws SQLException {
0918:                int type = getOutParameterType(i);
0919:                switch (type) {
0920:                case Types.CLOB:
0921:                    return (Clob) outParameters.get(new Integer(i));
0922:                default:
0923:                    throw new SQLException(
0924:                            "Cannot convert OUT parameter of type " + type
0925:                                    + " to the requested type.");
0926:                }
0927:            }
0928:
0929:            /**
0930:             * Retrieves the value of the designated JDBC <code>ARRAY</code> parameter
0931:             * as an {@link Array}object in the Java programming language.
0932:             * 
0933:             * @param i the first parameter is 1, the second is 2, and so on
0934:             * @return the parameter value as an <code>Array</code> object in the Java
0935:             *         programming language. If the value was SQL <code>NULL</code>,
0936:             *         the value <code>null</code> is returned.
0937:             * @exception SQLException if a database access error occurs
0938:             * @since 1.2
0939:             */
0940:            public Array getArray(int i) throws SQLException {
0941:                int type = getOutParameterType(i);
0942:                switch (type) {
0943:                case Types.ARRAY:
0944:                    return (Array) outParameters.get(new Integer(i));
0945:                default:
0946:                    throw new SQLException(
0947:                            "Cannot convert OUT parameter of type " + type
0948:                                    + " to the requested type.");
0949:                }
0950:            }
0951:
0952:            /**
0953:             * Retrieves the value of the designated JDBC <code>DATE</code> parameter as
0954:             * a <code>java.sql.Date</code> object, using the given
0955:             * <code>Calendar</code> object to construct the date. With a
0956:             * <code>Calendar</code> object, the driver can calculate the date taking
0957:             * into account a custom timezone and locale. If no <code>Calendar</code>
0958:             * object is specified, the driver uses the default timezone and locale.
0959:             * 
0960:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0961:             * @param cal the <code>Calendar</code> object the driver will use to
0962:             *          construct the date
0963:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
0964:             *         result is <code>null</code>.
0965:             * @exception SQLException if a database access error occurs
0966:             * @see #setDate(String, Date)
0967:             * @since 1.2
0968:             */
0969:            public Date getDate(int parameterIndex, Calendar cal)
0970:                    throws SQLException {
0971:                return getDate(parameterIndex);
0972:            }
0973:
0974:            /**
0975:             * Retrieves the value of the designated JDBC <code>TIME</code> parameter as
0976:             * a <code>java.sql.Time</code> object, using the given
0977:             * <code>Calendar</code> object to construct the time. With a
0978:             * <code>Calendar</code> object, the driver can calculate the time taking
0979:             * into account a custom timezone and locale. If no <code>Calendar</code>
0980:             * object is specified, the driver uses the default timezone and locale.
0981:             * 
0982:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
0983:             * @param cal the <code>Calendar</code> object the driver will use to
0984:             *          construct the time
0985:             * @return the parameter value; if the value is SQL <code>NULL</code>, the
0986:             *         result is <code>null</code>.
0987:             * @exception SQLException if a database access error occurs
0988:             * @see #setTime(String, Time)
0989:             * @since 1.2
0990:             */
0991:            public Time getTime(int parameterIndex, Calendar cal)
0992:                    throws SQLException {
0993:                return getTime(parameterIndex);
0994:            }
0995:
0996:            /**
0997:             * Retrieves the value of the designated JDBC <code>TIMESTAMP</code>
0998:             * parameter as a <code>java.sql.Timestamp</code> object, using the given
0999:             * <code>Calendar</code> object to construct the <code>Timestamp</code>
1000:             * object. With a <code>Calendar</code> object, the driver can calculate the
1001:             * timestamp taking into account a custom timezone and locale. If no
1002:             * <code>Calendar</code> object is specified, the driver uses the default
1003:             * timezone and locale.
1004:             * 
1005:             * @param parameterIndex the first parameter is 1, the second is 2, and so on
1006:             * @param cal the <code>Calendar</code> object the driver will use to
1007:             *          construct the timestamp
1008:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
1009:             *         result is <code>null</code>.
1010:             * @exception SQLException if a database access error occurs
1011:             * @see #setTimestamp(String, Timestamp)
1012:             * @since 1.2
1013:             */
1014:            public Timestamp getTimestamp(int parameterIndex, Calendar cal)
1015:                    throws SQLException {
1016:                return getTimestamp(parameterIndex);
1017:            }
1018:
1019:            /**
1020:             * Retrieves the value of the designated JDBC <code>DATALINK</code>
1021:             * parameter as a <code>java.net.URL</code> object.
1022:             * 
1023:             * @param parameterIndex the first parameter is 1, the second is 2,...
1024:             * @return a <code>java.net.URL</code> object that represents the JDBC
1025:             *         <code>DATALINK</code> value used as the designated parameter
1026:             * @exception SQLException if a database access error occurs, or if the URL
1027:             *              being returned is not a valid URL on the Java platform
1028:             * @see #setURL
1029:             * @since 1.4
1030:             */
1031:            public URL getURL(int parameterIndex) throws SQLException {
1032:                int type = getOutParameterType(parameterIndex);
1033:                switch (type) {
1034:                case Types.DATALINK:
1035:                    return (URL) outParameters.get(new Integer(parameterIndex));
1036:                default:
1037:                    throw new SQLException(
1038:                            "Cannot convert OUT parameter of type " + type
1039:                                    + " to the requested type.");
1040:                }
1041:            }
1042:
1043:            /**
1044:             * Registers the OUT parameter named <code>parameterName</code> to the JDBC
1045:             * type <code>sqlType</code>. All OUT parameters must be registered before
1046:             * a stored procedure is executed.
1047:             * <p>
1048:             * The JDBC type specified by <code>sqlType</code> for an OUT parameter
1049:             * determines the Java type that must be used in the <code>get</code> method
1050:             * to read the value of that parameter.
1051:             * <p>
1052:             * If the JDBC type expected to be returned to this output parameter is
1053:             * specific to this particular database, <code>sqlType</code> should be
1054:             * <code>java.sql.Types.OTHER</code>. The method {@link #getObject(String)}
1055:             * retrieves the value.
1056:             * 
1057:             * @param parameterName the name of the parameter
1058:             * @param sqlType the JDBC type code defined by <code>java.sql.Types</code>.
1059:             *          If the parameter is of JDBC type <code>NUMERIC</code> or
1060:             *          <code>DECIMAL</code>, the version of
1061:             *          <code>registerOutParameter</code> that accepts a scale value
1062:             *          should be used.
1063:             * @exception SQLException if a database access error occurs
1064:             * @since 1.4
1065:             * @see java.sql.Types
1066:             */
1067:            public void registerOutParameter(String parameterName, int sqlType)
1068:                    throws SQLException {
1069:                setOutParameterWithTag(parameterName,
1070:                        PreparedStatementSerialization.REGISTER_OUT_PARAMETER,
1071:                        String.valueOf(sqlType));
1072:            }
1073:
1074:            /**
1075:             * Registers the parameter named <code>parameterName</code> to be of JDBC
1076:             * type <code>sqlType</code>. This method must be called before a stored
1077:             * procedure is executed.
1078:             * <p>
1079:             * The JDBC type specified by <code>sqlType</code> for an OUT parameter
1080:             * determines the Java type that must be used in the <code>get</code> method
1081:             * to read the value of that parameter.
1082:             * <p>
1083:             * This version of <code>registerOutParameter</code> should be used when the
1084:             * parameter is of JDBC type <code>NUMERIC</code> or <code>DECIMAL</code>.
1085:             * 
1086:             * @param parameterName the name of the parameter
1087:             * @param sqlType SQL type code defined by <code>java.sql.Types</code>.
1088:             * @param scale the desired number of digits to the right of the decimal
1089:             *          point. It must be greater than or equal to zero.
1090:             * @exception SQLException if a database access error occurs
1091:             * @since 1.4
1092:             * @see java.sql.Types
1093:             */
1094:            public void registerOutParameter(String parameterName, int sqlType,
1095:                    int scale) throws SQLException {
1096:                setOutParameterWithTag(
1097:                        parameterName,
1098:                        PreparedStatementSerialization.REGISTER_OUT_PARAMETER_WITH_SCALE,
1099:                        String.valueOf(sqlType) + "," + scale);
1100:            }
1101:
1102:            /**
1103:             * Registers the designated output parameter. This version of the method
1104:             * <code>registerOutParameter</code> should be used for a user-named or REF
1105:             * output parameter. Examples of user-named types include: STRUCT, DISTINCT,
1106:             * JAVA_OBJECT, and named array types.
1107:             * <p>
1108:             * Before executing a stored procedure call, you must explicitly call
1109:             * <code>registerOutParameter</code> to register the type from
1110:             * <code>java.sql.Types</code> for each OUT parameter. For a user-named
1111:             * parameter the fully-qualified SQL type name of the parameter should also be
1112:             * given, while a REF parameter requires that the fully-qualified type name of
1113:             * the referenced type be given. A JDBC driver that does not need the type
1114:             * code and type name information may ignore it. To be portable, however,
1115:             * applications should always provide these values for user-named and REF
1116:             * parameters.
1117:             * <p>
1118:             * Although it is intended for user-named and REF parameters, this method may
1119:             * be used to register a parameter of any JDBC type. If the parameter does not
1120:             * have a user-named or REF type, the typeName parameter is ignored.
1121:             * <p>
1122:             * <b>Note: </b> When reading the value of an out parameter, you must use the
1123:             * <code>getXXX</code> method whose Java type XXX corresponds to the
1124:             * parameter's registered SQL type.
1125:             * 
1126:             * @param parameterName the name of the parameter
1127:             * @param sqlType a value from {@link java.sql.Types}
1128:             * @param typeName the fully-qualified name of an SQL structured type
1129:             * @exception SQLException if a database access error occurs
1130:             * @see java.sql.Types
1131:             * @since 1.4
1132:             */
1133:            public void registerOutParameter(String parameterName, int sqlType,
1134:                    String typeName) throws SQLException {
1135:                setOutParameterWithTag(
1136:                        parameterName,
1137:                        PreparedStatementSerialization.REGISTER_OUT_PARAMETER_WITH_NAME,
1138:                        String.valueOf(sqlType) + "," + typeName);
1139:            }
1140:
1141:            /**
1142:             * Stores an out parameter and its type as a <em>quoted</em> String, so the
1143:             * controller can decode them back.
1144:             * 
1145:             * @param paramName the name of the parameter (index must be converted to
1146:             *          String)
1147:             * @param typeTag type of the parameter
1148:             * @param paramValue the parameter string to be stored
1149:             * @see PreparedStatementSerialization#setPreparedStatement(String,
1150:             *      java.sql.PreparedStatement)
1151:             */
1152:            private void setOutParameterWithTag(String paramName,
1153:                    String typeTag, String paramValue) {
1154:                if (outAndNamedParameterTypes == null)
1155:                    outAndNamedParameterTypes = new HashMap();
1156:
1157:                /**
1158:                 * insert TAGS so the controller can parse and "unset" the request using
1159:                 * {@link PreparedStatementSerialization#setPreparedStatement(String, java.sql.PreparedStatement) 
1160:                 */
1161:                outAndNamedParameterTypes.put(paramName,
1162:                        PreparedStatementSerialization.START_PARAM_TAG
1163:                                + typeTag + paramName + "," + paramValue
1164:                                + PreparedStatementSerialization.END_PARAM_TAG);
1165:            }
1166:
1167:            /**
1168:             * Stores a named parameter and its type as a <em>quoted</em> String, so the
1169:             * controller can decode them back.
1170:             * 
1171:             * @param paramName the name of the parameter
1172:             * @param typeTag type of the parameter
1173:             * @param param the parameter string to be stored
1174:             * @see PreparedStatementSerialization#setPreparedStatement(String,
1175:             *      java.sql.PreparedStatement)
1176:             */
1177:            private void setNamedParameterWithTag(String paramName,
1178:                    String typeTag, String param) {
1179:                if (outAndNamedParameterTypes == null)
1180:                    outAndNamedParameterTypes = new HashMap();
1181:
1182:                /**
1183:                 * insert TAGS so the controller can parse and "unset" the request using
1184:                 * {@link PreparedStatementSerialization#setPreparedStatement(String, java.sql.PreparedStatement) 
1185:                 */
1186:                outAndNamedParameterTypes
1187:                        .put(
1188:                                paramName,
1189:                                PreparedStatementSerialization.START_PARAM_TAG
1190:                                        + PreparedStatementSerialization.NAMED_PARAMETER_TAG
1191:                                        + paramName
1192:                                        + ","
1193:                                        + typeTag
1194:                                        + Strings
1195:                                                .replace(
1196:                                                        param,
1197:                                                        PreparedStatementSerialization.TAG_MARKER,
1198:                                                        PreparedStatementSerialization.TAG_MARKER_ESCAPE)
1199:                                        + PreparedStatementSerialization.END_PARAM_TAG);
1200:            }
1201:
1202:            /**
1203:             * Sets the designated parameter to the given <code>java.net.URL</code>
1204:             * object. The driver converts this to an SQL <code>DATALINK</code> value
1205:             * when it sends it to the database.
1206:             * 
1207:             * @param parameterName the name of the parameter
1208:             * @param url the parameter value
1209:             * @exception SQLException if a database access error occurs, or if a URL is
1210:             *              malformed
1211:             * @see #getURL(String)
1212:             * @since 1.4
1213:             */
1214:            public void setURL(String parameterName, URL url)
1215:                    throws SQLException {
1216:                if (url == null)
1217:                    setNamedParameterWithTag(parameterName,
1218:                            PreparedStatementSerialization.URL_TAG,
1219:                            PreparedStatementSerialization.NULL_VALUE);
1220:                else
1221:                    setNamedParameterWithTag(parameterName,
1222:                            PreparedStatementSerialization.URL_TAG, url
1223:                                    .toString());
1224:            }
1225:
1226:            /**
1227:             * Sets the designated parameter to SQL <code>NULL</code>.
1228:             * <p>
1229:             * <b>Note: </b> you must specify the parameter's SQL type.
1230:             * 
1231:             * @param parameterName the name of the parameter
1232:             * @param sqlType the SQL type code defined in <code>java.sql.Types</code>
1233:             * @exception SQLException if a database access error occurs
1234:             * @since 1.4
1235:             */
1236:            public void setNull(String parameterName, int sqlType)
1237:                    throws SQLException {
1238:                setNamedParameterWithTag(parameterName,
1239:                        PreparedStatementSerialization.NULL_VALUE, String
1240:                                .valueOf(sqlType));
1241:            }
1242:
1243:            /**
1244:             * Sets the designated parameter to the given Java <code>boolean</code>
1245:             * value. The driver converts this to an SQL <code>BIT</code> value when it
1246:             * sends it to the database.
1247:             * 
1248:             * @param parameterName the name of the parameter
1249:             * @param x the parameter value
1250:             * @exception SQLException if a database access error occurs
1251:             * @see #getBoolean(String)
1252:             * @since 1.4
1253:             */
1254:            public void setBoolean(String parameterName, boolean x)
1255:                    throws SQLException {
1256:                setNamedParameterWithTag(parameterName,
1257:                        PreparedStatementSerialization.BOOLEAN_TAG, String
1258:                                .valueOf(x));
1259:            }
1260:
1261:            /**
1262:             * Sets the designated parameter to the given Java <code>byte</code> value.
1263:             * The driver converts this to an SQL <code>TINYINT</code> value when it
1264:             * sends it to the database.
1265:             * 
1266:             * @param parameterName the name of the parameter
1267:             * @param x the parameter value
1268:             * @exception SQLException if a database access error occurs
1269:             * @see #getByte(String)
1270:             * @since 1.4
1271:             */
1272:            public void setByte(String parameterName, byte x)
1273:                    throws SQLException {
1274:                setNamedParameterWithTag(parameterName,
1275:                        PreparedStatementSerialization.BYTE_TAG, Integer
1276:                                .toString(x));
1277:            }
1278:
1279:            /**
1280:             * Sets the designated parameter to the given Java <code>short</code> value.
1281:             * The driver converts this to an SQL <code>SMALLINT</code> value when it
1282:             * sends it to the database.
1283:             * 
1284:             * @param parameterName the name of the parameter
1285:             * @param x the parameter value
1286:             * @exception SQLException if a database access error occurs
1287:             * @see #getShort(String)
1288:             * @since 1.4
1289:             */
1290:            public void setShort(String parameterName, short x)
1291:                    throws SQLException {
1292:                setNamedParameterWithTag(parameterName,
1293:                        PreparedStatementSerialization.SHORT_TAG, Integer
1294:                                .toString(x));
1295:            }
1296:
1297:            /**
1298:             * Sets the designated parameter to the given Java <code>int</code> value.
1299:             * The driver converts this to an SQL <code>INTEGER</code> value when it
1300:             * sends it to the database.
1301:             * 
1302:             * @param parameterName the name of the parameter
1303:             * @param x the parameter value
1304:             * @exception SQLException if a database access error occurs
1305:             * @see #getInt(String)
1306:             * @since 1.4
1307:             */
1308:            public void setInt(String parameterName, int x) throws SQLException {
1309:                setNamedParameterWithTag(parameterName,
1310:                        PreparedStatementSerialization.INTEGER_TAG, Integer
1311:                                .toString(x));
1312:            }
1313:
1314:            /**
1315:             * Sets the designated parameter to the given Java <code>long</code> value.
1316:             * The driver converts this to an SQL <code>BIGINT</code> value when it
1317:             * sends it to the database.
1318:             * 
1319:             * @param parameterName the name of the parameter
1320:             * @param x the parameter value
1321:             * @exception SQLException if a database access error occurs
1322:             * @see #getLong(String)
1323:             * @since 1.4
1324:             */
1325:            public void setLong(String parameterName, long x)
1326:                    throws SQLException {
1327:                setNamedParameterWithTag(parameterName,
1328:                        PreparedStatementSerialization.LONG_TAG, Long
1329:                                .toString(x));
1330:            }
1331:
1332:            /**
1333:             * Sets the designated parameter to the given Java <code>float</code> value.
1334:             * The driver converts this to an SQL <code>FLOAT</code> value when it sends
1335:             * it to the database.
1336:             * 
1337:             * @param parameterName the name of the parameter
1338:             * @param x the parameter value
1339:             * @exception SQLException if a database access error occurs
1340:             * @see #getFloat(String)
1341:             * @since 1.4
1342:             */
1343:            public void setFloat(String parameterName, float x)
1344:                    throws SQLException {
1345:                setNamedParameterWithTag(parameterName,
1346:                        PreparedStatementSerialization.FLOAT_TAG, Float
1347:                                .toString(x));
1348:            }
1349:
1350:            /**
1351:             * Sets the designated parameter to the given Java <code>double</code>
1352:             * value. The driver converts this to an SQL <code>DOUBLE</code> value when
1353:             * it sends it to the database.
1354:             * 
1355:             * @param parameterName the name of the parameter
1356:             * @param x the parameter value
1357:             * @exception SQLException if a database access error occurs
1358:             * @see #getDouble(String)
1359:             * @since 1.4
1360:             */
1361:            public void setDouble(String parameterName, double x)
1362:                    throws SQLException {
1363:                setNamedParameterWithTag(parameterName,
1364:                        PreparedStatementSerialization.DOUBLE_TAG, Double
1365:                                .toString(x));
1366:            }
1367:
1368:            /**
1369:             * Sets the designated parameter to the given
1370:             * <code>java.math.BigDecimal</code> value. The driver converts this to an
1371:             * SQL <code>NUMERIC</code> value when it sends it to the database.
1372:             * 
1373:             * @param parameterName the name of the parameter
1374:             * @param x the parameter value
1375:             * @exception SQLException if a database access error occurs
1376:             * @see #getBigDecimal(String)
1377:             * @since 1.4
1378:             */
1379:            public void setBigDecimal(String parameterName, BigDecimal x)
1380:                    throws SQLException {
1381:                if (x == null)
1382:                    setNamedParameterWithTag(parameterName,
1383:                            PreparedStatementSerialization.BIG_DECIMAL_TAG,
1384:                            PreparedStatementSerialization.NULL_VALUE);
1385:                else
1386:                    setNamedParameterWithTag(parameterName,
1387:                            PreparedStatementSerialization.BIG_DECIMAL_TAG, x
1388:                                    .toString());
1389:            }
1390:
1391:            /**
1392:             * Sets the designated parameter to the given Java <code>String</code>
1393:             * value. The driver converts this to an SQL <code>VARCHAR</code> or
1394:             * <code>LONGVARCHAR</code> value (depending on the argument's size relative
1395:             * to the driver's limits on <code>VARCHAR</code> values) when it sends it
1396:             * to the database.
1397:             * 
1398:             * @param parameterName the name of the parameter
1399:             * @param x the parameter value
1400:             * @exception SQLException if a database access error occurs
1401:             * @see #getString(String)
1402:             * @since 1.4
1403:             */
1404:            public void setString(String parameterName, String x)
1405:                    throws SQLException {
1406:                if (x == null)
1407:                    setNamedParameterWithTag(parameterName,
1408:                            PreparedStatementSerialization.STRING_TAG,
1409:                            PreparedStatementSerialization.NULL_VALUE);
1410:                else {
1411:                    if (PreparedStatementSerialization.NULL_VALUE.equals(x)) { // Someone is trying to set a String that matches our NULL tag, a real
1412:                        // bad luck, use our special NULL_STRING_TAG!
1413:                        setNamedParameterWithTag(parameterName,
1414:                                PreparedStatementSerialization.NULL_STRING_TAG,
1415:                                x);
1416:                    } else { // No escape processing is needed for queries not being parsed into
1417:                        // statements.
1418:                        setNamedParameterWithTag(parameterName,
1419:                                PreparedStatementSerialization.STRING_TAG, x);
1420:                    }
1421:                }
1422:            }
1423:
1424:            /**
1425:             * Sets the designated parameter to the given Java array of bytes. The driver
1426:             * converts this to an SQL <code>VARBINARY</code> or
1427:             * <code>LONGVARBINARY</code> (depending on the argument's size relative to
1428:             * the driver's limits on <code>VARBINARY</code> values) when it sends it to
1429:             * the database.
1430:             * 
1431:             * @param parameterName the name of the parameter
1432:             * @param x the parameter value
1433:             * @exception SQLException if a database access error occurs
1434:             * @see #getBytes(String)
1435:             * @since 1.4
1436:             */
1437:            public void setBytes(String parameterName, byte[] x)
1438:                    throws SQLException {
1439:                try {
1440:                    /**
1441:                     * Encoded only for request inlining. Decoded right away by the controller
1442:                     * at static
1443:                     * {@link #setPreparedStatement(String, java.sql.PreparedStatement)}
1444:                     */
1445:                    String encodedString = AbstractBlobFilter
1446:                            .getDefaultBlobFilter().encode(x);
1447:                    setNamedParameterWithTag(parameterName,
1448:                            PreparedStatementSerialization.BYTES_TAG,
1449:                            encodedString);
1450:                } catch (OutOfMemoryError oome) {
1451:                    System.gc();
1452:                    throw new SQLException("Out of memory while encoding bytes");
1453:                }
1454:            }
1455:
1456:            /**
1457:             * Sets the designated parameter to the given <code>java.sql.Date</code>
1458:             * value. The driver converts this to an SQL <code>DATE</code> value when it
1459:             * sends it to the database.
1460:             * 
1461:             * @param parameterName the name of the parameter
1462:             * @param x the parameter value
1463:             * @exception SQLException if a database access error occurs
1464:             * @see #getDate(String)
1465:             * @since 1.4
1466:             */
1467:            public void setDate(String parameterName, Date x)
1468:                    throws SQLException {
1469:                if (x == null)
1470:                    setNamedParameterWithTag(parameterName,
1471:                            PreparedStatementSerialization.DATE_TAG,
1472:                            PreparedStatementSerialization.NULL_VALUE);
1473:                else
1474:                    setNamedParameterWithTag(parameterName,
1475:                            PreparedStatementSerialization.DATE_TAG,
1476:                            new java.sql.Date(x.getTime()).toString());
1477:            }
1478:
1479:            /**
1480:             * Sets the designated parameter to the given <code>java.sql.Time</code>
1481:             * value. The driver converts this to an SQL <code>TIME</code> value when it
1482:             * sends it to the database.
1483:             * 
1484:             * @param parameterName the name of the parameter
1485:             * @param x the parameter value
1486:             * @exception SQLException if a database access error occurs
1487:             * @see #getTime(String)
1488:             * @since 1.4
1489:             */
1490:            public void setTime(String parameterName, Time x)
1491:                    throws SQLException {
1492:                if (x == null)
1493:                    setNamedParameterWithTag(parameterName,
1494:                            PreparedStatementSerialization.TIME_TAG,
1495:                            PreparedStatementSerialization.NULL_VALUE);
1496:                else
1497:                    setNamedParameterWithTag(parameterName,
1498:                            PreparedStatementSerialization.TIME_TAG, x
1499:                                    .toString());
1500:            }
1501:
1502:            /**
1503:             * Sets the designated parameter to the given <code>java.sql.Timestamp</code>
1504:             * value. The driver converts this to an SQL <code>TIMESTAMP</code> value
1505:             * when it sends it to the database.
1506:             * 
1507:             * @param parameterName the name of the parameter
1508:             * @param x the parameter value
1509:             * @exception SQLException if a database access error occurs
1510:             * @see #getTimestamp(String)
1511:             * @since 1.4
1512:             */
1513:            public void setTimestamp(String parameterName, Timestamp x)
1514:                    throws SQLException {
1515:                if (x == null)
1516:                    setNamedParameterWithTag(parameterName,
1517:                            PreparedStatementSerialization.TIMESTAMP_TAG,
1518:                            PreparedStatementSerialization.NULL_VALUE);
1519:                else {
1520:                    if (x.getClass().equals(Timestamp.class))
1521:                        setNamedParameterWithTag(parameterName,
1522:                                PreparedStatementSerialization.TIMESTAMP_TAG,
1523:                                new Timestamp(x.getTime()).toString());
1524:                }
1525:            }
1526:
1527:            /**
1528:             * Sets the designated parameter to the given input stream, which will have
1529:             * the specified number of bytes. When a very large ASCII value is input to a
1530:             * <code>LONGVARCHAR</code> parameter, it may be more practical to send it
1531:             * via a <code>java.io.InputStream</code>. Data will be read from the
1532:             * stream as needed until end-of-file is reached. The JDBC driver will do any
1533:             * necessary conversion from ASCII to the database char format.
1534:             * <p>
1535:             * <b>Note: </b> This stream object can either be a standard Java stream
1536:             * object or your own subclass that implements the standard interface.
1537:             * 
1538:             * @param parameterName the name of the parameter
1539:             * @param x the Java input stream that contains the ASCII parameter value
1540:             * @param length the number of bytes in the stream
1541:             * @exception SQLException if a database access error occurs
1542:             * @since 1.4
1543:             */
1544:            public void setAsciiStream(String parameterName, InputStream x,
1545:                    int length) throws SQLException {
1546:                setBinaryStream(parameterName, x, length);
1547:            }
1548:
1549:            /**
1550:             * Sets the designated parameter to the given input stream, which will have
1551:             * the specified number of bytes. When a very large binary value is input to a
1552:             * <code>LONGVARBINARY</code> parameter, it may be more practical to send it
1553:             * via a <code>java.io.InputStream</code> object. The data will be read from
1554:             * the stream as needed until end-of-file is reached.
1555:             * <p>
1556:             * <b>Note: </b> This stream object can either be a standard Java stream
1557:             * object or your own subclass that implements the standard interface.
1558:             * 
1559:             * @param parameterName the name of the parameter
1560:             * @param x the java input stream which contains the binary parameter value
1561:             * @param length the number of bytes in the stream
1562:             * @exception SQLException if a database access error occurs
1563:             * @since 1.4
1564:             */
1565:            public void setBinaryStream(String parameterName, InputStream x,
1566:                    int length) throws SQLException {
1567:                byte[] data = new byte[length];
1568:                try {
1569:                    x.read(data, 0, length);
1570:                } catch (Exception ioe) {
1571:                    throw new SQLException("Problem with streaming of data");
1572:                }
1573:                // TODO: optimize me and avoid the copy thanks to a new setBytesFromStream()
1574:                // setBytes does the blob filter encoding.
1575:                setBytes(parameterName, data);
1576:            }
1577:
1578:            /**
1579:             * Sets the value of the designated parameter with the given object. The
1580:             * second argument must be an object type; for integral values, the
1581:             * <code>java.lang</code> equivalent objects should be used.
1582:             * <p>
1583:             * The given Java object will be converted to the given
1584:             * <code>targetSqlType</code> before being sent to the database.
1585:             * <p>
1586:             * If the object has a custom mapping (is of a class implementing the
1587:             * interface <code>SQLData</code>), the JDBC driver should call the method
1588:             * <code>SQLData.writeSQL</code> to write it to the SQL data stream. If, on
1589:             * the other hand, the object is of a class implementing <code>Ref</code>,
1590:             * <code>Blob</code>,<code>Clob</code>,<code>Struct</code>, or
1591:             * <code>Array</code>, the driver should pass it to the database as a value
1592:             * of the corresponding SQL type.
1593:             * <p>
1594:             * Note that this method may be used to pass datatabase-specific abstract data
1595:             * types.
1596:             * 
1597:             * @param parameterName the name of the parameter
1598:             * @param x the object containing the input parameter value
1599:             * @param targetSqlType the SQL type (as defined in
1600:             *          <code>java.sql.Types</code>) to be sent to the database. The
1601:             *          scale argument may further qualify this type.
1602:             * @param scale for <code>java.sql.Types.DECIMAL</code> or
1603:             *          <code>java.sql.Types.NUMERIC</code> types, this is the number of
1604:             *          digits after the decimal point. For all other types, this value
1605:             *          will be ignored.
1606:             * @exception SQLException if a database access error occurs
1607:             * @see java.sql.Types
1608:             * @see #getObject(String, Map)
1609:             * @since 1.4
1610:             */
1611:            public void setObject(String parameterName, Object x,
1612:                    int targetSqlType, int scale) throws SQLException {
1613:                if (x == null) {
1614:                    setNull(parameterName, targetSqlType);
1615:                    return;
1616:                }
1617:
1618:                try {
1619:                    boolean failed = false;
1620:                    switch (targetSqlType) {
1621:                    /**
1622:                     * Reference is table "Conversions Performed by setObject()..." in JDBC
1623:                     * Reference Book (table 47.9.5 in 2nd edition, 50.5 in 3rd edition).
1624:                     * Also available online in Sun's "JDBC Technology Guide: Getting
1625:                     * Started", section "Mapping SQL and Java Types".
1626:                     */
1627:                    // Some drivers (at least postgresql > 8.1) don't accept setInt for tiny
1628:                    // and small ints. We can safely use setShort instead. See bug
1629:                    // SEQUOIA-543
1630:                    // setShort().
1631:                    case Types.TINYINT:
1632:                    case Types.SMALLINT:
1633:                        if (x instanceof  Number)
1634:                            setShort(parameterName, ((Number) x).shortValue());
1635:                        else if (x instanceof  Boolean)
1636:                            setShort(parameterName, ((Boolean) x)
1637:                                    .booleanValue() ? (short) 1 : (short) 0);
1638:                        else if (x instanceof  String)
1639:                            setInt(parameterName, Short.parseShort((String) x));
1640:                        else
1641:                            failed = true;
1642:                        break;
1643:                    // setInt()
1644:                    case Types.INTEGER:
1645:                        if (x instanceof  Number)
1646:                            setInt(parameterName, ((Number) x).intValue());
1647:                        else if (x instanceof  Boolean)
1648:                            setInt(parameterName,
1649:                                    ((Boolean) x).booleanValue() ? 1 : 0);
1650:                        else if (x instanceof  String)
1651:                            setInt(parameterName, Integer.parseInt((String) x));
1652:                        else
1653:                            failed = true;
1654:                        break;
1655:                    // setLong()
1656:                    case Types.BIGINT:
1657:                        if (x instanceof  Number)
1658:                            setLong(parameterName, ((Number) x).longValue());
1659:                        else if (x instanceof  String)
1660:                            setLong(parameterName, Long.parseLong((String) x));
1661:                        else if (x instanceof  Boolean)
1662:                            setLong(parameterName,
1663:                                    ((Boolean) x).booleanValue() ? 1 : 0);
1664:                        else
1665:                            failed = true;
1666:                        break;
1667:                    // setDouble()
1668:                    case Types.REAL:
1669:                    case Types.FLOAT:
1670:                    case Types.DOUBLE:
1671:                        if (x instanceof  Number)
1672:                            setDouble(parameterName, ((Number) x).doubleValue());
1673:                        else if (x instanceof  String)
1674:                            setDouble(parameterName, Double
1675:                                    .parseDouble((String) x));
1676:                        else if (x instanceof  Boolean)
1677:                            setDouble(parameterName, ((Boolean) x)
1678:                                    .booleanValue() ? 1 : 0);
1679:                        else
1680:                            failed = true;
1681:                        break;
1682:                    // setBigDecimal()
1683:                    case Types.DECIMAL:
1684:                    case Types.NUMERIC:
1685:                        BigDecimal bd;
1686:                        if (x instanceof  Boolean)
1687:                            bd = new BigDecimal(
1688:                                    ((Boolean) x).booleanValue() ? 1d : 0d);
1689:                        else if (x instanceof  Number)
1690:                            bd = new BigDecimal(((Number) x).toString());
1691:                        else if (x instanceof  String)
1692:                            bd = new BigDecimal((String) x);
1693:                        else {
1694:                            failed = true;
1695:                            break;
1696:                        }
1697:                        bd = bd.setScale(scale, BigDecimal.ROUND_HALF_UP);
1698:                        setBigDecimal(parameterName, bd);
1699:                        break;
1700:                    // setBoolean()
1701:                    case Types.BIT:
1702:                    case Types.BOOLEAN:
1703:                        if (x instanceof  Number)
1704:                            setBoolean(parameterName, 0 != ((Number) x)
1705:                                    .longValue());
1706:                        else if (x instanceof  Boolean)
1707:                            setBoolean(parameterName, ((Boolean) x)
1708:                                    .booleanValue());
1709:                        else if (x instanceof  String)
1710:                            setBoolean(parameterName, Boolean.valueOf(
1711:                                    (String) x).booleanValue());
1712:                        else
1713:                            failed = true;
1714:                        break;
1715:                    // setString()
1716:                    case Types.CHAR:
1717:                    case Types.VARCHAR:
1718:                    case Types.LONGVARCHAR:
1719:                        setString(parameterName, x.toString());
1720:                        break;
1721:                    // setBytes(), setBlob(),...
1722:                    case Types.BINARY:
1723:                    case Types.VARBINARY:
1724:                    case Types.LONGVARBINARY:
1725:                        if (x instanceof  byte[])
1726:                            setBytes(parameterName, (byte[]) x);
1727:                        else if (x instanceof  Serializable)
1728:                            // Try it as an Object (serialized in bytes in setObject below)
1729:                            setObject(parameterName, x);
1730:                        else
1731:                            failed = true;
1732:                        break;
1733:                    // setDate()
1734:                    case Types.DATE:
1735:                        if (x instanceof  String)
1736:                            setDate(parameterName, java.sql.Date
1737:                                    .valueOf((String) x));
1738:                        else if (x instanceof  java.sql.Date)
1739:                            setDate(parameterName, (java.sql.Date) x);
1740:                        else if (x instanceof  Timestamp)
1741:                            setDate(parameterName, new java.sql.Date(
1742:                                    ((Timestamp) x).getTime()));
1743:                        else
1744:                            failed = true;
1745:                        break;
1746:                    // setTime()
1747:                    case Types.TIME:
1748:                        if (x instanceof  String)
1749:                            setTime(parameterName, Time.valueOf((String) x));
1750:                        else if (x instanceof  Time)
1751:                            setTime(parameterName, (Time) x);
1752:                        else if (x instanceof  Timestamp)
1753:                            setTime(parameterName, new Time(((Timestamp) x)
1754:                                    .getTime()));
1755:                        else
1756:                            failed = true;
1757:                        break;
1758:                    // setTimeStamp()
1759:                    case Types.TIMESTAMP:
1760:                        if (x instanceof  String)
1761:                            setTimestamp(parameterName, Timestamp
1762:                                    .valueOf((String) x));
1763:                        else if (x instanceof  Date)
1764:                            setTimestamp(parameterName, new Timestamp(
1765:                                    ((Date) x).getTime()));
1766:                        else if (x instanceof  Timestamp)
1767:                            setTimestamp(parameterName, (Timestamp) x);
1768:                        else
1769:                            failed = true;
1770:                        break;
1771:                    // setBlob()
1772:                    case Types.BLOB:
1773:                        failed = true;
1774:                        break;
1775:                    // setURL()
1776:                    case Types.DATALINK:
1777:                        if (x instanceof  java.net.URL)
1778:                            setURL(parameterName, (java.net.URL) x);
1779:                        else
1780:                            setURL(parameterName,
1781:                                    new java.net.URL(x.toString()));
1782:                        break;
1783:                    case Types.JAVA_OBJECT:
1784:                    case Types.OTHER:
1785:                        // let's ignore the unknown target type given.
1786:                        setObject(parameterName, x);
1787:                        break;
1788:                    default:
1789:                        throw new SQLException("Unsupported type value");
1790:                    }
1791:                    if (true == failed)
1792:                        throw new IllegalArgumentException(
1793:                                "Attempt to perform an illegal conversion");
1794:                } catch (Exception e) {
1795:                    SQLException outE = new SQLException(
1796:                            "Exception while converting type " + x.getClass()
1797:                                    + " to SQL type " + targetSqlType);
1798:                    outE.initCause(e);
1799:                    throw outE;
1800:                }
1801:            }
1802:
1803:            /**
1804:             * Sets the value of the designated parameter with the given object. This
1805:             * method is like the method <code>setObject</code> above, except that it
1806:             * assumes a scale of zero.
1807:             * 
1808:             * @param parameterName the name of the parameter
1809:             * @param x the object containing the input parameter value
1810:             * @param targetSqlType the SQL type (as defined in
1811:             *          <code>java.sql.Types</code>) to be sent to the database
1812:             * @exception SQLException if a database access error occurs
1813:             * @see #getObject(String, Map)
1814:             * @since 1.4
1815:             */
1816:            public void setObject(String parameterName, Object x,
1817:                    int targetSqlType) throws SQLException {
1818:                setObject(parameterName, x, targetSqlType, 0);
1819:            }
1820:
1821:            /**
1822:             * Sets the value of the designated parameter with the given object. The
1823:             * second parameter must be of type <code>Object</code>; therefore, the
1824:             * <code>java.lang</code> equivalent objects should be used for built-in
1825:             * types.
1826:             * <p>
1827:             * The JDBC specification specifies a standard mapping from Java
1828:             * <code>Object</code> types to SQL types. The given argument will be
1829:             * converted to the corresponding SQL type before being sent to the database.
1830:             * <p>
1831:             * Note that this method may be used to pass datatabase-specific abstract data
1832:             * types, by using a driver-specific Java type.
1833:             * <p>
1834:             * If the object is of a class implementing the interface <code>SQLData</code>,
1835:             * the JDBC driver should call the method <code>SQLData.writeSQL</code> to
1836:             * write it to the SQL data stream. If, on the other hand, the object is of a
1837:             * class implementing <code>Ref</code>,<code>Blob</code>,
1838:             * <code>Clob</code>,<code>Struct</code>, or <code>Array</code>, the
1839:             * driver should pass it to the database as a value of the corresponding SQL
1840:             * type.
1841:             * <p>
1842:             * This method throws an exception if there is an ambiguity, for example, if
1843:             * the object is of a class implementing more than one of the interfaces named
1844:             * above.
1845:             * 
1846:             * @param parameterName the name of the parameter
1847:             * @param x the object containing the input parameter value
1848:             * @exception SQLException if a database access error occurs or if the given
1849:             *              <code>Object</code> parameter is ambiguous
1850:             * @see #getObject(String, Map)
1851:             * @since 1.4
1852:             */
1853:            public void setObject(String parameterName, Object x)
1854:                    throws SQLException {
1855:                if (x == null) {
1856:                    setNamedParameterWithTag(parameterName,
1857:                            PreparedStatementSerialization.OBJECT_TAG,
1858:                            PreparedStatementSerialization.NULL_VALUE);
1859:                } else { // This is an optimization, faster than going through
1860:                    // the generic setObject() method and calling instanceof again.
1861:                    // This has to be in the end equivalent to
1862:                    // setObject(index, object, DEFAULT_targetSqlType, 0)
1863:                    // where DEFAULT_targetSqlType is defined in table:
1864:                    // "Java Object Type Mapped to JDBC Types".
1865:                    // It's currently not exactly the same, since generic setObject()
1866:                    // is not strict enough in its conversions. For instance
1867:                    // setObject(target=Float) actually calls "setDouble()" -- MH.
1868:
1869:                    if (x instanceof  String)
1870:                        setString(parameterName, (String) x);
1871:                    else if (x instanceof  BigDecimal)
1872:                        setBigDecimal(parameterName, (BigDecimal) x);
1873:                    else if (x instanceof  Boolean)
1874:                        setBoolean(parameterName, ((Boolean) x).booleanValue());
1875:                    else if (x instanceof  Short)
1876:                        setShort(parameterName, ((Short) x).shortValue());
1877:                    else if (x instanceof  Integer)
1878:                        setInt(parameterName, ((Integer) x).intValue());
1879:                    else if (x instanceof  Long)
1880:                        setLong(parameterName, ((Long) x).longValue());
1881:                    else if (x instanceof  Float)
1882:                        setFloat(parameterName, ((Float) x).floatValue());
1883:                    else if (x instanceof  Double)
1884:                        setDouble(parameterName, ((Double) x).doubleValue());
1885:                    else if (x instanceof  byte[])
1886:                        setBytes(parameterName, (byte[]) x);
1887:                    else if (x instanceof  java.sql.Date)
1888:                        setDate(parameterName, (java.sql.Date) x);
1889:                    else if (x instanceof  Time)
1890:                        setTime(parameterName, (Time) x);
1891:                    else if (x instanceof  Timestamp)
1892:                        setTimestamp(parameterName, (Timestamp) x);
1893:                    else if (x instanceof  java.net.URL)
1894:                        setURL(parameterName, (java.net.URL) x);
1895:                    else if (x instanceof  Serializable) {
1896:                        ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
1897:                        try {
1898:                            // Serialize object to byte array
1899:                            ObjectOutputStream objectOutputStream = new ObjectOutputStream(
1900:                                    byteOutputStream);
1901:                            objectOutputStream.writeObject(x);
1902:                            objectOutputStream.close();
1903:                            synchronized (this .sbuf) {
1904:                                this .sbuf.setLength(0);
1905:                                /**
1906:                                 * Encoded only for request inlining. Decoded right away by the
1907:                                 * controller
1908:                                 */
1909:                                this .sbuf
1910:                                        .append(AbstractBlobFilter
1911:                                                .getDefaultBlobFilter().encode(
1912:                                                        byteOutputStream
1913:                                                                .toByteArray()));
1914:                                setNamedParameterWithTag(
1915:                                        parameterName,
1916:                                        PreparedStatementSerialization.OBJECT_TAG,
1917:                                        trimStringBuffer());
1918:                            }
1919:                        } catch (IOException e) {
1920:                            throw new SQLException(
1921:                                    "Failed to serialize object: " + e);
1922:                        }
1923:                    } else
1924:                        throw new SQLException("Objects of type "
1925:                                + x.getClass() + " are not supported.");
1926:                }
1927:            }
1928:
1929:            /**
1930:             * Sets the designated parameter to the given <code>Reader</code> object,
1931:             * which is the given number of characters long. When a very large UNICODE
1932:             * value is input to a <code>LONGVARCHAR</code> parameter, it may be more
1933:             * practical to send it via a <code>java.io.Reader</code> object. The data
1934:             * will be read from the stream as needed until end-of-file is reached. The
1935:             * JDBC driver will do any necessary conversion from UNICODE to the database
1936:             * char format.
1937:             * <p>
1938:             * <b>Note: </b> This stream object can either be a standard Java stream
1939:             * object or your own subclass that implements the standard interface.
1940:             * 
1941:             * @param parameterName the name of the parameter
1942:             * @param reader the <code>java.io.Reader</code> object that contains the
1943:             *          UNICODE data used as the designated parameter
1944:             * @param length the number of characters in the stream
1945:             * @exception SQLException if a database access error occurs
1946:             * @since 1.4
1947:             */
1948:            public void setCharacterStream(String parameterName, Reader reader,
1949:                    int length) throws SQLException {
1950:                char[] data = new char[length];
1951:                try {
1952:                    reader.read(data, 0, length);
1953:                } catch (Exception ioe) {
1954:                    throw new SQLException("Problem with streaming of data");
1955:                }
1956:                setString(parameterName, new String(data));
1957:            }
1958:
1959:            /**
1960:             * Sets the designated parameter to the given <code>java.sql.Date</code>
1961:             * value, using the given <code>Calendar</code> object. The driver uses the
1962:             * <code>Calendar</code> object to construct an SQL <code>DATE</code>
1963:             * value, which the driver then sends to the database. With a a
1964:             * <code>Calendar</code> object, the driver can calculate the date taking
1965:             * into account a custom timezone. If no <code>Calendar</code> object is
1966:             * specified, the driver uses the default timezone, which is that of the
1967:             * virtual machine running the application.
1968:             * 
1969:             * @param parameterName the name of the parameter
1970:             * @param d the parameter value
1971:             * @param cal the <code>Calendar</code> object the driver will use to
1972:             *          construct the date
1973:             * @exception SQLException if a database access error occurs
1974:             * @see #getDate(String, Calendar)
1975:             * @since 1.4
1976:             */
1977:            public void setDate(String parameterName, Date d, Calendar cal)
1978:                    throws SQLException {
1979:                if (d == null)
1980:                    setNamedParameterWithTag(parameterName,
1981:                            PreparedStatementSerialization.DATE_TAG,
1982:                            PreparedStatementSerialization.NULL_VALUE);
1983:                else {
1984:                    if (cal == null)
1985:                        setDate(parameterName, d);
1986:                    else {
1987:                        cal.setTime(d);
1988:                        setDate(parameterName, new java.sql.Date(cal.getTime()
1989:                                .getTime()));
1990:                    }
1991:                }
1992:            }
1993:
1994:            /**
1995:             * Sets the designated parameter to the given <code>java.sql.Time</code>
1996:             * value, using the given <code>Calendar</code> object. The driver uses the
1997:             * <code>Calendar</code> object to construct an SQL <code>TIME</code>
1998:             * value, which the driver then sends to the database. With a a
1999:             * <code>Calendar</code> object, the driver can calculate the time taking
2000:             * into account a custom timezone. If no <code>Calendar</code> object is
2001:             * specified, the driver uses the default timezone, which is that of the
2002:             * virtual machine running the application.
2003:             * 
2004:             * @param parameterName the name of the parameter
2005:             * @param t the parameter value
2006:             * @param cal the <code>Calendar</code> object the driver will use to
2007:             *          construct the time
2008:             * @exception SQLException if a database access error occurs
2009:             * @see #getTime(String, Calendar)
2010:             * @since 1.4
2011:             */
2012:            public void setTime(String parameterName, Time t, Calendar cal)
2013:                    throws SQLException {
2014:                if (t == null)
2015:                    setNamedParameterWithTag(parameterName,
2016:                            PreparedStatementSerialization.TIME_TAG,
2017:                            PreparedStatementSerialization.NULL_VALUE);
2018:                else {
2019:                    if (cal == null)
2020:                        setTime(parameterName, t);
2021:                    else {
2022:                        cal.setTime(t);
2023:                        setTime(parameterName, new java.sql.Time(cal.getTime()
2024:                                .getTime()));
2025:                    }
2026:                }
2027:            }
2028:
2029:            /**
2030:             * Sets the designated parameter to the given <code>java.sql.Timestamp</code>
2031:             * value, using the given <code>Calendar</code> object. The driver uses the
2032:             * <code>Calendar</code> object to construct an SQL <code>TIMESTAMP</code>
2033:             * value, which the driver then sends to the database. With a a
2034:             * <code>Calendar</code> object, the driver can calculate the timestamp
2035:             * taking into account a custom timezone. If no <code>Calendar</code> object
2036:             * is specified, the driver uses the default timezone, which is that of the
2037:             * virtual machine running the application.
2038:             * 
2039:             * @param parameterName the name of the parameter
2040:             * @param t the parameter value
2041:             * @param cal the <code>Calendar</code> object the driver will use to
2042:             *          construct the timestamp
2043:             * @exception SQLException if a database access error occurs
2044:             * @see #getTimestamp(String, Calendar)
2045:             * @since 1.4
2046:             */
2047:            public void setTimestamp(String parameterName, Timestamp t,
2048:                    Calendar cal) throws SQLException {
2049:                if (t == null)
2050:                    setNamedParameterWithTag(parameterName,
2051:                            PreparedStatementSerialization.TIMESTAMP_TAG,
2052:                            PreparedStatementSerialization.NULL_VALUE);
2053:                else {
2054:                    if (cal == null)
2055:                        setTimestamp(parameterName, t);
2056:                    else {
2057:                        cal.setTime(t);
2058:                        setTimestamp(parameterName, new java.sql.Timestamp(cal
2059:                                .getTime().getTime()));
2060:                    }
2061:                }
2062:            }
2063:
2064:            /**
2065:             * Sets the designated parameter to SQL <code>NULL</code>. This version of
2066:             * the method <code>setNull</code> should be used for user-defined types and
2067:             * REF type parameters. Examples of user-defined types include: STRUCT,
2068:             * DISTINCT, JAVA_OBJECT, and named array types.
2069:             * <p>
2070:             * <b>Note: </b> to be portable, applications must give the SQL type code and
2071:             * the fully-qualified SQL type name when specifying a NULL user-defined or
2072:             * REF parameter. In the case of a user-defined type the name is the type name
2073:             * of the parameter itself. For a REF parameter, the name is the type name of
2074:             * the referenced type. If a JDBC driver does not need the type code or type
2075:             * name information, it may ignore it.
2076:             * <p>
2077:             * Although it is intended for user-defined and Ref parameters, this method
2078:             * may be used to set a null parameter of any JDBC type. If the parameter does
2079:             * not have a user-defined or REF type, the given typeName is ignored.
2080:             * 
2081:             * @param parameterName the name of the parameter
2082:             * @param sqlType a value from <code>java.sql.Types</code>
2083:             * @param typeName the fully-qualified name of an SQL user-defined type;
2084:             *          ignored if the parameter is not a user-defined type or SQL
2085:             *          <code>REF</code> value
2086:             * @exception SQLException if a database access error occurs
2087:             * @since 1.4
2088:             */
2089:            public void setNull(String parameterName, int sqlType,
2090:                    String typeName) throws SQLException {
2091:                setNull(parameterName, sqlType);
2092:            }
2093:
2094:            /**
2095:             * Retrieves the value of a JDBC <code>CHAR</code>,<code>VARCHAR</code>,
2096:             * or <code>LONGVARCHAR</code> parameter as a <code>String</code> in the
2097:             * Java programming language.
2098:             * <p>
2099:             * For the fixed-length type JDBC <code>CHAR</code>, the
2100:             * <code>String</code> object returned has exactly the same value the JDBC
2101:             * <code>CHAR</code> value had in the database, including any padding added
2102:             * by the database.
2103:             * 
2104:             * @param parameterName the name of the parameter
2105:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2106:             *         result is <code>null</code>.
2107:             * @exception SQLException if a database access error occurs
2108:             * @see #setString
2109:             * @since 1.4
2110:             */
2111:            public String getString(String parameterName) throws SQLException {
2112:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2113:                    throw new SQLException("Invalid named parameter "
2114:                            + parameterName);
2115:
2116:                try {
2117:                    return (String) namedParameterValues.get(parameterName);
2118:                } catch (Exception e) {
2119:                    throw new SQLException("Unable to convert named parameter "
2120:                            + parameterName + " to the requested type");
2121:                }
2122:            }
2123:
2124:            /**
2125:             * Retrieves the value of a JDBC <code>BIT</code> parameter as a
2126:             * <code>boolean</code> in the Java programming language.
2127:             * 
2128:             * @param parameterName the name of the parameter
2129:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2130:             *         result is <code>false</code>.
2131:             * @exception SQLException if a database access error occurs
2132:             * @see #setBoolean
2133:             * @since 1.4
2134:             */
2135:            public boolean getBoolean(String parameterName) throws SQLException {
2136:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2137:                    throw new SQLException("Invalid named parameter "
2138:                            + parameterName);
2139:
2140:                try {
2141:                    Boolean b = (Boolean) namedParameterValues
2142:                            .get(parameterName);
2143:                    if (b == null)
2144:                        return false;
2145:                    else
2146:                        return b.booleanValue();
2147:                } catch (Exception e) {
2148:                    throw new SQLException("Unable to convert named parameter "
2149:                            + parameterName + " to the requested type");
2150:                }
2151:            }
2152:
2153:            /**
2154:             * Retrieves the value of a JDBC <code>TINYINT</code> parameter as a
2155:             * <code>byte</code> in the Java programming language.
2156:             * 
2157:             * @param parameterName the name of the parameter
2158:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2159:             *         result is <code>0</code>.
2160:             * @exception SQLException if a database access error occurs
2161:             * @see #setByte
2162:             * @since 1.4
2163:             */
2164:            public byte getByte(String parameterName) throws SQLException {
2165:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2166:                    throw new SQLException("Invalid named parameter "
2167:                            + parameterName);
2168:
2169:                try {
2170:                    Byte b = (Byte) namedParameterValues.get(parameterName);
2171:                    if (b == null)
2172:                        return 0;
2173:                    else
2174:                        return b.byteValue();
2175:                } catch (Exception e) {
2176:                    throw new SQLException("Unable to convert named parameter "
2177:                            + parameterName + " to the requested type");
2178:                }
2179:            }
2180:
2181:            /**
2182:             * Retrieves the value of a JDBC <code>SMALLINT</code> parameter as a
2183:             * <code>short</code> in the Java programming language.
2184:             * 
2185:             * @param parameterName the name of the parameter
2186:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2187:             *         result is <code>0</code>.
2188:             * @exception SQLException if a database access error occurs
2189:             * @see #setShort
2190:             * @since 1.4
2191:             */
2192:            public short getShort(String parameterName) throws SQLException {
2193:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2194:                    throw new SQLException("Invalid named parameter "
2195:                            + parameterName);
2196:
2197:                try {
2198:                    Short s = (Short) namedParameterValues.get(parameterName);
2199:                    if (s == null)
2200:                        return 0;
2201:                    else
2202:                        return s.shortValue();
2203:                } catch (Exception e) {
2204:                    throw new SQLException("Unable to convert named parameter "
2205:                            + parameterName + " to the requested type");
2206:                }
2207:            }
2208:
2209:            /**
2210:             * Retrieves the value of a JDBC <code>INTEGER</code> parameter as an
2211:             * <code>int</code> in the Java programming language.
2212:             * 
2213:             * @param parameterName the name of the parameter
2214:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2215:             *         result is <code>0</code>.
2216:             * @exception SQLException if a database access error occurs
2217:             * @see #setInt
2218:             * @since 1.4
2219:             */
2220:            public int getInt(String parameterName) throws SQLException {
2221:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2222:                    throw new SQLException("Invalid named parameter "
2223:                            + parameterName);
2224:
2225:                try {
2226:                    Integer i = (Integer) namedParameterValues
2227:                            .get(parameterName);
2228:                    if (i == null)
2229:                        return 0;
2230:                    else
2231:                        return i.intValue();
2232:                } catch (Exception e) {
2233:                    throw new SQLException("Unable to convert named parameter "
2234:                            + parameterName + " to the requested type");
2235:                }
2236:            }
2237:
2238:            /**
2239:             * Retrieves the value of a JDBC <code>BIGINT</code> parameter as a
2240:             * <code>long</code> in the Java programming language.
2241:             * 
2242:             * @param parameterName the name of the parameter
2243:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2244:             *         result is <code>0</code>.
2245:             * @exception SQLException if a database access error occurs
2246:             * @see #setLong
2247:             * @since 1.4
2248:             */
2249:            public long getLong(String parameterName) throws SQLException {
2250:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2251:                    throw new SQLException("Invalid named parameter "
2252:                            + parameterName);
2253:
2254:                try {
2255:                    Long l = (Long) namedParameterValues.get(parameterName);
2256:                    if (l == null)
2257:                        return 0;
2258:                    else
2259:                        return l.longValue();
2260:                } catch (Exception e) {
2261:                    throw new SQLException("Unable to convert named parameter "
2262:                            + parameterName + " to the requested type");
2263:                }
2264:            }
2265:
2266:            /**
2267:             * Retrieves the value of a JDBC <code>FLOAT</code> parameter as a
2268:             * <code>float</code> in the Java programming language.
2269:             * 
2270:             * @param parameterName the name of the parameter
2271:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2272:             *         result is <code>0</code>.
2273:             * @exception SQLException if a database access error occurs
2274:             * @see #setFloat
2275:             * @since 1.4
2276:             */
2277:            public float getFloat(String parameterName) throws SQLException {
2278:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2279:                    throw new SQLException("Invalid named parameter "
2280:                            + parameterName);
2281:
2282:                try {
2283:                    Float f = (Float) namedParameterValues.get(parameterName);
2284:                    if (f == null)
2285:                        return 0;
2286:                    else
2287:                        return f.floatValue();
2288:                } catch (Exception e) {
2289:                    throw new SQLException("Unable to convert named parameter "
2290:                            + parameterName + " to the requested type");
2291:                }
2292:            }
2293:
2294:            /**
2295:             * Retrieves the value of a JDBC <code>DOUBLE</code> parameter as a
2296:             * <code>double</code> in the Java programming language.
2297:             * 
2298:             * @param parameterName the name of the parameter
2299:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2300:             *         result is <code>0</code>.
2301:             * @exception SQLException if a database access error occurs
2302:             * @see #setDouble
2303:             * @since 1.4
2304:             */
2305:            public double getDouble(String parameterName) throws SQLException {
2306:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2307:                    throw new SQLException("Invalid named parameter "
2308:                            + parameterName);
2309:
2310:                try {
2311:                    Double d = (Double) namedParameterValues.get(parameterName);
2312:                    if (d == null)
2313:                        return 0;
2314:                    else
2315:                        return d.doubleValue();
2316:                } catch (Exception e) {
2317:                    throw new SQLException("Unable to convert named parameter "
2318:                            + parameterName + " to the requested type");
2319:                }
2320:            }
2321:
2322:            /**
2323:             * Retrieves the value of a JDBC <code>BINARY</code> or
2324:             * <code>VARBINARY</code> parameter as an array of <code>byte</code>
2325:             * values in the Java programming language.
2326:             * 
2327:             * @param parameterName the name of the parameter
2328:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2329:             *         result is <code>null</code>.
2330:             * @exception SQLException if a database access error occurs
2331:             * @see #setBytes
2332:             * @since 1.4
2333:             */
2334:            public byte[] getBytes(String parameterName) throws SQLException {
2335:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2336:                    throw new SQLException("Invalid named parameter "
2337:                            + parameterName);
2338:
2339:                try {
2340:                    return (byte[]) namedParameterValues.get(parameterName);
2341:                } catch (Exception e) {
2342:                    throw new SQLException("Unable to convert named parameter "
2343:                            + parameterName + " to the requested type");
2344:                }
2345:            }
2346:
2347:            /**
2348:             * Retrieves the value of a JDBC <code>DATE</code> parameter as a
2349:             * <code>java.sql.Date</code> object.
2350:             * 
2351:             * @param parameterName the name of the parameter
2352:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2353:             *         result is <code>null</code>.
2354:             * @exception SQLException if a database access error occurs
2355:             * @see #setDate(String, Date)
2356:             * @since 1.4
2357:             */
2358:            public Date getDate(String parameterName) throws SQLException {
2359:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2360:                    throw new SQLException("Invalid named parameter "
2361:                            + parameterName);
2362:
2363:                try {
2364:                    return (Date) namedParameterValues.get(parameterName);
2365:                } catch (Exception e) {
2366:                    throw new SQLException("Unable to convert named parameter "
2367:                            + parameterName + " to the requested type");
2368:                }
2369:            }
2370:
2371:            /**
2372:             * Retrieves the value of a JDBC <code>TIME</code> parameter as a
2373:             * <code>java.sql.Time</code> object.
2374:             * 
2375:             * @param parameterName the name of the parameter
2376:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2377:             *         result is <code>null</code>.
2378:             * @exception SQLException if a database access error occurs
2379:             * @see #setTime(String, Time)
2380:             * @since 1.4
2381:             */
2382:            public Time getTime(String parameterName) throws SQLException {
2383:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2384:                    throw new SQLException("Invalid named parameter "
2385:                            + parameterName);
2386:
2387:                try {
2388:                    return (Time) namedParameterValues.get(parameterName);
2389:                } catch (Exception e) {
2390:                    throw new SQLException("Unable to convert named parameter "
2391:                            + parameterName + " to the requested type");
2392:                }
2393:            }
2394:
2395:            /**
2396:             * Retrieves the value of a JDBC <code>TIMESTAMP</code> parameter as a
2397:             * <code>java.sql.Timestamp</code> object.
2398:             * 
2399:             * @param parameterName the name of the parameter
2400:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2401:             *         result is <code>null</code>.
2402:             * @exception SQLException if a database access error occurs
2403:             * @see #setTimestamp(String, Timestamp)
2404:             * @since 1.4
2405:             */
2406:            public Timestamp getTimestamp(String parameterName)
2407:                    throws SQLException {
2408:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2409:                    throw new SQLException("Invalid named parameter "
2410:                            + parameterName);
2411:
2412:                try {
2413:                    return (Timestamp) namedParameterValues.get(parameterName);
2414:                } catch (Exception e) {
2415:                    throw new SQLException("Unable to convert named parameter "
2416:                            + parameterName + " to the requested type");
2417:                }
2418:            }
2419:
2420:            /**
2421:             * Retrieves the value of a parameter as an <code>Object</code> in the Java
2422:             * programming language. If the value is an SQL <code>NULL</code>, the
2423:             * driver returns a Java <code>null</code>.
2424:             * <p>
2425:             * This method returns a Java object whose type corresponds to the JDBC type
2426:             * that was registered for this parameter using the method
2427:             * <code>registerOutParameter</code>. By registering the target JDBC type
2428:             * as <code>java.sql.Types.OTHER</code>, this method can be used to read
2429:             * database-specific abstract data types.
2430:             * 
2431:             * @param parameterName the name of the parameter
2432:             * @return A <code>java.lang.Object</code> holding the OUT parameter value.
2433:             * @exception SQLException if a database access error occurs
2434:             * @see java.sql.Types
2435:             * @see #setObject(String, Object)
2436:             * @since 1.4
2437:             */
2438:            public Object getObject(String parameterName) throws SQLException {
2439:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2440:                    throw new SQLException("Invalid named parameter "
2441:                            + parameterName);
2442:
2443:                try {
2444:                    return namedParameterValues.get(parameterName);
2445:                } catch (Exception e) {
2446:                    throw new SQLException("Unable to convert named parameter "
2447:                            + parameterName + " to the requested type");
2448:                }
2449:            }
2450:
2451:            /**
2452:             * Retrieves the value of a JDBC <code>NUMERIC</code> parameter as a
2453:             * <code>java.math.BigDecimal</code> object with as many digits to the right
2454:             * of the decimal point as the value contains.
2455:             * 
2456:             * @param parameterName the name of the parameter
2457:             * @return the parameter value in full precision. If the value is SQL
2458:             *         <code>NULL</code>, the result is <code>null</code>.
2459:             * @exception SQLException if a database access error occurs
2460:             * @see #setBigDecimal
2461:             * @since 1.4
2462:             */
2463:            public BigDecimal getBigDecimal(String parameterName)
2464:                    throws SQLException {
2465:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2466:                    throw new SQLException("Invalid named parameter "
2467:                            + parameterName);
2468:
2469:                try {
2470:                    return (BigDecimal) namedParameterValues.get(parameterName);
2471:                } catch (Exception e) {
2472:                    throw new SQLException("Unable to convert named parameter "
2473:                            + parameterName + " to the requested type");
2474:                }
2475:            }
2476:
2477:            /**
2478:             * Returns an object representing the value of OUT parameter <code>i</code>
2479:             * and uses <code>map</code> for the custom mapping of the parameter value.
2480:             * <p>
2481:             * This method returns a Java object whose type corresponds to the JDBC type
2482:             * that was registered for this parameter using the method
2483:             * <code>registerOutParameter</code>. By registering the target JDBC type
2484:             * as <code>java.sql.Types.OTHER</code>, this method can be used to read
2485:             * database-specific abstract data types.
2486:             * 
2487:             * @param parameterName the name of the parameter
2488:             * @param map the mapping from SQL type names to Java classes
2489:             * @return a <code>java.lang.Object</code> holding the OUT parameter value
2490:             * @exception SQLException if a database access error occurs
2491:             * @see #setObject(String, Object)
2492:             * @since 1.4
2493:             */
2494:            public Object getObject(String parameterName, Map map)
2495:                    throws SQLException {
2496:                throw new NotImplementedException("getObject");
2497:            }
2498:
2499:            /**
2500:             * Retrieves the value of a JDBC <code>REF(&lt;structured-type&gt;)</code>
2501:             * parameter as a <code>Ref</code> object in the Java programming language.
2502:             * 
2503:             * @param parameterName the name of the parameter
2504:             * @return the parameter value as a <code>Ref</code> object in the Java
2505:             *         programming language. If the value was SQL <code>NULL</code>,
2506:             *         the value <code>null</code> is returned.
2507:             * @exception SQLException if a database access error occurs
2508:             * @since 1.4
2509:             */
2510:            public Ref getRef(String parameterName) throws SQLException {
2511:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2512:                    throw new SQLException("Invalid named parameter "
2513:                            + parameterName);
2514:
2515:                try {
2516:                    return (Ref) namedParameterValues.get(parameterName);
2517:                } catch (Exception e) {
2518:                    throw new SQLException("Unable to convert named parameter "
2519:                            + parameterName + " to the requested type");
2520:                }
2521:            }
2522:
2523:            /**
2524:             * Retrieves the value of a JDBC <code>BLOB</code> parameter as a
2525:             * {@link Blob}object in the Java programming language.
2526:             * 
2527:             * @param parameterName the name of the parameter
2528:             * @return the parameter value as a <code>Blob</code> object in the Java
2529:             *         programming language. If the value was SQL <code>NULL</code>,
2530:             *         the value <code>null</code> is returned.
2531:             * @exception SQLException if a database access error occurs
2532:             * @since 1.4
2533:             */
2534:            public Blob getBlob(String parameterName) throws SQLException {
2535:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2536:                    throw new SQLException("Invalid named parameter "
2537:                            + parameterName);
2538:
2539:                try {
2540:                    return (Blob) namedParameterValues.get(parameterName);
2541:                } catch (Exception e) {
2542:                    throw new SQLException("Unable to convert named parameter "
2543:                            + parameterName + " to the requested type");
2544:                }
2545:            }
2546:
2547:            /**
2548:             * Retrieves the value of a JDBC <code>CLOB</code> parameter as a
2549:             * <code>Clob</code> object in the Java programming language.
2550:             * 
2551:             * @param parameterName the name of the parameter
2552:             * @return the parameter value as a <code>Clob</code> object in the Java
2553:             *         programming language. If the value was SQL <code>NULL</code>,
2554:             *         the value <code>null</code> is returned.
2555:             * @exception SQLException if a database access error occurs
2556:             * @since 1.4
2557:             */
2558:            public Clob getClob(String parameterName) throws SQLException {
2559:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2560:                    throw new SQLException("Invalid named parameter "
2561:                            + parameterName);
2562:
2563:                try {
2564:                    return (Clob) namedParameterValues.get(parameterName);
2565:                } catch (Exception e) {
2566:                    throw new SQLException("Unable to convert named parameter "
2567:                            + parameterName + " to the requested type");
2568:                }
2569:            }
2570:
2571:            /**
2572:             * Retrieves the value of a JDBC <code>ARRAY</code> parameter as an
2573:             * {@link Array}object in the Java programming language.
2574:             * 
2575:             * @param parameterName the name of the parameter
2576:             * @return the parameter value as an <code>Array</code> object in Java
2577:             *         programming language. If the value was SQL <code>NULL</code>,
2578:             *         the value <code>null</code> is returned.
2579:             * @exception SQLException if a database access error occurs
2580:             * @since 1.4
2581:             */
2582:            public Array getArray(String parameterName) throws SQLException {
2583:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2584:                    throw new SQLException("Invalid named parameter "
2585:                            + parameterName);
2586:
2587:                try {
2588:                    return (Array) namedParameterValues.get(parameterName);
2589:                } catch (Exception e) {
2590:                    throw new SQLException("Unable to convert named parameter "
2591:                            + parameterName + " to the requested type");
2592:                }
2593:            }
2594:
2595:            /**
2596:             * Retrieves the value of a JDBC <code>DATE</code> parameter as a
2597:             * <code>java.sql.Date</code> object, using the given <code>Calendar</code>
2598:             * object to construct the date. With a <code>Calendar</code> object, the
2599:             * driver can calculate the date taking into account a custom timezone and
2600:             * locale. If no <code>Calendar</code> object is specified, the driver uses
2601:             * the default timezone and locale.
2602:             * 
2603:             * @param parameterName the name of the parameter
2604:             * @param cal the <code>Calendar</code> object the driver will use to
2605:             *          construct the date
2606:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2607:             *         result is <code>null</code>.
2608:             * @exception SQLException if a database access error occurs
2609:             * @see #setDate(String, Date, Calendar)
2610:             * @since 1.4
2611:             */
2612:            public Date getDate(String parameterName, Calendar cal)
2613:                    throws SQLException {
2614:                return getDate(executeUpdate());
2615:            }
2616:
2617:            /**
2618:             * Retrieves the value of a JDBC <code>TIME</code> parameter as a
2619:             * <code>java.sql.Time</code> object, using the given <code>Calendar</code>
2620:             * object to construct the time. With a <code>Calendar</code> object, the
2621:             * driver can calculate the time taking into account a custom timezone and
2622:             * locale. If no <code>Calendar</code> object is specified, the driver uses
2623:             * the default timezone and locale.
2624:             * 
2625:             * @param parameterName the name of the parameter
2626:             * @param cal the <code>Calendar</code> object the driver will use to
2627:             *          construct the time
2628:             * @return the parameter value; if the value is SQL <code>NULL</code>, the
2629:             *         result is <code>null</code>.
2630:             * @exception SQLException if a database access error occurs
2631:             * @see #setTime(String, Time, Calendar)
2632:             * @since 1.4
2633:             */
2634:            public Time getTime(String parameterName, Calendar cal)
2635:                    throws SQLException {
2636:                return getTime(executeUpdate());
2637:            }
2638:
2639:            /**
2640:             * Retrieves the value of a JDBC <code>TIMESTAMP</code> parameter as a
2641:             * <code>java.sql.Timestamp</code> object, using the given
2642:             * <code>Calendar</code> object to construct the <code>Timestamp</code>
2643:             * object. With a <code>Calendar</code> object, the driver can calculate the
2644:             * timestamp taking into account a custom timezone and locale. If no
2645:             * <code>Calendar</code> object is specified, the driver uses the default
2646:             * timezone and locale.
2647:             * 
2648:             * @param parameterName the name of the parameter
2649:             * @param cal the <code>Calendar</code> object the driver will use to
2650:             *          construct the timestamp
2651:             * @return the parameter value. If the value is SQL <code>NULL</code>, the
2652:             *         result is <code>null</code>.
2653:             * @exception SQLException if a database access error occurs
2654:             * @see #setTimestamp(String, Timestamp, Calendar)
2655:             * @since 1.4
2656:             */
2657:            public Timestamp getTimestamp(String parameterName, Calendar cal)
2658:                    throws SQLException {
2659:                return getTimestamp(executeUpdate());
2660:            }
2661:
2662:            /**
2663:             * Retrieves the value of a JDBC <code>DATALINK</code> parameter as a
2664:             * <code>java.net.URL</code> object.
2665:             * 
2666:             * @param parameterName the name of the parameter
2667:             * @return the parameter value as a <code>java.net.URL</code> object in the
2668:             *         Java programming language. If the value was SQL <code>NULL</code>,
2669:             *         the value <code>null</code> is returned.
2670:             * @exception SQLException if a database access error occurs, or if there is a
2671:             *              problem with the URL
2672:             * @see #setURL
2673:             * @since 1.4
2674:             */
2675:            public URL getURL(String parameterName) throws SQLException {
2676:                if (!outAndNamedParameterTypes.containsKey(parameterName))
2677:                    throw new SQLException("Invalid named parameter "
2678:                            + parameterName);
2679:
2680:                try {
2681:                    return (URL) namedParameterValues.get(parameterName);
2682:                } catch (Exception e) {
2683:                    throw new SQLException("Unable to convert named parameter "
2684:                            + parameterName + " to the requested type");
2685:                }
2686:            }
2687:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.