Source Code Cross Referenced for statementJdbc20.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.statementJdbc20
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.Connection;
025:        import java.sql.DriverManager;
026:        import java.sql.ResultSetMetaData;
027:        import java.sql.ResultSet;
028:        import java.sql.Statement;
029:        import java.sql.SQLException;
030:        import java.sql.Types;
031:
032:        import org.apache.derby.tools.ij;
033:        import org.apache.derby.tools.JDBCDisplayUtil;
034:
035:        /**
036:         * Test of additional methods in JDBC2.0  methods in statement and 
037:         * resultset classes.
038:         *
039:         */
040:
041:        public class statementJdbc20 {
042:
043:            public static void main(String[] args) {
044:                Connection con;
045:                ResultSet rs;
046:                Statement stmt;
047:
048:                System.out.println("Test statementJdbc20 starting");
049:
050:                try {
051:                    // use the ij utility to read the property file and
052:                    // make the initial connection.
053:                    ij.getPropertyArg(args);
054:                    con = ij.startJBMS();
055:
056:                    stmt = con.createStatement();
057:
058:                    //create a table, insert a row, do a select from the table,
059:                    stmt
060:                            .execute("create table tab1 (i int, s smallint, r real)");
061:                    stmt.executeUpdate("insert into tab1 values(1, 2, 3.1)");
062:
063:                    // set all the peformance hint parameters
064:                    stmt.setFetchSize(25);
065:                    stmt.setFetchDirection(ResultSet.FETCH_REVERSE);
066:                    stmt.setEscapeProcessing(true);
067:
068:                    //Error  testing  : set wrong values ..
069:                    try {
070:                        stmt.setFetchSize(-1000);
071:                    } catch (SQLException e) {
072:                        dumpExpectedSQLExceptions(e);
073:                    }
074:
075:                    try {
076:                        stmt.setFetchDirection(-1000);
077:                    } catch (SQLException e) {
078:                        dumpExpectedSQLExceptions(e);
079:                    }
080:
081:                    System.out.println("Fetch Size " + stmt.getFetchSize());
082:                    System.out.println("Fetch Direction "
083:                            + stmt.getFetchDirection());
084:
085:                    // read the data just for the heck of it 
086:                    rs = stmt.executeQuery("select * from tab1");
087:                    while (rs.next()) {
088:                        System.out.println(rs.getInt(1) + " " + rs.getShort(2)
089:                                + " " + rs.getFloat(3));
090:                    }
091:
092:                    // Get the constatnts for a result set            
093:                    System.out.println("Result Set Fetch Size "
094:                            + rs.getFetchSize());
095:                    System.out.println("Result Set Fetch Direction "
096:                            + rs.getFetchDirection());
097:
098:                    // change values local to result set and get them back
099:                    rs.setFetchSize(250);
100:                    try {
101:                        rs.setFetchDirection(ResultSet.FETCH_FORWARD);
102:                    } catch (SQLException e) {
103:                        dumpExpectedSQLExceptions(e);
104:                    }
105:
106:                    System.out.println("Result Set Fetch Size "
107:                            + rs.getFetchSize());
108:                    System.out.println("Result Set Fetch Direction "
109:                            + rs.getFetchDirection());
110:
111:                    // exception conditions 
112:                    stmt.setMaxRows(10);
113:                    try {
114:                        rs.setFetchSize(100);
115:                    } catch (SQLException e) {
116:                        dumpExpectedSQLExceptions(e);
117:                    }
118:
119:                    //Error  testing  : set wrong values ..
120:                    try {
121:                        rs.setFetchSize(-2000);
122:                    } catch (SQLException e) {
123:                        dumpExpectedSQLExceptions(e);
124:                    }
125:
126:                    try {
127:                        rs.setFetchDirection(-2000);
128:                    } catch (SQLException e) {
129:                        dumpExpectedSQLExceptions(e);
130:                    }
131:
132:                    // set the fetch size values to zero .. to ensure 
133:                    // error condtions are correct !
134:
135:                    rs.setFetchSize(0);
136:                    stmt.setFetchSize(0);
137:
138:                    rs.close();
139:
140:                    //RESOLVE - uncomment tests in 3.5
141:                    // executeQuery() not allowed on statements
142:                    // that return a row count
143:                    try {
144:                        stmt.executeQuery("create table trash(c1 int)");
145:                    } catch (SQLException e) {
146:                        dumpExpectedSQLExceptions(e);
147:                    }
148:
149:                    // verify that table was not created
150:                    try {
151:                        rs = stmt.executeQuery("select * from trash");
152:                        System.out
153:                                .println("select from trash expected to fail");
154:                    } catch (SQLException e) {
155:                        dumpExpectedSQLExceptions(e);
156:                    }
157:
158:                    // executeUpdate() not allowed on statements
159:                    // that return a ResultSet
160:                    try {
161:                        stmt.executeUpdate("values 1");
162:                    } catch (SQLException e) {
163:                        dumpExpectedSQLExceptions(e);
164:                    }
165:
166:                    stmt.close();
167:                    con.close();
168:
169:                } catch (SQLException e) {
170:                    dumpSQLExceptions(e);
171:                    e.printStackTrace();
172:                } catch (Throwable e) {
173:                    System.out.println("FAIL -- unexpected exception: " + e);
174:                    e.printStackTrace();
175:                }
176:
177:                System.out.println("Test statementJdbc20 finished");
178:            }
179:
180:            static private void dumpSQLExceptions(SQLException se) {
181:                System.out.println("FAIL -- unexpected exception");
182:                while (se != null) {
183:                    System.out.println("SQLSTATE(" + se.getSQLState() + "): "
184:                            + se);
185:                    se = se.getNextException();
186:                }
187:            }
188:
189:            static private void dumpExpectedSQLExceptions(SQLException se) {
190:                System.out.println("PASS -- expected exception");
191:                while (se != null) {
192:                    System.out.println("SQLSTATE(" + se.getSQLState() + "): "
193:                            + se);
194:                    se = se.getNextException();
195:                }
196:            }
197:
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.