java判断Object对象类型,记录一下

Object param = params.get(i);
   if (param instanceof Integer) {
    int value = ((Integer) param).intValue();
    prepStatement.setInt(i + , value);
   } else if (param instanceof String) {
    String s = (String) param;
    prepStatement.setString(i + , s);
   } else if (param instanceof Double) {
    double d = ((Double) param).doubleValue();
    prepStatement.setDouble(i + , d);
   } else if (param instanceof Float) {
    float f = ((Float) param).floatValue();
    prepStatement.setFloat(i + , f);
   } else if (param instanceof Long) {
    long l = ((Long) param).longValue();
    prepStatement.setLong(i + , l);
   } else if (param instanceof Boolean) {
    boolean b = ((Boolean) param).booleanValue();
    prepStatement.setBoolean(i + , b);
   } else if (param instanceof Date) {
    Date d = (Date) param;
    prepStatement.setDate(i + , (Date) param);
   }
Scroll Up