KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > derbynet > TestEnc


1 /*
2
3 Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.TestEnc
4
5 Licensed to the Apache Software Foundation (ASF) under one or more
6 contributor license agreements. See the NOTICE file distributed with
7 this work for additional information regarding copyright ownership.
8 The ASF licenses this file to You under the Apache License, Version 2.0
9 (the "License"); you may not use this file except in compliance with
10 the License. You may obtain a copy of the License at
11
12    http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19
20 */

21 package org.apache.derbyTesting.functionTests.tests.derbynet;
22
23 import java.io.PrintWriter JavaDoc;
24 import java.sql.Connection JavaDoc;
25 import java.sql.SQLException JavaDoc;
26 import java.sql.Statement JavaDoc;
27
28 import org.apache.derby.tools.ij;
29
30 /**
31  * This test is part of the encodingTests suite and has regression testcases that
32  * have caused problems because of usage of non-portable methods, constructors like
33  * String(byte[]) etc. These problems were noticed on Z/OS but can be reproduced
34  * when server and client are running with different native encoding
35  */

36 public class TestEnc {
37     
38     private PrintWriter JavaDoc out;
39     
40     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
41         new TestEnc().go(args);
42     }
43     
44     public void go(String JavaDoc[] args) throws Exception JavaDoc {
45         
46         // Load the JDBC Driver class
47
// use the ij utility to read the property file and
48
// make the initial connection.
49
ij.getPropertyArg(args);
50         Connection JavaDoc conn = ij.startJBMS();
51         
52         conn.setAutoCommit(true);
53         Statement JavaDoc stmt = conn.createStatement();
54         
55         // Error messages on z/os were garbled because
56
// of different native encoding on server/client
57
// Related jira issues are
58
// DERBY-583,DERBY-900,DERBY-901,DERBY-902.
59
try {
60             stmt.execute("select bla");
61         } catch (SQLException JavaDoc e) {
62             if (e.getSQLState().equals("42X01")) {
63                 System.out.println("Message "+e.getMessage());
64             }
65             else
66                 handleSQLException("DERBY-583",e,false);
67         }
68         finally {
69             if (stmt != null)
70                 stmt.close();
71         }
72     }
73     
74     public void handleSQLException(String JavaDoc method,
75             SQLException JavaDoc e,
76             boolean expected) throws Exception JavaDoc {
77         do {
78             out.print("\t" + method + " \tException " +
79                     "SQLSTATE:" + e.getSQLState());
80             if (expected)
81                 out.println(" (EXPECTED)");
82             else
83                 e.printStackTrace(out);
84             e = e.getNextException();
85         } while (e != null);
86         
87     }
88 }
89
Popular Tags