Get name of database table column type by field class. - Android Database

Android examples for Database:Table Column

Description

Get name of database table column type by field class.

Demo Code


//package com.java2s;

import java.util.Date;

public class Main {
    /**/*from ww  w  .  j a  v  a 2 s.co m*/
     * Get name of column type by field class.
     *
     * @return - name of class.
     */
    private static String getType(Class<?> inClass) {
        if (inClass.isAssignableFrom(Integer.class)
                || inClass.isAssignableFrom(int.class)
                || inClass.isAssignableFrom(long.class)
                || inClass.isAssignableFrom(Long.class)
                || inClass.isAssignableFrom(Short.class)
                || inClass.isAssignableFrom(short.class)
                || inClass.isAssignableFrom(byte.class)
                || inClass.isAssignableFrom(Byte.class)
                || inClass.isAssignableFrom(Date.class)
                || inClass.isAssignableFrom(Boolean.class)
                || inClass.isAssignableFrom(boolean.class)) {
            return "INTEGER";
        }
        if (inClass.isAssignableFrom(Double.class)
                || inClass.isAssignableFrom(double.class)
                || inClass.isAssignableFrom(Float.class)
                || inClass.isAssignableFrom(float.class)) {
            return "REAL";
        }
        if (inClass.isAssignableFrom(String.class)
                || inClass.isAssignableFrom(CharSequence.class)) {
            return "TEXT";
        }
        if (inClass.isAssignableFrom(Byte[].class)
                || inClass.isAssignableFrom(byte[].class)) {
            return "BLOB";
        }
        return null;
    }
}

Related Tutorials