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


001:        /*
002:
003:           Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.resultsetJdbc30
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to You under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derbyTesting.functionTests.tests.jdbcapi;
023:
024:        import java.sql.Array;
025:        import java.sql.Connection;
026:        import java.sql.ResultSet;
027:        import java.sql.SQLException;
028:        import java.sql.Statement;
029:
030:        import org.apache.derby.tools.ij;
031:
032:        /**
033:         * Test of additional methods in JDBC3.0 result set
034:         *
035:         */
036:
037:        public class resultsetJdbc30 {
038:            public static void main(String[] args) {
039:                Connection con;
040:                ResultSet rs;
041:                Statement stmt;
042:                String[] columnNames = { "i", "s", "r", "d", "dt", "t", "ts",
043:                        "c", "v", "tn", "dc" };
044:
045:                System.out.println("Test resultsetJdbc30 starting");
046:
047:                try {
048:                    // use the ij utility to read the property file and
049:                    // make the initial connection.
050:                    ij.getPropertyArg(args);
051:                    con = ij.startJBMS();
052:
053:                    stmt = con.createStatement();
054:
055:                    //create a table, insert a row, do a select from the table,
056:                    stmt
057:                            .execute("create table t (i int, s smallint, r real, "
058:                                    + "d double precision, dt date, t time, ts timestamp, "
059:                                    + "c char(10), v varchar(40) not null, dc dec(10,2))");
060:                    stmt
061:                            .execute("insert into t values(1,2,3.3,4.4,date('1990-05-05'),"
062:                                    + "time('12:06:06'),timestamp('1990-07-07 07:07:07.07'),"
063:                                    + "'eight','nine', 11.1)");
064:
065:                    rs = stmt.executeQuery("select * from t");
066:                    rs.next();
067:
068:                    //following will give not implemented exceptions.
069:                    try {
070:                        System.out.println();
071:                        System.out.println("trying rs.getURL(int) :");
072:                        rs.getURL(8);
073:                        System.out
074:                                .println("Shouldn't reach here. Method not implemented yet.");
075:                    } catch (SQLException ex) {
076:                        System.out.println("Expected : " + ex.getMessage());
077:                    }
078:
079:                    try {
080:                        System.out.println();
081:                        System.out.println("trying rs.getURL(String) :");
082:                        rs.getURL("c");
083:                        System.out
084:                                .println("Shouldn't reach here. Method not implemented yet.");
085:                    } catch (SQLException ex) {
086:                        System.out.println("Expected : " + ex.getMessage());
087:                    }
088:
089:                    try {
090:                        System.out.println();
091:                        System.out.println("trying rs.updateRef(int, Ref) :");
092:                        rs.updateRef(8, null);
093:                        System.out
094:                                .println("Shouldn't reach here. Method not implemented yet.");
095:                    } catch (NoSuchMethodError nsme) {
096:                        System.out
097:                                .println("ResultSet.updateRef not present - correct for JSR169");
098:                    } catch (SQLException ex) {
099:                        System.out.println("Expected : " + ex.getMessage());
100:                    }
101:
102:                    try {
103:                        System.out.println();
104:                        System.out
105:                                .println("trying rs.updateRef(String, Ref) :");
106:                        rs.updateRef("c", null);
107:                        System.out
108:                                .println("Shouldn't reach here. Method not implemented yet.");
109:                    } catch (NoSuchMethodError nsme) {
110:                        System.out
111:                                .println("ResultSet.updateRef not present - correct for JSR169");
112:                    } catch (SQLException ex) {
113:                        System.out.println("Expected : " + ex.getMessage());
114:                    }
115:
116:                    try {
117:                        System.out.println();
118:                        System.out.println("trying rs.updateBlob(int, Blob) :");
119:                        rs.updateBlob(8, null);
120:                        System.out
121:                                .println("Shouldn't reach here because method is being invoked on a read only resultset");
122:                    } catch (SQLException ex) {
123:                        System.out.println("Expected : " + ex.getMessage());
124:                    }
125:
126:                    try {
127:                        System.out.println();
128:                        System.out
129:                                .println("trying rs.updateBlob(String, Blob) :");
130:                        rs.updateBlob("c", null);
131:                        System.out
132:                                .println("Shouldn't reach here because method is being invoked on a read only resultset");
133:                    } catch (SQLException ex) {
134:                        System.out.println("Expected : " + ex.getMessage());
135:                    }
136:
137:                    try {
138:                        System.out.println();
139:                        System.out.println("trying rs.updateClob(int, Clob) :");
140:                        rs.updateClob(8, null);
141:                        System.out
142:                                .println("Shouldn't reach here because method is being invoked on a read only resultset");
143:                    } catch (SQLException ex) {
144:                        System.out.println("Expected : " + ex.getMessage());
145:                    }
146:
147:                    try {
148:                        System.out.println();
149:                        System.out
150:                                .println("trying rs.updateClob(String, Clob) :");
151:                        rs.updateClob("c", null);
152:                        System.out
153:                                .println("Shouldn't reach here because method is being invoked on a read only resultset");
154:                    } catch (SQLException ex) {
155:                        System.out.println("Expected : " + ex.getMessage());
156:                    }
157:
158:                    try {
159:                        System.out.println();
160:                        System.out
161:                                .println("trying rs.updateArray(int, Array) :");
162:                        rs.updateArray(8, null);
163:                        System.out
164:                                .println("Shouldn't reach here. Method not implemented yet.");
165:                    } catch (NoSuchMethodError nsme) {
166:                        System.out
167:                                .println("ResultSet.updateArray not present - correct for JSR169");
168:                    } catch (SQLException ex) {
169:                        System.out.println("Expected : " + ex.getMessage());
170:                    }
171:
172:                    try {
173:                        System.out.println();
174:                        System.out
175:                                .println("trying rs.updateArray(String, Array) :");
176:                        rs.updateArray("c", null);
177:                        System.out
178:                                .println("Shouldn't reach here. Method not implemented yet.");
179:                    } catch (NoSuchMethodError nsme) {
180:                        System.out
181:                                .println("ResultSet.updateArray not present - correct for JSR169");
182:                    } catch (SQLException ex) {
183:                        System.out.println("Expected : " + ex.getMessage());
184:                    }
185:
186:                    rs.close();
187:                    stmt.close();
188:
189:                    //
190:                    // Check our behavior around closing result sets when auto-commit
191:                    // is true.  Test with both holdable and non-holdable result sets
192:                    //
193:                    con.setAutoCommit(true);
194:
195:                    // Create a non-updatable holdable result set, and then try to 
196:                    // update it
197:                    stmt = con.createStatement(
198:                            ResultSet.TYPE_SCROLL_INSENSITIVE,
199:                            ResultSet.CONCUR_READ_ONLY,
200:                            ResultSet.HOLD_CURSORS_OVER_COMMIT);
201:
202:                    rs = stmt.executeQuery("select * from t");
203:                    rs.next();
204:
205:                    checkForCloseOnException(rs, true);
206:
207:                    rs.close();
208:                    stmt.close();
209:
210:                    // Create a non-updatable non-holdable result set, and then try to 
211:                    // update it
212:                    stmt = con.createStatement(
213:                            ResultSet.TYPE_SCROLL_INSENSITIVE,
214:                            ResultSet.CONCUR_READ_ONLY,
215:                            ResultSet.CLOSE_CURSORS_AT_COMMIT);
216:
217:                    rs = stmt.executeQuery("select * from t");
218:                    rs.next();
219:
220:                    checkForCloseOnException(rs, false);
221:
222:                    rs.close();
223:                    stmt.close();
224:                    con.close();
225:
226:                } catch (SQLException e) {
227:                    dumpSQLExceptions(e);
228:                    e.printStackTrace();
229:                } catch (Throwable e) {
230:                    System.out.println("FAIL -- unexpected exception: " + e);
231:                    e.printStackTrace();
232:                }
233:
234:                System.out.println("Test resultsetJdbc30 finished");
235:            }
236:
237:            static private void checkForCloseOnException(ResultSet rs,
238:                    boolean holdable) throws Exception {
239:                try {
240:                    rs.updateBlob("c", null);
241:                    throw new Exception(
242:                            "rs.updateBlob() on a read-only result set"
243:                                    + "should not have succeeded");
244:                } catch (SQLException ex) {
245:                }
246:
247:                try {
248:                    rs.beforeFirst();
249:                    String holdableStr = holdable ? "holdable" : "non-holdable";
250:                    System.out.println(holdableStr
251:                            + " result set was not closed on exception");
252:                } catch (SQLException ex) {
253:                    String state = ex.getSQLState();
254:                    if (state.equals("XCL16")) {
255:                        System.out
256:                                .println("Holdable result set was closed on exception");
257:                    } else {
258:                        throw ex;
259:                    }
260:                }
261:
262:            }
263:
264:            static private void dumpSQLExceptions(SQLException se) {
265:                System.out.println("FAIL -- unexpected exception");
266:                while (se != null) {
267:                    System.out.println("SQLSTATE(" + se.getSQLState() + "): "
268:                            + se);
269:                    se = se.getNextException();
270:                }
271:            }
272:
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.