Source Code Cross Referenced for nullSQLText.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.nullSQLText
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.DatabaseMetaData;
027:        import java.sql.ResultSetMetaData;
028:        import java.sql.PreparedStatement;
029:        import java.sql.Statement;
030:        import java.sql.ResultSet;
031:        import java.sql.SQLException;
032:        import java.sql.Types;
033:
034:        import org.apache.derby.tools.ij;
035:        import org.apache.derbyTesting.functionTests.util.TestUtil;
036:        import org.apache.derbyTesting.functionTests.util.JDBCTestDisplayUtil;
037:
038:        /**
039:         * Test of null strings in prepareStatement and execute 
040:         * result set.  Also test comments in SQL text that is
041:         * passed to an "execute" call.
042:         *
043:         * @author peachey
044:         */
045:
046:        public class nullSQLText {
047:            public static void main(String[] args) {
048:                Connection con;
049:                PreparedStatement ps;
050:                Statement s;
051:                String nullString = null;
052:
053:                System.out.println("Test nullSQLText starting");
054:
055:                try {
056:                    // use the ij utility to read the property file and
057:                    // make the initial connection.
058:                    ij.getPropertyArg(args);
059:                    con = ij.startJBMS();
060:                    con.setAutoCommit(true); // make sure it is true
061:                    s = con.createStatement();
062:
063:                    // Clean-up in case anything was left from previous tests.
064:                    try {
065:                        s.execute("drop table t1");
066:                    } catch (SQLException se) {
067:                    }
068:                    try {
069:                        s.execute("drop procedure za");
070:                    } catch (SQLException se) {
071:                    }
072:
073:                    try {
074:                        // test null String in prepared statement
075:                        System.out
076:                                .println("Test prepareStatement with null argument");
077:                        ps = con.prepareStatement(nullString);
078:                    } catch (SQLException e) {
079:                        System.out.println("FAIL -- expected exception");
080:                        dumpSQLExceptions(e);
081:                    }
082:                    try {
083:                        // test null String in execute statement
084:                        System.out.println("Test execute with null argument");
085:                        s.execute(nullString);
086:                    } catch (SQLException e) {
087:                        System.out.println("FAIL -- expected exception");
088:                        dumpSQLExceptions(e);
089:                    }
090:                    try {
091:                        // test null String in execute query statement
092:                        System.out
093:                                .println("Test executeQuery with null argument");
094:                        s.executeQuery(nullString);
095:                    } catch (SQLException e) {
096:                        System.out.println("FAIL -- expected exception");
097:                        dumpSQLExceptions(e);
098:                    }
099:                    try {
100:                        // test null String in execute update statement
101:                        System.out
102:                                .println("Test executeUpdate with null argument");
103:                        s.executeUpdate(nullString);
104:                    } catch (SQLException e) {
105:                        System.out.println("FAIL -- expected exception");
106:                        dumpSQLExceptions(e);
107:                    }
108:
109:                    // Test comments in statements.
110:                    derby522(s);
111:
112:                    con.close();
113:                } catch (SQLException e) {
114:                    dumpSQLExceptions(e);
115:                    e.printStackTrace(System.out);
116:                } catch (Throwable e) {
117:                    System.out.println("FAIL -- unexpected exception:");
118:                    e.printStackTrace(System.out);
119:                }
120:
121:                System.out.println("Test nullSQLText finished");
122:            }
123:
124:            static private void dumpSQLExceptions(SQLException se) {
125:                while (se != null) {
126:                    JDBCTestDisplayUtil.ShowCommonSQLException(System.out, se);
127:                    se = se.getNextException();
128:                }
129:            }
130:
131:            /* ****
132:             * Derby-522: When a statement with comments at the front
133:             * is passed through to an "execute" call, the client throws
134:             * error X0Y79 ("executeUpdate cannot be called with a statement
135:             * that returns a result set").  The same thing works fine
136:             * against Derby embedded.  This method executes several
137:             * statements that have comments preceding them; with the
138:             * fix for DERBY-522, these should all either pass or
139:             * throw the correct syntax errors (i.e. the client should
140:             * behave the same way as embedded).
141:             */
142:            private static void derby522(Statement st) throws Exception {
143:                System.out.println("Starting test for DERBY-522.");
144:
145:                st.execute("create table t1 (i int)");
146:                st.execute("insert into t1 values 1, 2, 3, 4, 5, 6, 7");
147:                st
148:                        .execute("create procedure za() language java external name "
149:                                + "'org.apache.derbyTesting.functionTests.util.ProcedureTest.zeroArg'"
150:                                + " parameter style java");
151:
152:                // These we expect to fail with syntax errors, as in embedded mode.
153:                testCommentStmt(st, " --", true);
154:                testCommentStmt(st, " -- ", true);
155:                testCommentStmt(st, " -- This is a comment \n --", true);
156:                testCommentStmt(
157:                        st,
158:                        " -- This is a comment\n --And another\n -- Andonemore",
159:                        true);
160:
161:                // These we expect to return valid results for embedded and
162:                // Derby Client (as of DERBY-522 fix); for JCC, these will
163:                // fail.
164:                testCommentStmt(st, " --\nvalues 2, 4, 8", TestUtil
165:                        .isJCCFramework());
166:                testCommentStmt(st,
167:                        " -- This is \n -- \n --3 comments\nvalues 8", TestUtil
168:                                .isJCCFramework());
169:                testCommentStmt(
170:                        st,
171:                        " -- This is a comment\n --And another\n -- Andonemore\nvalues (2,3)",
172:                        TestUtil.isJCCFramework());
173:                testCommentStmt(st, " -- This is a comment\n select i from t1",
174:                        TestUtil.isJCCFramework());
175:                testCommentStmt(st,
176:                        " --singleword\n insert into t1 values (8)", TestUtil
177:                                .isJCCFramework());
178:                testCommentStmt(st, " --singleword\ncall za()", TestUtil
179:                        .isJCCFramework());
180:                testCommentStmt(st, " -- leading comment\n(\nvalues 4, 8)",
181:                        TestUtil.isJCCFramework());
182:                testCommentStmt(st,
183:                        " -- leading comment\n\n(\n\n\rvalues 4, 8)", TestUtil
184:                                .isJCCFramework());
185:
186:                // While we're at it, test comments in the middle and end of the
187:                // statement.  Prior to the patch for DERBY-522, statements
188:                // ending with a comment threw syntax errors; that problem
189:                // was fixed with DERBY-522, as well, so all of these should now
190:                // succeed in all modes (embedded, Derby Client, and JCC).
191:                testCommentStmt(st, "select i from t1 -- This is a comment",
192:                        false);
193:                testCommentStmt(st, "select i from t1\n -- This is a comment",
194:                        false);
195:                testCommentStmt(st, "values 8, 4, 2\n --", false);
196:                testCommentStmt(st,
197:                        "values 8, 4,\n -- middle comment\n2\n -- end", false);
198:                testCommentStmt(st,
199:                        "values 8, 4,\n -- middle comment\n2\n -- end\n", false);
200:
201:                // Clean-up.
202:                try {
203:                    st.execute("drop table t1");
204:                } catch (SQLException se) {
205:                }
206:                try {
207:                    st.execute("drop procedure za");
208:                } catch (SQLException se) {
209:                }
210:
211:                st.close();
212:                System.out.println("DERBY-522 test completed.");
213:            }
214:
215:            /* ****
216:             * Helper method for derby522.
217:             */
218:            private static void testCommentStmt(Statement st, String sql,
219:                    boolean expectError) throws SQLException {
220:
221:                try {
222:
223:                    System.out.println("[ Test Statement ]:\n" + sql);
224:                    st.execute(sql);
225:                    System.out.print("[ Results ]: ");
226:                    ResultSet rs = st.getResultSet();
227:                    if (rs != null) {
228:                        while (rs.next())
229:                            System.out.print(" " + rs.getInt(1));
230:                        System.out.println();
231:                    } else
232:                        System.out.println("(NO RESULT SET)");
233:
234:                } catch (SQLException se) {
235:
236:                    if (expectError)
237:                        System.out.print("[ EXPECTED ERROR ]: ");
238:                    else
239:                        System.out.print("[ FAILED ]: ");
240:                    dumpSQLExceptions(se);
241:
242:                }
243:
244:            }
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.