001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.badConnection
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: package org.apache.derbyTesting.functionTests.tests.derbynet;
022:
023: import java.sql.*;
024: import java.util.Vector;
025: import java.util.Properties;
026: import java.io.File;
027:
028: import java.io.BufferedOutputStream;
029: import org.apache.derbyTesting.functionTests.harness.TimedProcess;
030: import org.apache.derbyTesting.functionTests.util.TestUtil;
031:
032: /**
033: This tests various bad connection states
034: - non-existant database
035: */
036:
037: public class badConnection {
038:
039: private static Properties properties = new java.util.Properties();
040:
041: private static String dbNotFoundDB = "notthere";
042: private static String invalidAttrDB = "testbase;upgrade=notValidValue";
043: private static String derbynetDB = "testbase";
044:
045: private static Connection newConn(String database,
046: Properties properties) throws Exception {
047: Connection conn = null;
048: String databaseURL = TestUtil.getJdbcUrlPrefix() + database;
049: //System.out.println("URL is: " + databaseURL);
050:
051: try {
052: conn = DriverManager.getConnection(databaseURL, properties);
053: if (conn == null)
054: System.out.println("create connection didn't work");
055: else
056: System.out.println("Connection made\n");
057:
058: } catch (SQLException se) {
059: showSQLException(se);
060: }
061:
062: return conn;
063: }
064:
065: private static void showSQLException(SQLException e) {
066: System.out
067: .println("passed SQLException all the way to client, then thrown by client...");
068: System.out.println("SQLState is: " + e.getSQLState());
069: System.out.println("vendorCode is: " + e.getErrorCode());
070: System.out.println("nextException is: " + e.getNextException());
071: System.out.println("reason is: " + e.getMessage() + "\n\n");
072: }
073:
074: public static void main(String args[]) throws Exception {
075:
076: try {
077: TestUtil.loadDriver();
078: System.out.println("No user/password (Client error)");
079: Connection conn1 = newConn(derbynetDB, properties);
080:
081: System.out.println("Database not Found (RDBNFNRM)");
082: properties.put("user", "admin");
083: properties.put("password", "admin");
084: conn1 = newConn(dbNotFoundDB, properties);
085: if (conn1 != null)
086: conn1.close();
087:
088: System.out.println("Invalid Attribute value (RDBAFLRM)");
089: conn1 = newConn(invalidAttrDB, properties);
090: if (conn1 != null)
091: conn1.close();
092:
093: } catch (SQLException se) {
094: showSQLException(se);
095: } catch (Exception e) {
096: e.printStackTrace();
097: }
098: }
099:
100: }
|