热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

访问DB2数据库进行数据更新的代码片段

1.访问Db2数据库首先请载入如下lib:db2jcc.jar,db2jcc_license_cu.jar在C:ProgramFilesIBMSQLLIBjava下可以找到它们。2.若

1.访问Db2数据库首先请载入如下lib:db2jcc.jar,db2jcc_license_cu.jar在C:\Program Files\IBM\SQLLIB\java下可以找到它们。2.若

1.访问Db2数据库首先请载入如下lib:
db2jcc.jar,db2jcc_license_cu.jar
在C:\Program Files\IBM\SQLLIB\java下可以找到它们。

2.若用户没有想要访问的表的权限,,请打开Db2控制中心,找到表,在右键菜单中加入用户访问许可。如果倒过来做不容易成功。

3.以下是访问代码:
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.NOTIFY_TEXT set NOTIFY_TYPE='a23' where SUBJECT='a' ";

Map map=getUpdateMap();

for(String key:map.keySet()){
String value=map.get(key);

sql = " update ONETEAM.NOTIFY_TEXT set NOTIFY_TYPE='"+value+"' where SUBJECT='"+key+"' ";
updatedRecordCount+=st.executeUpdate(sql);
}

conn.close();
return updatedRecordCount;
} catch (Exception e) {
System.out.println("Exception occured:" + e);
return updatedRecordCount;
}
}

private static Map getUpdateMap(){
Map map=new HashMap();

map.put("RECERT_BUNDLE_MGR_ONLY_C", "Action may be required: OneTEAM Recertification Completed. See Recertify before Date.");
map.put("RECERT_BUNDLE_MGR_ONLY_F", "Action may be required: OneTEAM Recertification Final reminder. See Recertify before Date.");
map.put("RECERT_BUNDLE_MGR_ONLY_I", "Action may be required: OneTEAM Recertification Initiated. See Recertify before Date.");
map.put("RECERT_BUNDLE_MGR_ONLY_R", "Action may be required: OneTEAM Recertification Reminder notification. See Recertify before Date.");
map.put("RECERT_BUNDLE_USER_C", "Action may be required: OneTEAM Recertification Completed. See Recertify before Date.");
map.put("RECERT_BUNDLE_USER_F", "Action may be required: OneTEAM Recertification Final reminder. See Recertify before Date.");
map.put("RECERT_BUNDLE_USER_I", "Action may be required: OneTEAM Recertification Initiated. See Recertify before Date.");
map.put("RECERT_BUNDLE_USER_R", "Action may be required: OneTEAM Recertification Reminder notification. See Recertify before Date");

return map;
}
}

linux

推荐阅读
author-avatar
小编106
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有