Source Code Cross Referenced for ResultSetTest.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » functionTests » tests » jdbc4 » 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 DBMS » db derby 10.2 » org.apache.derbyTesting.functionTests.tests.jdbc4 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         
0003:           Derby - Class ResultSetTest
0004:         
0005:           Licensed to the Apache Software Foundation (ASF) under one or more
0006:           contributor license agreements.  See the NOTICE file distributed with
0007:           this work for additional information regarding copyright ownership.
0008:           The ASF licenses this file to you under the Apache License, Version 2.0
0009:           (the "License"); you may not use this file except in compliance with
0010:           the License.  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:         */
0021:
0022:        package org.apache.derbyTesting.functionTests.tests.jdbc4;
0023:
0024:        import javax.xml.transform.Result;
0025:        import junit.extensions.TestSetup;
0026:        import junit.framework.*;
0027:
0028:        import org.apache.derbyTesting.junit.BaseJDBCTestCase;
0029:        import org.apache.derbyTesting.junit.BaseJDBCTestSetup;
0030:
0031:        import java.io.*;
0032:        import java.sql.*;
0033:
0034:        /**
0035:         * Tests of JDBC4 features in ResultSet.
0036:         *
0037:         * Some utility methods have been introduced for the updateXXX test-methods.
0038:         * This test also makes use of a TestSetup wrapper to perform one-time
0039:         * setup and teardown for the whole suite.
0040:         */
0041:        public class ResultSetTest extends BaseJDBCTestCase {
0042:
0043:            private static final byte[] BYTES1 = { 0x65, 0x66, 0x67, 0x68,
0044:                    0x69, 0x69, 0x68, 0x67, 0x66, 0x65 };
0045:
0046:            private static final byte[] BYTES2 = { 0x69, 0x68, 0x67, 0x66,
0047:                    0x65, 0x65, 0x66, 0x67, 0x68, 0x69 };
0048:
0049:            /** 
0050:             * Key used to identify inserted rows.
0051:             * Use method <code>requestKey</code> to obtain it. 
0052:             **/
0053:            private static int insertKey = 0;
0054:
0055:            /** Statement used to obtain default resultset. */
0056:            private Statement stmt = null;
0057:            /** Default resultset used by the tests. */
0058:            private ResultSet rs = null;
0059:            /** Default row identifier used by the tests. */
0060:            private int key = -1;
0061:
0062:            /**
0063:             * Create test with given name.
0064:             *
0065:             * @param name name of the test.
0066:             */
0067:            public ResultSetTest(String name) {
0068:                super (name);
0069:            }
0070:
0071:            protected void setUp() throws SQLException {
0072:                key = requestKey();
0073:                stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY,
0074:                        ResultSet.CONCUR_UPDATABLE);
0075:
0076:                rs = stmt.executeQuery("SELECT * FROM SYS.SYSTABLES");
0077:
0078:                // Position on first result.
0079:                rs.next();
0080:            }
0081:
0082:            protected void tearDown() throws Exception {
0083:
0084:                if (rs != null) {
0085:                    rs.close();
0086:                }
0087:                if (stmt != null) {
0088:                    stmt.close();
0089:                }
0090:
0091:                super .tearDown();
0092:            }
0093:
0094:            public void testGetNCharacterStreamIntNotImplemented()
0095:                    throws SQLException {
0096:                try {
0097:                    rs.getNCharacterStream(1);
0098:                    fail("ResultSet.getNCharacterStream(int) "
0099:                            + "should not be implemented");
0100:                } catch (SQLFeatureNotSupportedException sfnse) {
0101:                    // We are fine, do nothing.
0102:                }
0103:            }
0104:
0105:            public void testGetNCharaterStreamStringNotImplemented()
0106:                    throws SQLException {
0107:                try {
0108:                    rs.getNCharacterStream("some-column-name");
0109:                    fail("ResultSet.getNCharacterStream(String) "
0110:                            + "should not be implemented");
0111:                } catch (SQLFeatureNotSupportedException sfnse) {
0112:                    // We are fine, do nothing.
0113:                }
0114:            }
0115:
0116:            public void testGetNClobNotIntImplemented() throws SQLException {
0117:                try {
0118:                    rs.getNClob(1);
0119:                    fail("ResultSet.getNClob(int) "
0120:                            + "should not be implemented");
0121:                } catch (SQLFeatureNotSupportedException sfnse) {
0122:                    // We are fine, do nothing.
0123:                }
0124:            }
0125:
0126:            public void testGetNClobStringNotImplemented() throws SQLException {
0127:                try {
0128:                    rs.getNClob("some-column-name");
0129:                    fail("ResultSet.getNClob(String) "
0130:                            + "should not be implemented");
0131:                } catch (SQLFeatureNotSupportedException sfnse) {
0132:                    // We are fine, do nothing.
0133:                }
0134:            }
0135:
0136:            public void testGetNStringIntNotImplemented() throws SQLException {
0137:                try {
0138:                    rs.getNString(1);
0139:                    fail("ResultSet.getNString(int) "
0140:                            + "should not be implemented");
0141:                } catch (SQLFeatureNotSupportedException sfnse) {
0142:                    // We are fine, do nothing.
0143:                }
0144:            }
0145:
0146:            public void testGetNStringStringNotImplemented()
0147:                    throws SQLException {
0148:                try {
0149:                    rs.getNString("some-column-name");
0150:                    fail("ResultSet.getNString(String) "
0151:                            + "should not be implemented");
0152:                } catch (SQLFeatureNotSupportedException sfnse) {
0153:                    // We are fine, do nothing.
0154:                }
0155:            }
0156:
0157:            public void testGetSQLXMLIntNotImplemented() throws SQLException {
0158:                try {
0159:                    rs.getSQLXML(1);
0160:                    fail("ResultSet.getSQLXML(int) "
0161:                            + "should not be implemented");
0162:                } catch (SQLFeatureNotSupportedException sfnse) {
0163:                    // We are fine, do nothing.
0164:                }
0165:            }
0166:
0167:            public void testGetSQLXMLStringNotImplemented() throws SQLException {
0168:                try {
0169:                    rs.getSQLXML("some-column-name");
0170:                    fail("ResultSet.getSQLXML(String) "
0171:                            + "should not be implemented");
0172:                } catch (SQLFeatureNotSupportedException sfnse) {
0173:                    // We are fine, do nothing.
0174:                }
0175:            }
0176:
0177:            public void testUpdateNCharacterStreamIntNotImplemented()
0178:                    throws SQLException {
0179:                try {
0180:                    rs.updateNCharacterStream(1, null, 0);
0181:                    fail("ResultSet.updateNCharacterStream(int, Reader, int) "
0182:                            + "should not be implemented");
0183:                } catch (SQLFeatureNotSupportedException sfnse) {
0184:                    // We are fine, do nothing.
0185:                }
0186:            }
0187:
0188:            public void testUpdateNCharacterStreamIntLengthLessNotImplemented()
0189:                    throws SQLException {
0190:                try {
0191:                    rs.updateNCharacterStream(1, null);
0192:                    fail("ResultSet.updateNCharacterStream(int, Reader) "
0193:                            + "should not be implemented");
0194:                } catch (SQLFeatureNotSupportedException sfnse) {
0195:                    // We are fine, do nothing.
0196:                }
0197:            }
0198:
0199:            public void testUpdateNCharacterStreamStringNotImplemented()
0200:                    throws SQLException {
0201:                try {
0202:                    rs.updateNCharacterStream("some-column-name", null, 0);
0203:                    fail("ResultSet.updateNCharacterStream(String, Reader, 0) "
0204:                            + "should not be implemented");
0205:                } catch (SQLFeatureNotSupportedException sfnse) {
0206:                    // We are fine, do nothing.
0207:                }
0208:            }
0209:
0210:            public void testUpdateNCharacterStreamStringLengthlessNotImplemented()
0211:                    throws SQLException {
0212:                try {
0213:                    rs.updateNCharacterStream("some-column-name", null);
0214:                    fail("ResultSet.updateNCharacterStream(String, Reader) "
0215:                            + "should not be implemented");
0216:                } catch (SQLFeatureNotSupportedException sfnse) {
0217:                    // We are fine, do nothing.
0218:                }
0219:            }
0220:
0221:            public void testUpdateNClobIntNotImplemented() throws SQLException {
0222:                try {
0223:                    rs.updateNClob(1, (NClob) null);
0224:                    fail("ResultSet.updateNClob(int, NClob) "
0225:                            + "should not be implemented");
0226:                } catch (SQLFeatureNotSupportedException sfnse) {
0227:                    // We are fine, do nothing.
0228:                }
0229:            }
0230:
0231:            public void testUpdateNClobIntLengthlessNotImplemented()
0232:                    throws SQLException {
0233:                try {
0234:                    rs.updateNClob(1, (Reader) null);
0235:                    fail("ResultSet.updateNClob(int, Reader) "
0236:                            + "should not be implemented");
0237:                } catch (SQLFeatureNotSupportedException sfnse) {
0238:                    // We are fine, do nothing.
0239:                }
0240:            }
0241:
0242:            public void testUpdateNClobStringNotImplemented()
0243:                    throws SQLException {
0244:                try {
0245:                    rs.updateNClob("some-column-name", (NClob) null);
0246:                    fail("ResultSet.updateNClob(String, NClob) "
0247:                            + "should not be implemented");
0248:                } catch (SQLFeatureNotSupportedException sfnse) {
0249:                    // We are fine, do nothing.
0250:                }
0251:            }
0252:
0253:            public void testUpdateNClobStringLengthlessNotImplemented()
0254:                    throws SQLException {
0255:                try {
0256:                    rs.updateNClob("some-column-name", (Reader) null);
0257:                    fail("ResultSet.updateNClob(String, Reader) "
0258:                            + "should not be implemented");
0259:                } catch (SQLFeatureNotSupportedException sfnse) {
0260:                    // We are fine, do nothing.
0261:                }
0262:            }
0263:
0264:            public void testUpdateNStringIntNotImplemented()
0265:                    throws SQLException {
0266:                try {
0267:                    rs.updateNString(1, null);
0268:                    fail("ResultSet.updateNString(int, String) "
0269:                            + "should not be implemented");
0270:                } catch (SQLFeatureNotSupportedException sfnse) {
0271:                    // We are fine, do nothing.
0272:                }
0273:            }
0274:
0275:            public void testUpdateNStringStringNotImplemented()
0276:                    throws SQLException {
0277:                try {
0278:                    rs.updateNString("some-column-name", null);
0279:                    fail("ResultSet.updateNString(String, String) "
0280:                            + "should not be implemented");
0281:                } catch (SQLFeatureNotSupportedException sfnse) {
0282:                    // We are fine, do nothing.
0283:                }
0284:            }
0285:
0286:            public void testUpdateSQLXMLIntNotImplemented() throws SQLException {
0287:                try {
0288:                    rs.updateSQLXML(1, null);
0289:                    fail("ResultSet.updateSQLXML(int, SQLXML) "
0290:                            + "should not be implemented");
0291:                } catch (SQLFeatureNotSupportedException sfnse) {
0292:                    // We are fine, do nothing.
0293:                }
0294:            }
0295:
0296:            public void testUpdateSQLXMLStringNotImplemented()
0297:                    throws SQLException {
0298:                try {
0299:                    rs.updateSQLXML("some-column-name", null);
0300:                    fail("ResultSet.updateSQLXML(String, SQLXML) "
0301:                            + "should not be implemented");
0302:                } catch (SQLFeatureNotSupportedException sfnse) {
0303:                    // We are fine, do nothing.
0304:                }
0305:            }
0306:
0307:            /**
0308:             * This methods tests the ResultSet interface method
0309:             * updateBinaryStream
0310:             *
0311:             * @throws SQLException if some error occurs while calling the method
0312:             */
0313:
0314:            public void testUpdateBinaryStream() throws Exception {
0315:                //Byte array in which the returned bytes from
0316:                //the Database after the update are stored. This
0317:                //array is then checked to determine if it
0318:                //has the same elements of the Byte array used for
0319:                //the update operation
0320:
0321:                byte[] bytes_ret = new byte[10];
0322:
0323:                //Input Stream inserted initially
0324:                InputStream is = new java.io.ByteArrayInputStream(BYTES1);
0325:
0326:                //InputStream that is used for update
0327:                InputStream is_for_update = new java.io.ByteArrayInputStream(
0328:                        BYTES2);
0329:
0330:                //Prepared Statement used to insert the data
0331:                PreparedStatement ps_sb = prep("dLongBit");
0332:                ps_sb.setInt(1, key);
0333:                ps_sb.setBinaryStream(2, is, BYTES1.length);
0334:                ps_sb.executeUpdate();
0335:                ps_sb.close();
0336:
0337:                //Update operation
0338:                //use a different ResultSet variable so that the
0339:                //other tests can go on unimpacted
0340:
0341:                ResultSet rs1 = fetchUpd("dLongBit", key);
0342:                rs1.next();
0343:                rs1.updateBinaryStream(1, is_for_update, (int) BYTES2.length);
0344:                rs1.updateRow();
0345:                rs1.close();
0346:
0347:                //Query to see whether the data that has been updated
0348:                //using the updateBinaryStream method is the same
0349:                //data that we expected
0350:
0351:                rs1 = fetch("dLongBit", key);
0352:                rs1.next();
0353:                InputStream is_ret = rs1.getBinaryStream(1);
0354:
0355:                is_ret.read(bytes_ret);
0356:                is_ret.close();
0357:
0358:                for (int i = 0; i < BYTES2.length; i++) {
0359:                    assertEquals("Error in updateBinaryStream", BYTES2[i],
0360:                            bytes_ret[i]);
0361:                }
0362:                rs1.close();
0363:            }
0364:
0365:            /**
0366:             * This methods tests the ResultSet interface method
0367:             * updateAsciiStream
0368:             *
0369:             * @throws SQLException if some error occurs while calling the method
0370:             */
0371:
0372:            public void testUpdateAsciiStream() throws Exception {
0373:                //create the table
0374:                stmt
0375:                        .execute("create table UpdateTestTable_ResultSet (sno int, "
0376:                                + "datacol LONG VARCHAR)");
0377:
0378:                //Byte array in which the returned bytes from
0379:                //the Database after the update are stored. This
0380:                //array is then checked to determine if it
0381:                //has the same elements of the Byte array used for
0382:                //the update operation
0383:
0384:                byte[] bytes_ret = new byte[10];
0385:
0386:                //Input Stream inserted initially
0387:                InputStream is = new java.io.ByteArrayInputStream(BYTES1);
0388:
0389:                //InputStream that is used for update
0390:                InputStream is_for_update = new java.io.ByteArrayInputStream(
0391:                        BYTES2);
0392:
0393:                //Prepared Statement used to insert the data
0394:                PreparedStatement ps_sb = prepareStatement("insert into UpdateTestTable_ResultSet values(?,?)");
0395:                ps_sb.setInt(1, 1);
0396:                ps_sb.setAsciiStream(2, is, BYTES1.length);
0397:                ps_sb.executeUpdate();
0398:                ps_sb.close();
0399:
0400:                //Update operation
0401:                //use a different ResultSet variable so that the
0402:                //other tests can go on unimpacted
0403:
0404:                ResultSet rs1 = stmt
0405:                        .executeQuery("select * from UpdateTestTable_ResultSet for update");
0406:                rs1.next();
0407:                rs1.updateAsciiStream(2, is_for_update, (int) BYTES2.length);
0408:                rs1.updateRow();
0409:                rs1.close();
0410:
0411:                //Query to see whether the data that has been updated
0412:                //using the updateAsciiStream method is the same
0413:                //data that we expected
0414:
0415:                rs1 = stmt
0416:                        .executeQuery("select * from UpdateTestTable_ResultSet");
0417:                rs1.next();
0418:                InputStream is_ret = rs1.getAsciiStream(2);
0419:
0420:                is_ret.read(bytes_ret);
0421:                is_ret.close();
0422:
0423:                for (int i = 0; i < BYTES2.length; i++) {
0424:                    assertEquals("Error in updateAsciiStream", BYTES2[i],
0425:                            bytes_ret[i]);
0426:                }
0427:                rs1.close();
0428:                //delete the table
0429:                stmt.execute("drop table UpdateTestTable_ResultSet");
0430:            }
0431:
0432:            /**
0433:             * This methods tests the ResultSet interface method
0434:             * updateCharacterStream
0435:             *
0436:             * @throws SQLException if some error occurs while calling the method
0437:             */
0438:
0439:            public void testUpdateCharacterStream() throws Exception {
0440:                String str = "Test data";
0441:                String str_for_update = "Test data used for update";
0442:
0443:                StringReader r = new StringReader(str);
0444:                StringReader r_for_update = new StringReader(str_for_update);
0445:
0446:                //Prepared Statement used to insert the data
0447:                PreparedStatement ps_sb = prep("dLongVarchar");
0448:                ps_sb.setInt(1, key);
0449:                ps_sb.setCharacterStream(2, r, str.length());
0450:                ps_sb.executeUpdate();
0451:                ps_sb.close();
0452:
0453:                //Update operation
0454:                //use a different ResultSet variable so that the
0455:                //other tests can go on unimpacted
0456:                ResultSet rs1 = fetchUpd("dLongVarchar", key);
0457:                rs1.next();
0458:                rs1.updateCharacterStream(1, r_for_update, str_for_update
0459:                        .length());
0460:                rs1.updateRow();
0461:                rs1.close();
0462:
0463:                //Query to see whether the data that has been updated
0464:                //using the updateAsciiStream method is the same
0465:                //data that we expected
0466:
0467:                rs1 = fetch("dLongVarchar", key);
0468:                rs1.next();
0469:
0470:                StringReader r_ret = (StringReader) rs1.getCharacterStream(1);
0471:
0472:                char[] c_ret = new char[str_for_update.length()];
0473:
0474:                r_ret.read(c_ret);
0475:
0476:                String str_ret = new String(c_ret);
0477:
0478:                assertEquals("Error in updateCharacterStream" + str_ret,
0479:                        str_for_update, str_ret);
0480:
0481:                rs1.close();
0482:            }
0483:
0484:            /**
0485:             * This methods tests the ResultSet interface method
0486:             * updateBinaryStream
0487:             *
0488:             * @throws SQLException if some error occurs while calling the method
0489:             */
0490:
0491:            public void testUpdateBinaryStreamStringParameterName()
0492:                    throws Exception {
0493:                //Byte array in which the returned bytes from
0494:                //the Database after the update are stored. This
0495:                //array is then checked to determine if it
0496:                //has the same elements of the Byte array used for
0497:                //the update operation
0498:
0499:                byte[] bytes_ret = new byte[10];
0500:
0501:                //Input Stream inserted initially
0502:                InputStream is = new java.io.ByteArrayInputStream(BYTES1);
0503:
0504:                //InputStream that is used for update
0505:                InputStream is_for_update = new java.io.ByteArrayInputStream(
0506:                        BYTES2);
0507:
0508:                //Prepared Statement used to insert the data
0509:                PreparedStatement ps_sb = prep("dLongBit");
0510:                ps_sb.setInt(1, key);
0511:                ps_sb.setBinaryStream(2, is, BYTES1.length);
0512:                ps_sb.executeUpdate();
0513:                ps_sb.close();
0514:
0515:                //Update operation
0516:                //Update operation
0517:                //use a different ResultSet variable so that the
0518:                //other tests can go on unimpacted
0519:
0520:                ResultSet rs1 = fetchUpd("dLongBit", key);
0521:                rs1.next();
0522:                rs1.updateBinaryStream("dLongBit", is_for_update,
0523:                        (int) BYTES2.length);
0524:                rs1.updateRow();
0525:                rs1.close();
0526:
0527:                //Query to see whether the data that has been updated
0528:                //using the updateBinaryStream method is the same
0529:                //data that we expected
0530:
0531:                rs1 = fetch("dLongBit", key);
0532:                rs1.next();
0533:                InputStream is_ret = rs1.getBinaryStream(1);
0534:
0535:                is_ret.read(bytes_ret);
0536:                is_ret.close();
0537:
0538:                for (int i = 0; i < BYTES2.length; i++) {
0539:                    assertEquals("Error in updateBinaryStream", BYTES2[i],
0540:                            bytes_ret[i]);
0541:                }
0542:                rs1.close();
0543:            }
0544:
0545:            /**
0546:             * Test <code>updateBinaryStream</code> on a BINARY column, without
0547:             * specifying length of inputstream.
0548:             */
0549:            public void testUpdateBinaryStreamLengthless() throws IOException,
0550:                    SQLException {
0551:                InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
0552:                // InputStream used for update.
0553:                InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);
0554:
0555:                //Prepared Statement used to insert the data
0556:                PreparedStatement ps_sb = prep("dLongBit");
0557:                ps_sb.setInt(1, key);
0558:                ps_sb.setBinaryStream(2, is1);
0559:                ps_sb.executeUpdate();
0560:                ps_sb.close();
0561:
0562:                //Update operation
0563:                ResultSet rs1 = fetchUpd("dLongBit", key);
0564:                rs1.next();
0565:                rs1.updateBinaryStream(1, is2);
0566:                rs1.updateRow();
0567:                rs1.close();
0568:
0569:                //Query to see whether the data that has been updated
0570:                //using the updateBinaryStream method is the same
0571:                //data that we expected
0572:
0573:                rs1 = fetch("dLongBit", key);
0574:                rs1.next();
0575:                assertEquals(new ByteArrayInputStream(BYTES2), rs1
0576:                        .getBinaryStream(1));
0577:                rs1.close();
0578:            }
0579:
0580:            /**
0581:             * Test <code>updateBinaryStream</code> on a BLOB column, without
0582:             * specifying length of inputstream.
0583:             */
0584:            public void testUpdateBinaryStreamLengthlessBlob()
0585:                    throws IOException, SQLException {
0586:                InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
0587:                // InputStream used for update.
0588:                InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);
0589:
0590:                //Prepared Statement used to insert the data
0591:                PreparedStatement ps_sb = prep("dBlob");
0592:                ps_sb.setInt(1, key);
0593:                ps_sb.setBinaryStream(2, is1);
0594:                ps_sb.executeUpdate();
0595:                ps_sb.close();
0596:
0597:                //Update operation
0598:                ResultSet rs1 = fetchUpd("dBlob", key);
0599:                rs1.next();
0600:                rs1.updateBinaryStream(1, is2);
0601:                rs1.updateRow();
0602:                rs1.close();
0603:
0604:                //Query to see whether the data that has been updated
0605:                //using the updateBinaryStream method is the same
0606:                //data that we expected
0607:
0608:                rs1 = fetch("dBlob", key);
0609:                rs1.next();
0610:                assertEquals(new ByteArrayInputStream(BYTES2), rs1
0611:                        .getBinaryStream(1));
0612:                rs1.close();
0613:            }
0614:
0615:            public void testUpdateBinaryStreamLengthlessParameterName()
0616:                    throws IOException, SQLException {
0617:                InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
0618:                // InputStream used for update.
0619:                InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);
0620:
0621:                //Prepared Statement used to insert the data
0622:                PreparedStatement ps_sb = prep("dLongBit");
0623:                ps_sb.setInt(1, key);
0624:                ps_sb.setBinaryStream(2, is1);
0625:                ps_sb.executeUpdate();
0626:                ps_sb.close();
0627:
0628:                //Update operation
0629:                ResultSet rs1 = fetchUpd("dLongBit", key);
0630:                rs1.next();
0631:                rs1.updateBinaryStream("dLongBit", is2);
0632:                rs1.updateRow();
0633:                rs1.close();
0634:
0635:                //Query to see whether the data that has been updated
0636:                //using the updateBinaryStream method is the same
0637:                //data that we expected
0638:
0639:                rs1 = fetch("dLongBit", key);
0640:                rs1.next();
0641:                assertEquals(new ByteArrayInputStream(BYTES2), rs1
0642:                        .getBinaryStream(1));
0643:                rs1.close();
0644:            }
0645:
0646:            /**
0647:             * This methods tests the ResultSet interface method
0648:             * updateAsciiStream
0649:             *
0650:             * @throws SQLException if some error occurs while calling the method
0651:             */
0652:
0653:            public void testUpdateAsciiStreamStringParameterName()
0654:                    throws Exception {
0655:                //Byte array in which the returned bytes from
0656:                //the Database after the update are stored. This
0657:                //array is then checked to determine if it
0658:                //has the same elements of the Byte array used for
0659:                //the update operation
0660:
0661:                byte[] bytes_ret = new byte[10];
0662:
0663:                //Input Stream inserted initially
0664:                InputStream is = new java.io.ByteArrayInputStream(BYTES1);
0665:
0666:                //InputStream that is used for update
0667:                InputStream is_for_update = new java.io.ByteArrayInputStream(
0668:                        BYTES2);
0669:
0670:                //Prepared Statement used to insert the data
0671:                PreparedStatement ps_sb = prep("dLongVarchar");
0672:                ps_sb.setInt(1, key);
0673:                ps_sb.setAsciiStream(2, is, BYTES1.length);
0674:                ps_sb.executeUpdate();
0675:                ps_sb.close();
0676:
0677:                //Update operation
0678:                //use a different ResultSet variable so that the
0679:                //other tests can go on unimpacted
0680:
0681:                ResultSet rs1 = fetchUpd("dLongVarchar", key);
0682:                rs1.next();
0683:                rs1.updateAsciiStream("dLongVarchar", is_for_update,
0684:                        (int) BYTES2.length);
0685:                rs1.updateRow();
0686:                rs1.close();
0687:
0688:                //Query to see whether the data that has been updated
0689:                //using the updateAsciiStream method is the same
0690:                //data that we expected
0691:
0692:                rs1 = fetch("dLongVarchar", key);
0693:                rs1.next();
0694:                InputStream is_ret = rs1.getAsciiStream(1);
0695:
0696:                is_ret.read(bytes_ret);
0697:                is_ret.close();
0698:
0699:                for (int i = 0; i < BYTES2.length; i++) {
0700:                    assertEquals("Error in updateAsciiStream", BYTES2[i],
0701:                            bytes_ret[i]);
0702:                }
0703:                rs1.close();
0704:            }
0705:
0706:            public void testUpdateAsciiStreamLengthless() throws IOException,
0707:                    SQLException {
0708:                // Array to keep updated data fetched from the database.
0709:                byte[] bytesRet = new byte[10];
0710:
0711:                // Input Stream inserted initially.
0712:                InputStream is = new java.io.ByteArrayInputStream(BYTES1);
0713:
0714:                // InputStream that is used for update.
0715:                InputStream isForUpdate = new java.io.ByteArrayInputStream(
0716:                        BYTES2);
0717:
0718:                // Prepared Statement used to insert the data.
0719:                PreparedStatement ps_sb = prep("dLongVarchar");
0720:                ps_sb.setInt(1, key);
0721:                ps_sb.setAsciiStream(2, is, BYTES1.length);
0722:                ps_sb.executeUpdate();
0723:                ps_sb.close();
0724:
0725:                // Update the data.
0726:                ResultSet rs1 = fetchUpd("dLongVarchar", key);
0727:                rs1.next();
0728:                rs1.updateAsciiStream(1, isForUpdate);
0729:                rs1.updateRow();
0730:                rs1.close();
0731:
0732:                // Query to see whether the data that has been updated.
0733:                rs1 = fetch("dLongVarchar", key);
0734:                rs1.next();
0735:                InputStream isRet = rs1.getAsciiStream(1);
0736:                isRet.read(bytesRet);
0737:                isRet.close();
0738:
0739:                for (int i = 0; i < BYTES2.length; i++) {
0740:                    assertEquals("Error in updateAsciiStream", BYTES2[i],
0741:                            bytesRet[i]);
0742:                }
0743:                rs1.close();
0744:            }
0745:
0746:            public void testUpdateAsciiStreamLengthlessParameterName()
0747:                    throws IOException, SQLException {
0748:                // Array to keep updated data fetched from the database.
0749:                byte[] bytesRet = new byte[10];
0750:
0751:                // Input Stream inserted initially.
0752:                InputStream is = new java.io.ByteArrayInputStream(BYTES1);
0753:
0754:                // InputStream that is used for update.
0755:                InputStream isForUpdate = new java.io.ByteArrayInputStream(
0756:                        BYTES2);
0757:
0758:                // Prepared Statement used to insert the data.
0759:                PreparedStatement ps_sb = prep("dLongVarchar");
0760:                ps_sb.setInt(1, key);
0761:                ps_sb.setAsciiStream(2, is, BYTES1.length);
0762:                ps_sb.executeUpdate();
0763:                ps_sb.close();
0764:
0765:                // Update the data.
0766:                ResultSet rs1 = fetchUpd("dLongVarchar", key);
0767:                rs1.next();
0768:                rs1.updateAsciiStream("dLongVarchar", isForUpdate);
0769:                rs1.updateRow();
0770:                rs1.close();
0771:
0772:                // Query to see whether the data that has been updated.
0773:                rs1 = fetch("dLongVarchar", key);
0774:                rs1.next();
0775:                InputStream isRet = rs1.getAsciiStream(1);
0776:                isRet.read(bytesRet);
0777:                isRet.close();
0778:
0779:                for (int i = 0; i < BYTES2.length; i++) {
0780:                    assertEquals("Error in updateAsciiStream", BYTES2[i],
0781:                            bytesRet[i]);
0782:                }
0783:                rs1.close();
0784:            }
0785:
0786:            /**
0787:             * This methods tests the ResultSet interface method
0788:             * updateCharacterStream
0789:             *
0790:             * @throws SQLException if some error occurs while calling the method
0791:             */
0792:
0793:            public void testUpdateCharacterStreamStringParameterName()
0794:                    throws Exception {
0795:                String str = "Test data";
0796:                String str_for_update = "Test data used for update";
0797:
0798:                StringReader r = new StringReader(str);
0799:                StringReader r_for_update = new StringReader(str_for_update);
0800:
0801:                //Prepared Statement used to insert the data
0802:                PreparedStatement ps_sb = prep("dLongVarchar");
0803:                ps_sb.setInt(1, key);
0804:                ps_sb.setCharacterStream(2, r, str.length());
0805:                ps_sb.executeUpdate();
0806:                ps_sb.close();
0807:
0808:                //Update operation
0809:                //use a different ResultSet variable so that the
0810:                //other tests can go on unimpacted
0811:                ResultSet rs1 = fetchUpd("dLongVarchar", key);
0812:                rs1.next();
0813:                rs1.updateCharacterStream("dLongVarchar", r_for_update,
0814:                        str_for_update.length());
0815:                rs1.updateRow();
0816:                rs1.close();
0817:
0818:                //Query to see whether the data that has been updated
0819:                //using the updateAsciiStream method is the same
0820:                //data that we expected
0821:
0822:                rs1 = fetch("dLongVarchar", key);
0823:                rs1.next();
0824:
0825:                StringReader r_ret = (StringReader) rs1.getCharacterStream(1);
0826:
0827:                char[] c_ret = new char[str_for_update.length()];
0828:
0829:                r_ret.read(c_ret);
0830:
0831:                String str_ret = new String(c_ret);
0832:
0833:                assertEquals("Error in updateCharacterStream" + str_ret,
0834:                        str_for_update, str_ret);
0835:
0836:                rs1.close();
0837:            }
0838:
0839:            public void testUpdateCharacterStreamLengthless()
0840:                    throws IOException, SQLException {
0841:                String str = "This is the (\u0FFF\u1234) test string";
0842:                String strUpdated = "An updated (\u0FEF\u9876) test string";
0843:
0844:                // Insert test data
0845:                PreparedStatement psChar = prep("dLongVarchar");
0846:                psChar.setInt(1, key);
0847:                psChar.setCharacterStream(2, new StringReader(str));
0848:                psChar.execute();
0849:                psChar.close();
0850:
0851:                // Update test data
0852:                ResultSet rs = fetchUpd("dLongVarchar", key);
0853:                rs.next();
0854:                rs.updateCharacterStream(1, new StringReader(strUpdated));
0855:                rs.updateRow();
0856:                rs.close();
0857:
0858:                // Verify that update took place and is correct.
0859:                rs = fetch("dLongVarchar", key);
0860:                rs.next();
0861:                Reader updatedStr = rs.getCharacterStream(1);
0862:                for (int i = 0; i < strUpdated.length(); i++) {
0863:                    assertEquals("Strings differ at index " + i, strUpdated
0864:                            .charAt(i), updatedStr.read());
0865:                }
0866:                assertEquals("Too much data in stream", -1, updatedStr.read());
0867:                updatedStr.close();
0868:            }
0869:
0870:            public void testUpdateCharacterStreamLengthlessParameterName()
0871:                    throws IOException, SQLException {
0872:                String str = "This is the (\u0FFF\u1234) test string";
0873:                String strUpdated = "An updated (\u0FEF\u9876) test string";
0874:
0875:                // Insert test data
0876:                PreparedStatement psChar = prep("dLongVarchar");
0877:                psChar.setInt(1, key);
0878:                psChar.setCharacterStream(2, new StringReader(str));
0879:                psChar.execute();
0880:                psChar.close();
0881:
0882:                // Update test data
0883:                ResultSet rs = fetchUpd("dLongVarchar", key);
0884:                rs.next();
0885:                rs.updateCharacterStream("dLongVarchar", new StringReader(
0886:                        strUpdated));
0887:                rs.updateRow();
0888:                rs.close();
0889:
0890:                // Verify that update took place and is correct.
0891:                rs = fetch("dLongVarchar", key);
0892:                rs.next();
0893:                Reader updatedStr = rs.getCharacterStream(1);
0894:                for (int i = 0; i < strUpdated.length(); i++) {
0895:                    assertEquals("Strings differ at index " + i, strUpdated
0896:                            .charAt(i), updatedStr.read());
0897:                }
0898:                assertEquals("Too much data in stream", -1, updatedStr.read());
0899:                updatedStr.close();
0900:            }
0901:
0902:            /**
0903:             * This methods tests the ResultSet interface method
0904:             * updateClob
0905:             *
0906:             * @throws SQLException if some error occurs while calling the method
0907:             */
0908:            public void embeddedUpdateClob() throws Exception {
0909:                //Byte array in which the returned bytes from
0910:                //the Database after the update are stored. This
0911:                //array is then checked to determine if it
0912:                //has the same elements of the Byte array used for
0913:                //the update operation
0914:
0915:                byte[] bytes_ret = new byte[10];
0916:
0917:                //1 Input Stream for insertion
0918:                InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
0919:
0920:                //2 Input Stream for insertion
0921:                InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);
0922:
0923:                //Prepared Statement used to insert the data
0924:                PreparedStatement ps_sb = prep("dClob");
0925:
0926:                //first insert
0927:                ps_sb.setInt(1, key);
0928:                ps_sb.setAsciiStream(2, is1, BYTES1.length);
0929:                ps_sb.executeUpdate();
0930:
0931:                //second insert
0932:                int key2 = requestKey();
0933:                ps_sb.setInt(1, key2);
0934:                ps_sb.setAsciiStream(2, is2, BYTES2.length);
0935:                ps_sb.executeUpdate();
0936:
0937:                ps_sb.close();
0938:
0939:                //Update operation
0940:                //use a different ResultSet variable so that the
0941:                //other tests can go on unimpacted
0942:                //we do not have set methods on Clob and Blob implemented
0943:                //So query the first Clob from the database
0944:                //update the second result set with this
0945:                //Clob value
0946:
0947:                ResultSet rs1 = fetchUpd("dClob", key);
0948:                rs1.next();
0949:                Clob clob = rs1.getClob(1);
0950:                rs1.close();
0951:
0952:                rs1 = fetchUpd("dClob", key2);
0953:                rs1.next();
0954:                rs1.updateClob(1, clob);
0955:                rs1.updateRow();
0956:                rs1.close();
0957:
0958:                //Query to see whether the data that has been updated
0959:                //using the updateClob method is the same
0960:                //data that we expected
0961:
0962:                rs1 = fetch("dClob", key2);
0963:                rs1.next();
0964:                assertEquals(clob, rs1.getClob(1));
0965:                rs1.close();
0966:            }
0967:
0968:            public void testUpdateClobLengthless() throws Exception {
0969:                Reader r1 = new java.io.StringReader(new String(BYTES1));
0970:                // InputStream for insertion.
0971:                Reader r2 = new java.io.StringReader(new String(BYTES2));
0972:
0973:                // Prepared Statement used to insert the data
0974:                PreparedStatement ps_sb = prep("dClob");
0975:                ps_sb.setInt(1, key);
0976:                ps_sb.setCharacterStream(2, r1);
0977:                ps_sb.executeUpdate();
0978:                ps_sb.close();
0979:
0980:                // Update operation
0981:                ResultSet rs1 = fetchUpd("dClob", key);
0982:                rs1.next();
0983:                rs1.updateClob(1, r2);
0984:                rs1.updateRow();
0985:                rs1.close();
0986:
0987:                // Query to see whether the data that has been updated.
0988:                rs1 = fetch("dClob", key);
0989:                rs1.next();
0990:                assertEquals(new StringReader(new String(BYTES2)), rs1
0991:                        .getCharacterStream(1));
0992:                rs1.close();
0993:            }
0994:
0995:            /**
0996:             * This methods tests the ResultSet interface method
0997:             * updateBlob
0998:             *
0999:             * @throws SQLException if some error occurs while calling the method
1000:             */
1001:            public void embeddedUpdateBlob() throws Exception {
1002:                //Byte array in which the returned bytes from
1003:                //the Database after the update are stored. This
1004:                //array is then checked to determine if it
1005:                //has the same elements of the Byte array used for
1006:                //the update operation
1007:
1008:                byte[] bytes_ret = new byte[10];
1009:
1010:                //1 Input Stream for insertion
1011:                InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
1012:
1013:                //2 Input Stream for insertion
1014:                InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);
1015:
1016:                //Prepared Statement used to insert the data
1017:                PreparedStatement ps_sb = prep("dBlob");
1018:
1019:                //first insert
1020:                ps_sb.setInt(1, key);
1021:                ps_sb.setBinaryStream(2, is1, BYTES1.length);
1022:                ps_sb.executeUpdate();
1023:
1024:                //second insert
1025:                int key2 = requestKey();
1026:                ps_sb.setInt(1, key2);
1027:                ps_sb.setBinaryStream(2, is2, BYTES2.length);
1028:                ps_sb.executeUpdate();
1029:
1030:                ps_sb.close();
1031:
1032:                //Update operation
1033:                //use a different ResultSet variable so that the
1034:                //other tests can go on unimpacted
1035:                //we do not have set methods on Clob and Blob implemented
1036:                //So query the first Clob from the database
1037:                //update the second result set with this
1038:                //Clob value
1039:
1040:                ResultSet rs1 = fetch("dBlob", key);
1041:                rs1.next();
1042:                Blob blob = rs1.getBlob(1);
1043:                rs1.close();
1044:
1045:                rs1 = fetchUpd("dBlob", key2);
1046:                rs1.next();
1047:                rs1.updateBlob(1, blob);
1048:                rs1.updateRow();
1049:                rs1.close();
1050:
1051:                //Query to see whether the data that has been updated
1052:                //using the updateBlob method is the same
1053:                //data that we expected
1054:
1055:                rs1 = fetch("dBlob", key2);
1056:                rs1.next();
1057:                assertEquals(blob, rs1.getBlob(1));
1058:                rs1.close();
1059:            }
1060:
1061:            public void testUpdateBlobLengthless() throws Exception {
1062:                InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
1063:                // InputStream for insertion.
1064:                InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);
1065:
1066:                // Prepared Statement used to insert the data
1067:                PreparedStatement ps_sb = prep("dBlob");
1068:                ps_sb.setInt(1, key);
1069:                ps_sb.setBinaryStream(2, is1);
1070:                ps_sb.executeUpdate();
1071:                ps_sb.close();
1072:
1073:                // Update operation
1074:                ResultSet rs1 = fetchUpd("dBlob", key);
1075:                rs1.next();
1076:                rs1.updateBlob(1, is2);
1077:                rs1.updateRow();
1078:                rs1.close();
1079:
1080:                // Query to see whether the data that has been updated.
1081:                rs1 = fetch("dBlob", key);
1082:                rs1.next();
1083:                assertEquals(new ByteArrayInputStream(BYTES2), rs1
1084:                        .getBinaryStream(1));
1085:                rs1.close();
1086:            }
1087:
1088:            /**
1089:             * This methods tests the ResultSet interface method
1090:             * updateClob
1091:             *
1092:             * @throws SQLException if some error occurs while calling the method
1093:             */
1094:            public void embeddedUpdateClobStringParameterName()
1095:                    throws Exception {
1096:                //Byte array in which the returned bytes from
1097:                //the Database after the update are stored. This
1098:                //array is then checked to determine if it
1099:                //has the same elements of the Byte array used for
1100:                //the update operation
1101:
1102:                byte[] bytes_ret = new byte[10];
1103:
1104:                //1 Input Stream for insertion
1105:                InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
1106:
1107:                //2 Input Stream for insertion
1108:                InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);
1109:
1110:                //Prepared Statement used to insert the data
1111:                PreparedStatement ps_sb = prep("dClob");
1112:
1113:                //first insert
1114:                ps_sb.setInt(1, key);
1115:                ps_sb.setAsciiStream(2, is1, BYTES1.length);
1116:                ps_sb.executeUpdate();
1117:
1118:                //second insert
1119:                int key2 = requestKey();
1120:                ps_sb.setInt(1, key2);
1121:                ps_sb.setAsciiStream(2, is2, BYTES2.length);
1122:                ps_sb.executeUpdate();
1123:
1124:                ps_sb.close();
1125:
1126:                //Update operation
1127:                //use a different ResultSet variable so that the
1128:                //other tests can go on unimpacted
1129:                //we do not have set methods on Clob and Blob implemented
1130:                //So query the first Clob from the database
1131:                //update the second result set with this
1132:                //Clob value
1133:
1134:                ResultSet rs1 = fetch("dClob", key);
1135:                rs1.next();
1136:                Clob clob = rs1.getClob(1);
1137:                rs1.close();
1138:
1139:                rs1 = fetchUpd("dClob", key2);
1140:                rs1.next();
1141:                rs1.updateClob("dClob", clob);
1142:                rs1.updateRow();
1143:                rs1.close();
1144:
1145:                //Query to see whether the data that has been updated
1146:                //using the updateClob method is the same
1147:                //data that we expected
1148:
1149:                rs1 = fetch("dClob", key2);
1150:                rs1.next();
1151:                assertEquals(clob, rs1.getClob(1));
1152:                rs1.close();
1153:            }
1154:
1155:            public void testUpdateClobLengthlessParameterName()
1156:                    throws Exception {
1157:                Reader r1 = new java.io.StringReader(new String(BYTES1));
1158:                // InputStream for insertion.
1159:                Reader r2 = new java.io.StringReader(new String(BYTES2));
1160:
1161:                // Prepared Statement used to insert the data
1162:                PreparedStatement ps_sb = prep("dClob");
1163:                ps_sb.setInt(1, key);
1164:                ps_sb.setCharacterStream(2, r1);
1165:                ps_sb.executeUpdate();
1166:                ps_sb.close();
1167:
1168:                // Update operation
1169:                ResultSet rs1 = fetchUpd("dClob", key);
1170:                rs1.next();
1171:                rs1.updateClob("dClob", r2);
1172:                rs1.updateRow();
1173:                rs1.close();
1174:
1175:                // Query to see whether the data that has been updated.
1176:                rs1 = fetch("dClob", key);
1177:                rs1.next();
1178:                assertEquals(new StringReader(new String(BYTES2)), rs1
1179:                        .getCharacterStream(1));
1180:                rs1.close();
1181:            }
1182:
1183:            /**
1184:             * This methods tests the ResultSet interface method
1185:             * updateBlob
1186:             *
1187:             * @throws SQLException if some error occurs while calling the method
1188:             */
1189:            public void embeddedUpdateBlobStringParameterName()
1190:                    throws Exception {
1191:                //Byte array in which the returned bytes from
1192:                //the Database after the update are stored. This
1193:                //array is then checked to determine if it
1194:                //has the same elements of the Byte array used for
1195:                //the update operation
1196:
1197:                byte[] bytes_ret = new byte[10];
1198:
1199:                //1 Input Stream for insertion
1200:                InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
1201:
1202:                //2 Input Stream for insertion
1203:                InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);
1204:
1205:                //Prepared Statement used to insert the data
1206:                PreparedStatement ps_sb = prep("dBlob");
1207:
1208:                //first insert
1209:                ps_sb.setInt(1, key);
1210:                ps_sb.setBinaryStream(2, is1, BYTES1.length);
1211:                ps_sb.executeUpdate();
1212:
1213:                //second insert
1214:                int key2 = requestKey();
1215:                ps_sb.setInt(1, key2);
1216:                ps_sb.setBinaryStream(2, is2, BYTES2.length);
1217:                ps_sb.executeUpdate();
1218:
1219:                ps_sb.close();
1220:
1221:                //Update operation
1222:                //use a different ResultSet variable so that the
1223:                //other tests can go on unimpacted
1224:                //we do not have set methods on Clob and Blob implemented
1225:                //So query the first Clob from the database
1226:                //update the second result set with this
1227:                //Clob value
1228:
1229:                ResultSet rs1 = fetch("dBlob", key);
1230:                rs1.next();
1231:                Blob blob = rs1.getBlob(1);
1232:                rs1.close();
1233:
1234:                rs1 = fetchUpd("dBlob", key2);
1235:                rs1.next();
1236:                rs1.updateBlob("dBlob", blob);
1237:                rs1.updateRow();
1238:                rs1.close();
1239:
1240:                //Query to see whether the data that has been updated
1241:                //using the updateBlob method is the same
1242:                //data that we expected
1243:
1244:                rs1 = fetch("dBlob", key2);
1245:                rs1.next();
1246:                assertEquals(blob, rs1.getBlob(1));
1247:                rs1.close();
1248:            }
1249:
1250:            public void testUpdateBlobWithStreamLengthlessParameterName()
1251:                    throws Exception {
1252:                InputStream is1 = new java.io.ByteArrayInputStream(BYTES1);
1253:                // InputStream for insertion.
1254:                InputStream is2 = new java.io.ByteArrayInputStream(BYTES2);
1255:
1256:                // Prepared Statement used to insert the data
1257:                PreparedStatement ps_sb = prep("dBlob");
1258:                ps_sb.setInt(1, key);
1259:                ps_sb.setBinaryStream(2, is1);
1260:                ps_sb.executeUpdate();
1261:                ps_sb.close();
1262:
1263:                // Update operation
1264:                ResultSet rs1 = fetchUpd("dBlob", key);
1265:                rs1.next();
1266:                rs1.updateBlob("dBlob", is2);
1267:                rs1.updateRow();
1268:                rs1.close();
1269:
1270:                // Query to see whether the data that has been updated.
1271:                rs1 = fetch("dBlob", key);
1272:                rs1.next();
1273:                assertEquals(new ByteArrayInputStream(BYTES2), rs1
1274:                        .getBinaryStream(1));
1275:                rs1.close();
1276:            }
1277:
1278:            /************************************************************************
1279:             **                        T E S T  S E T U P                           *
1280:             ************************************************************************/
1281:
1282:            /**
1283:             * Create suite containing client-only tests.
1284:             */
1285:            private static TestSuite clientSuite(String name) {
1286:                TestSuite clientSuite = new TestSuite(name);
1287:                return clientSuite;
1288:            }
1289:
1290:            /**
1291:             * Create suite containing embedded-only tests.
1292:             */
1293:            private static TestSuite embeddedSuite(String name) {
1294:                TestSuite embeddedSuite = new TestSuite(name);
1295:                embeddedSuite.addTest(new ResultSetTest("embeddedUpdateBlob"));
1296:                embeddedSuite.addTest(new ResultSetTest("embeddedUpdateClob"));
1297:                embeddedSuite.addTest(new ResultSetTest(
1298:                        "embeddedUpdateClobStringParameterName"));
1299:                return embeddedSuite;
1300:            }
1301:
1302:            public static Test suite() {
1303:                TestSuite rsSuite = new TestSuite(ResultSetTest.class,
1304:                        "ResultSetTest suite");
1305:                // Add client only tests
1306:                // NOTE: JCC is excluded
1307:                if (usingDerbyNetClient()) {
1308:                    rsSuite
1309:                            .addTest(clientSuite("ResultSetTest client-only suite"));
1310:                }
1311:                // Add embedded only tests
1312:                if (usingEmbedded()) {
1313:                    rsSuite
1314:                            .addTest(embeddedSuite("ResultSetTest embedded-only suite"));
1315:                }
1316:                // Wrap suite in a TestSetup-class.
1317:                return new BaseJDBCTestSetup(rsSuite) {
1318:                    protected void setUp() throws SQLException {
1319:                        Connection con = getConnection();
1320:                        Statement stmt = con.createStatement();
1321:                        stmt.execute("create table UpdateTestTableResultSet ("
1322:                                + "sno int not null unique," + "dBlob BLOB,"
1323:                                + "dClob CLOB," + "dLongVarchar LONG VARCHAR,"
1324:                                + "dLongBit LONG VARCHAR FOR BIT DATA)");
1325:                        stmt.close();
1326:                    }
1327:
1328:                    protected void tearDown() throws Exception {
1329:                        Connection con = getConnection();
1330:                        Statement stmt = con.createStatement();
1331:                        stmt.execute("drop table UpdateTestTableResultSet");
1332:                        stmt.close();
1333:                        super .tearDown();
1334:                    }
1335:                };
1336:            }
1337:
1338:            /*************************************************************************
1339:             **                    U T I L I T Y  M E T H O D S                      *
1340:             *************************************************************************/
1341:
1342:            /**
1343:             * Get a key that is used to identify an inserted row.
1344:             * Introduced to avoid having to delete table contents after each test,
1345:             * and because the order of the tests is not guaranteed.
1346:             *
1347:             * @return an integer in range [1, Integer.MAX_VALUE -1]
1348:             */
1349:            private static final int requestKey() {
1350:                return ++insertKey;
1351:            }
1352:
1353:            /**
1354:             * Prepare commonly used statement to insert a row.
1355:             *
1356:             * @param con connection to database
1357:             * @param colName name of the column to insert into
1358:             */
1359:            private PreparedStatement prep(String colName) throws SQLException {
1360:                return prepareStatement("insert into UpdateTestTableResultSet "
1361:                        + "(sno, " + colName + ") values (?,?)");
1362:            }
1363:
1364:            /**
1365:             * Fetch the specified row for update.
1366:             *
1367:             * @param con connection to database
1368:             * @param colName name of the column to fetch
1369:             * @param key identifier for row to fetch
1370:             * @return a <code>ResultSet</code> with zero or one row, depending on
1371:             *      the key used
1372:             */
1373:            private ResultSet fetchUpd(String colName, int key)
1374:                    throws SQLException {
1375:                Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY,
1376:                        ResultSet.CONCUR_UPDATABLE);
1377:                return stmt.executeQuery("select " + colName
1378:                        + " from UpdateTestTableResultSet where sno = " + key
1379:                        + " for update");
1380:            }
1381:
1382:            /**
1383:             * Fetch the specified row.
1384:             *
1385:             * @param con connection to database
1386:             * @param colName name of the column to fetch
1387:             * @param key identifier for row to fetch
1388:             * @return a <code>ResultSet</code> with zero or one row, depending on
1389:             *      the key used
1390:             */
1391:            private ResultSet fetch(String colName, int key)
1392:                    throws SQLException {
1393:                Statement stmt = createStatement();
1394:                return stmt.executeQuery("select " + colName
1395:                        + " from UpdateTestTableResultSet where sno = " + key);
1396:            }
1397:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.