I'm trying to use the JDBC Universal driver to get a Type 4 connection in a
Java client program running under DB2 V8.2.1 but I keep getting a
"connection refused: connect" message.
I'm running DB2 Personal Edition so I am trying to connect to the database
SQLPROCS on this same machine. I've checked the manual and am imitating the
examples as well as I can but the examples are geared to remote machines,
not the local one, so I strongly suspect that the syntax is somehow
different for local machines. Anyway, here is the relevant code:
/**
* Load the JDBC driver.
*/
public void loadDriver() {
String METHOD_NAME = "loadDriver()";
String JDBC_DRIVER_NAME = "com.ibm.db2.jcc.DB2Driver"; //new Universal
JDBC driver
/* Load the JDBC driver. */
try {
Class.forName(JDBC_DRIVER_NAME).newInstance();
}
catch (Exception excp) {
System.err.println(CLASS_NAME + "." + METHOD_NAME + " - Encountered
error " +
"while attempting to load JDBC driver, " + JDBC_DRIVER_NAME + ".");
excp.printStackTrace();
System.exit(16);
}
}
/**
* Get a connection to the database and set Autocommit.
*/
public void connectToDatabase() {
String METHOD_NAME = "connectToDatabase()";
String DB2_URL = "jdbc:db2:sqlprocs"; //old and new Type 2 URL - works
// String DB2_URL =
"jdbc:db2://localhost/sqlprocs:user=rhino;password=rhino;"; //new Type 4
URL - doesn't work
// String DB2_URL =
"jdbc:db2://127.0.0.1/sqlprocs:user=rhino;password=rhino;"; //new Type 4
URL - doesn't work
boolean AUTOCOMMIT = false;
/* Connect to the database. */
try {
conn01 = DriverManager.getConnection(DB2_URL);
}
catch (SQLException sql_excp) {
System.err.println(CLASS_NAME + "." + METHOD_NAME + " - Encountered
error while " +
"connecting to URL, " + DB2_URL + ".");
sql_excp.printStackTrace();
System.exit(16);
}
/* Set autocommit. */
try {
conn01.setAutoCommit(AUTOCOMMIT);
}
catch (SQLException sql_excp) {
System.err.println(CLASS_NAME + "." + METHOD_NAME + " - Encountered
error while " +
"setting autocommit to " + AUTOCOMMIT + ".");
sql_excp.printStackTrace();
System.exit(16);
}
}
Only the first version of the DB2_URL variable works; the other two don't.
That means that I can get a Type 2 connection but not a Type 4 connection.
What am I doing wrong?
By the way, I can successfully ping both localhost and 127.0.0.1 from my
Windows command prompt so I don't seem to be missing and etc/ entries.
--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare