1. To access the Db2 database, first load the following lib:
Db2jcc. jar, db2jcc_license_cu.jar
You can find them in C: \ Program Files \ IBM \ SQLLIB \ java.
2. If the user does not have the permission to access the table, open the Db2 control center, find the table, and add the user access permission to the right-click menu. However, it is not easy to succeed.
3. The following is the access code:
Package com. ibm;
Import java. SQL. Connection;
Import java. SQL. DriverManager;
Import java. SQL. Statement;
Import java. util. HashMap;
Import java. util. Map;
Public class TableUpdater {
Public static void main (String [] args ){
Int count = TableUpdater. updateTableNOTIFY_TEXT ("127.0.0.1", "50000", "db2admin", "123456789 ");
System. out. println ("" + count + "records have been updated .");
}
Public static int updateTableNOTIFY_TEXT (String dbIpAddress, String dbPort, String dbUserName, String dbUserPassword ){
String driver = "com. ibm. db2.jcc. DB2Driver ";
String url = "jdbc: db2: //" + dbIpAddress + ":" + dbPort + "/ONETEAMP ";
String userName = dbUserName;
String passWord = dbUserPassword;
Int updatedRecordCount = 0;
String SQL = "";
Try {
Class. forName (driver). newInstance ();
Connection conn = DriverManager. getConnection (url, userName, passWord );
Statement st = conn. createStatement ();
SQL = "update ONETEAM. policy_text set policy_type = 'a23' where SUBJECT = 'A '";
Map <String, String> map = getUpdateMap ();
For (String key: map. keySet ()){
String value = map. get (key );
SQL = "update ONETEAM. policy_text set policy_type = '" + value + "'where SUBJECT ='" + key + "'";
Updatedrecordcount+st.exe cuteUpdate (SQL );
}
Conn. close ();
Return updatedRecordCount;
} Catch (Exception e ){
System. out. println ("Exception occured:" + e );
Return updatedRecordCount;
}
}
Private static Map <String, String> getUpdateMap (){
Map <String, String> map = new HashMap <String, String> ();
Map. put ("RECERT_BUNDLE_MGR_ONLY_C", "Action may be required: OneTEAM Recertification Completed. See recersponbefore Date .");
Map. put ("RECERT_BUNDLE_MGR_ONLY_F", "Action may be required: OneTEAM Recertification Final reminder. See recer=before Date .");
Map. put ("RECERT_BUNDLE_MGR_ONLY_ I", "Action may be required: OneTEAM Recertification Initiated. See recersponbefore Date .");
Map. put ("RECERT_BUNDLE_MGR_ONLY_R", "Action may be required: OneTEAM Recertification Reminder notification. See recer=before Date .");
Map. put ("RECERT_BUNDLE_USER_C", "Action may be required: OneTEAM Recertification Completed. See recersponbefore Date .");
Map. put ("RECERT_BUNDLE_USER_F", "Action may be required: OneTEAM Recertification Final reminder. See recer#before Date .");
Map. put ("RECERT_BUNDLE_USER_ I", "Action may be required: OneTEAM Recertification Initiated. See recersponbefore Date .");
Map. put ("RECERT_BUNDLE_USER_R", "Action may be required: OneTEAM Recertification Reminder notification. See recer#before Date ");
Return map;
}
}