Technote (FAQ)
Question
When using the following sample code, the username is returned in uppercase unexpectedly.
----- example.java ------------------------------
import java.sql.*;
import java.io.*;
import javax.sql.*;
import java.util.*;
public class example {
public static void main(String argv[]) {
Connection conn = null;
try {
if (argv.length == 4 | argv.length == 2) {
if (argv[0].equals("legacy") ){
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
}else if(argv[0].equals("jcc")){
Class.forName("com.ibm.db2.jcc.DB2Driver");
}else{
System.out.println("argv[0]=[" + argv[0] + "]: incorrect driver name, should be legacy or jcc.");
System.exit(0);
}
}
else {
// print usage then terminate.
System.out.println("\nUsage: java example legacy|jcc url [username password]\n" +
" ex: java example legacy jdbc:db2:sample db2inst1 password\n" +
" ex: java example jcc jdbc:db2://localhost:55555/sample db2inst1 password\n");
System.exit(0);
}
if (argv.length == 4){
conn = DriverManager.getConnection(argv[1], argv[2], argv[3]);
}
else if (argv.length == 2){
conn = DriverManager.getConnection(argv[1]);
}
DatabaseMetaData dbMetaData = conn.getMetaData();
System.out.println("getUserName:" + dbMetaData.getUserName());
conn.close();
}
catch (Exception ex) {
ex.printStackTrace(System.err);
}
}
}
// end of example
-----------------------------------------------
The following is the output of the DB2® Version 9.7 Fix Pack 6, 64 bit software.
JCC Type 2:
$ java example jcc jdbc:db2:sample hidehy hidehy
getUserName:HIDEHY
Legacy JDBC Type 2:
$ java example legacy jdbc:db2:sample hidehy hidehy
getUserName:hidehy
JCC Type 4:
$ java example jcc jdbc:db2://localhost:55555/sample hidehy hidehy
getUserName:hidehy
As shown in the sample output of JCC Type 2 driver, the username is not returned in lowercase. In DB2 Version 8.2, all three types of drivers return the username is lowercase. However in DB2 Version 9.1, Version 9.5, and Version 9.7, only JCC Type 2 drivers return usernames in all capital letters.
Answer
The current DB2 Version 9.7 Fix Pack 6 behavior works as designed. There is no commitment for future version/release updates because the JCC Type 2 driver is not case sensitive.
Rate this page:
Copyright and trademark information
IBM, the IBM logo and ibm.com are trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml.