This is an example of how to use the Connection property in SQL naming mode.
//////////////////////////////////////////////////////////////////////////////////
//
// InvalidConnect example.
//
// This program uses the Connection property in SQL naming mode.
//
//////////////////////////////////////////////////////////////////////////////////
//
// This source is an example of the IBM Developer for Java JDBC driver.
// IBM grants you a nonexclusive license to use this as an example
// from which you can generate similar function tailored to
// your own specific needs.
//
// This sample code is provided by IBM for illustrative purposes
// only. These examples have not been thoroughly tested under all
// conditions. IBM, therefore, cannot guarantee or imply
// reliability, serviceability, or function of these programs.
//
// All programs contained herein are provided to you "AS IS"
// without any warranties of any kind. The implied warranties of
// merchantability and fitness for a particular purpose are
// expressly disclaimed.
//
// IBM Developer Kit for Java
// (C) Copyright IBM Corp. 2001
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
//
//////////////////////////////////////////////////////////////////////////////////
import java.sql.*;
import java.util.*;
public class InvalidConnect {
public static void main(java.lang.String[] args)
{
// Register the driver.
try {
Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
} catch (ClassNotFoundException cnf) {
System.out.println("ERROR: JDBC driver did not load.");
System.exit(0);
}
// Attempt to obtain a connection without specifying any user or
// password. The attempt works and the connection uses the
// same user profile under which the job is running.
try {
Connection c1 = DriverManager.getConnection("jdbc:db2:*local");
c1.close();
} catch (SQLException e) {
System.out.println("This test should not get into this exception path.");
e.printStackTrace();
System.exit(1);
}
try {
Connection c2 = DriverManager.getConnection("jdbc:db2:*local",
"notvalid", "notvalid");
} catch (SQLException e) {
System.out.println("This is an expected error.");
System.out.println("Message is " + e.getMessage());
System.out.println("SQLSTATE is " + e.getSQLState());
}
}
}