zoukankan      html  css  js  c++  java
  • jdbc反射操作

     1 package com.gu.utils;
     2 
     3 import java.lang.reflect.InvocationTargetException;
     4 import java.lang.reflect.Method;
     5 
     6 /**
     7  * jdbc反射而常用的操作
     8  * @author 9  *
    10  */
    11 public class reflectUtils {
    12 
    13     //由属性名获得属性值
    14     public static Object invokeGet( String feildName,Object obj){
    15         Method m=null;
    16         Object end=null;
    17         try {
    18             Class c=obj.getClass();
    19             m=c.getMethod("Get"+StringUtils.firstChar2uppercas(feildName), null);
    20             try {
    21                 end=m.invoke(obj, null);
    22             } catch (IllegalAccessException e) {
    23                 // TODO Auto-generated catch block
    24                 e.printStackTrace();
    25             } catch (IllegalArgumentException e) {
    26                 // TODO Auto-generated catch block
    27                 e.printStackTrace();
    28             } catch (InvocationTargetException e) {
    29                 // TODO Auto-generated catch block
    30                 e.printStackTrace();
    31             }
    32         } catch (NoSuchMethodException e) {
    33             // TODO Auto-generated catch block
    34             e.printStackTrace();
    35         } catch (SecurityException e) {
    36             // TODO Auto-generated catch block
    37             e.printStackTrace();
    38         }
    39         return end;
    40     }
    41     public static void invokeSet( String columnName,Object columnValue,Object RowObj){
    42         //调用set方法将属性值设进去
    43         Method m=null;
    44         try {
    45             m = RowObj.getClass().getDeclaredMethod("Set"+StringUtils.firstChar2uppercase(columnName),columnValue.getClass() );
    46         } catch (NoSuchMethodException e1) {
    47             // TODO Auto-generated catch block
    48             e1.printStackTrace();
    49         } catch (SecurityException e1) {
    50             // TODO Auto-generated catch block
    51             e1.printStackTrace();
    52         }
    53         try {
    54             m.invoke(RowObj, columnValue);
    55         } catch (IllegalAccessException e) {
    56             // TODO Auto-generated catch block
    57             e.printStackTrace();
    58         } catch (IllegalArgumentException e) {
    59             // TODO Auto-generated catch block
    60             e.printStackTrace();
    61         } catch (InvocationTargetException e) {
    62             // TODO Auto-generated catch block
    63             e.printStackTrace();
    64         }
    65     }
    66 
    67 }
  • 相关阅读:
    随机生成字符串,可用来当id
    自己总结的关于uniapp项目用androidstuido打包成apk
    css3 滑动效果 门
    在数组里面随机获取随机的几个内容
    把一个数组分割成两个(不管奇数还是偶数)
    Mysql常用命令
    怎样才能彻底地删除多余输入法软件
    启动MySQL服务
    linux监控命令全覆盖
    浅谈MVC模式与SSH框架
  • 原文地址:https://www.cnblogs.com/helloMyworld0001/p/5972931.html
Copyright © 2011-2022 走看看