01: /*
02:
03: Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.TestEnc
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to You under the Apache License, Version 2.0
09: (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;
24: import java.sql.Connection;
25: import java.sql.SQLException;
26: import java.sql.Statement;
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 out;
39:
40: public static void main(String args[]) throws Exception {
41: new TestEnc().go(args);
42: }
43:
44: public void go(String[] args) throws Exception {
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 conn = ij.startJBMS();
51:
52: conn.setAutoCommit(true);
53: Statement 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 e) {
62: if (e.getSQLState().equals("42X01")) {
63: System.out.println("Message " + e.getMessage());
64: } else
65: handleSQLException("DERBY-583", e, false);
66: } finally {
67: if (stmt != null)
68: stmt.close();
69: }
70: }
71:
72: public void handleSQLException(String method, SQLException e,
73: boolean expected) throws Exception {
74: do {
75: out.print("\t" + method + " \tException " + "SQLSTATE:"
76: + e.getSQLState());
77: if (expected)
78: out.println(" (EXPECTED)");
79: else
80: e.printStackTrace(out);
81: e = e.getNextException();
82: } while (e != null);
83:
84: }
85: }
|