Source Code Cross Referenced for TestJDBC40Exception.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) 


001:        /*
002:         
003:           Derby - Class 
004:                org.apache.derbyTesting.functionTests.tests.jdbc4.TestJDBC40Exception
005:         
006:           Licensed to the Apache Software Foundation (ASF) under one or more
007:           contributor license agreements.  See the NOTICE file distributed with
008:           this work for additional information regarding copyright ownership.
009:           The ASF licenses this file to you under the Apache License, Version 2.0
010:           (the "License"); you may not use this file except in compliance with
011:           the License.  You may obtain a copy of the License at
012:         
013:              http://www.apache.org/licenses/LICENSE-2.0
014:         
015:           Unless required by applicable law or agreed to in writing, software
016:           distributed under the License is distributed on an "AS IS" BASIS,
017:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018:           See the License for the specific language governing permissions and
019:           limitations under the License.
020:         
021:         */
022:
023:        package org.apache.derbyTesting.functionTests.tests.jdbc4;
024:
025:        import java.sql.Connection;
026:        import java.sql.Statement;
027:        import java.sql.SQLDataException;
028:        import java.sql.SQLException;
029:        import java.sql.SQLIntegrityConstraintViolationException;
030:        import java.sql.SQLSyntaxErrorException;
031:        import java.sql.SQLTransientConnectionException;
032:        import java.sql.SQLTransactionRollbackException;
033:        import junit.framework.Test;
034:        import junit.framework.TestResult;
035:        import junit.framework.TestSuite;
036:        import org.apache.derby.tools.ij;
037:        import org.apache.derbyTesting.functionTests.tests.derbynet.testconnection;
038:
039:        public class TestJDBC40Exception {
040:
041:            private static final String EXCEPTION_TABLE1 = "EXCEPTION_TABLE1";
042:
043:            private static String[] _startupArgs;
044:
045:            public TestJDBC40Exception() {
046:            }
047:
048:            /*
049:             * Stub methods to be removed after 623 is fixed and test is 
050:             * moved to use junit
051:             */
052:            private Connection getConnection() throws Exception {
053:                // use the ij utility to read the property file and
054:                // make the initial connection.
055:                ij.getPropertyArg(_startupArgs);
056:
057:                Connection conn_main = ij.startJBMS();
058:
059:                return conn_main;
060:            }
061:
062:            /*
063:             * Stub methods to be removed after 623 is fixed and test is 
064:             * moved to use junit
065:             */
066:            private void close(Connection conn) throws SQLException {
067:                conn.close();
068:            }
069:
070:            /*
071:             * Stub methods to be removed after 623 is fixed and test is 
072:             * moved to use junit
073:             */
074:            private void execute(Connection conn, String sql)
075:                    throws SQLException {
076:                Statement stmt = conn.createStatement();
077:                stmt.execute(sql);
078:                stmt.close();
079:            }
080:
081:            public static Test suite() {
082:                TestSuite testSuite = new TestSuite();
083:                testSuite.addTestSuite(TestJDBC40Exception.class);
084:                return testSuite;
085:            }
086:
087:            public void testException() throws Exception {
088:                Connection conn = getConnection();
089:                execute(conn, "create table " + EXCEPTION_TABLE1
090:                        + "(id integer " + "primary key, data varchar (5))");
091:                execute(conn, "insert into " + EXCEPTION_TABLE1 + "(id, data)"
092:                        + "values (1, 'data1')");
093:                close(conn);
094:                checkDataException();
095:                checkIntegrityConstraintViolationException();
096:                checkSyntaxErrorException();
097:                checkConnectionException();
098:                checkTimeout();
099:            }
100:
101:            private void checkIntegrityConstraintViolationException()
102:                    throws Exception {
103:                Connection conn = getConnection();
104:                try {
105:                    execute(conn, "insert into " + EXCEPTION_TABLE1
106:                            + "(id, data)" + "values (1, 'data1')");
107:                } catch (SQLIntegrityConstraintViolationException e) {
108:                    if (!e.getSQLState().startsWith("23"))
109:                        System.out.println("Unexpected SQL State"
110:                                + e.getSQLState());
111:                }
112:            }
113:
114:            private void checkDataException() throws Exception {
115:                Connection conn = getConnection();
116:                try {
117:                    execute(conn, "insert into " + EXCEPTION_TABLE1
118:                            + "(id, data)" + "values (2, 'data1234556')");
119:                } catch (SQLDataException e) {
120:                    if (!e.getSQLState().startsWith("22"))
121:                        System.out.println("Unexpected SQL State"
122:                                + e.getSQLState());
123:                }
124:            }
125:
126:            private void checkConnectionException() throws Exception {
127:                Statement stmt = null;
128:                Connection con = null;
129:                try {
130:                    con = getConnection();
131:                    stmt = con.createStatement();
132:                    con.close();
133:                    stmt.execute("select * from exception1");
134:                } catch (SQLTransientConnectionException cone) {
135:                    if (!cone.getSQLState().startsWith("08"))
136:                        System.out.println("Unexpected SQL State"
137:                                + cone.getSQLState());
138:                }
139:            }
140:
141:            private void checkSyntaxErrorException() throws Exception {
142:                Connection conn = getConnection();
143:                try {
144:                    execute(conn, "insert into " + EXCEPTION_TABLE1
145:                            + "(id, data)" + "values ('2', 'data1')");
146:                } catch (SQLSyntaxErrorException e) {
147:                    if (!e.getSQLState().startsWith("42"))
148:                        System.out.println("Unexpected SQL State"
149:                                + e.getSQLState());
150:                }
151:            }
152:
153:            private void checkTimeout() throws Exception {
154:                Connection con1 = getConnection();
155:                Connection con2 = getConnection();
156:                try {
157:                    con1.setAutoCommit(false);
158:                    con2.setAutoCommit(false);
159:                    con1
160:                            .setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
161:                    con2
162:                            .setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
163:                    execute(con1, "select * from " + EXCEPTION_TABLE1
164:                            + " for update");
165:                    execute(con2, "select * from " + EXCEPTION_TABLE1
166:                            + " for update");
167:                } catch (SQLTransactionRollbackException e) {
168:                    if (!e.getSQLState().startsWith("40"))
169:                        System.out.println("Unexpected SQL State"
170:                                + e.getSQLState());
171:                }
172:            }
173:
174:            public static void main(String[] args) throws Exception {
175:                TestJDBC40Exception test = new TestJDBC40Exception();
176:
177:                _startupArgs = args;
178:                test.testException();
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.