java获取数据库表字段_Java获取数据库表 字段 存储的部分数据

1 /**

2 * 河北天气删除 选中图片3 */

4 public int[] HeBeiTianQiDelete(String IdParam, String ThisPicLocalPathStr,String AuthenticatePeople) {5 if(StringUtil.isEmpty(IdParam)){6 return null;7 }8 String sql = "select id,picLocalPath from TabHeBeiTianQi where id in ("+IdParam+")";9 String picLocalPathStr=this.getJsonStrBySql(sql);10 int[] result=new int[3];//定义一个长度为3的int型数组

11 int sucessCount=0;12 int falseCount=0;13 int oneResult=0;14 try{15 JSONArray jsonArray = newJSONArray(picLocalPathStr);16 JSONArray thisJsonArray = newJSONArray(ThisPicLocalPathStr);17 for(int i=0 ; i < jsonArray.length() ;i++){18 //将json数组转换成json对象

19 JSONObject jsonObject = jsonArray.getJSONObject(i);//JSONObject jsonObject = (JSONObject) jsonArray.get(i);

20 String idVal = jsonObject.getString("id");//id这里是列名称,获取json对象中列名为id的值

21 String picLocalPathVal = jsonObject.getString("picLocalPath");22 String[] picLocalPathValArr = picLocalPathVal.split(",");23 String ResultPicLocalPathValStr = null;24 List oneList = Arrays.asList(picLocalPathValArr);//将数组转换为list集合

25 List arrayList = new ArrayList(oneList);//转换为ArrayLsit调用相关的remove方法

26 for(int j=0 ; j < thisJsonArray.length() ;j++){27 JSONObject thisJsonObject =thisJsonArray.getJSONObject(j);28 String thisIdVal = thisJsonObject.getString("id");29 String thisPicLocalPathVal = thisJsonObject.getString("url"); //实际获取的字符串中只有1个url30 //String[] thisPicLocalPathValArr = thisPicLocalPathVal.split(",");//不需要分割 ,因为实际传来字符串中只有1个url

31 if(thisIdVal.equals(idVal)){//这里不能用idVal==thisIdVal ,因为会根据id清空

32 arrayList.remove(thisPicLocalPathVal);33 /*for(int m=0;m

36 //控制台输出演示---- 数组列表

37 /*for (String str1 : arrayList) {38 System.out.println(str1 + ",");39 }*/

40 //ArrayList转成String数组["","",""]

41 String[] array = arrayList.toArray(new String[0]);42 /*for (int n = 0; n < array.length; n++) {43 System.out.println("array--> " + array[n]);44 }*/

45 //方式一将String数组["","",""]转换成String",,"

46 ResultPicLocalPathValStr=StringUtil.formatStringArrToString(array);47 //方式二将String数组["","",""]转换成String"[,,]"48 //ResultPicLocalPathValStr = Arrays.toString(array);49 //String格式转换:将String"[,,]"转换成String",,"50 //参考https://zhidao.baidu.com/question/136765761398462045.html

51 //将字符串转换成json对象

52 /*JSONObject ResultPicLocalPathVal=new JSONObject();53 ResultPicLocalPathVal.put("picLocalPath", ResultPicLocalPathValStr);*/

54 StringBuffer sqlDelete = newStringBuffer();55 String nowDate = TimeUtil.getCurrentDate("yyyy-MM-dd HH:mm:ss");56 sqlDelete.append("update TabHeBeiTianQi set picLocalPath= ?,AuthenticateDate = ?,AuthenticatePeople=? where ID = ?");57 oneResult= this.executeBySql(sqlDelete.toString(),newObject[]{ResultPicLocalPathValStr,nowDate,AuthenticatePeople,idVal});58 if (oneResult>0){59 sucessCount=sucessCount+oneResult;//执行成功个数

60 }else{61 falseCount=thisJsonArray.length()-sucessCount;62 }63 }64 }65 }66 result[0]=oneResult;67 result[1]=sucessCount;68 result[2]=falseCount;69 } catch(JSONException e) {70 e.printStackTrace();71 }72 returnresult;73 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值