Java SQL Type convert2MysqlType(String cls)

Here you can find the source of convert2MysqlType(String cls)

Description

convert Mysql Type

License

Apache License

Parameter

Parameter Description
cls a parameter

Declaration

public static String convert2MysqlType(String cls) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from   ww  w . j a  v  a  2 s .c  om*/
     * @param cls
     * @return
     */
    public static String convert2MysqlType(String cls) throws Exception {
        if (cls.equals("java.lang.String")) {
            return "VARCHAR(20)";
        } else if (cls.equals("java.lang.byte[]")) {
            return "BLOB";
        } else if (cls.equals("java.lang.Integer") || cls.equals("int")) {
            return "INT";
        } else if (cls.equals("java.lang.Long") || cls.equals("long")) {
            return "BIGINT";
        } else if (cls.equals("java.lang.Boolean") || cls.equals("boolean")) {
            return "TINYINT";
        } else if (cls.equals("java.math.BigInteger")) {
            return "BIGINT";
        } else if (cls.equals("java.lang.Float") || cls.equals("float")) {
            return "FLOAT";
        } else if (cls.equals("java.lang.Double") || cls.equals("double")) {
            return "DOUBLE";
        } else if (cls.equals("java.math.BigDecimal")) {
            return "DECIMAL";
        } else if (cls.equals("java.util.Date")) {
            return "DATE";
        } else if (cls.equals("java.sql.Date")) {
            return "DATE";
        } else if (cls.equals("java.sql.Time")) {
            return "TIME";
        } else if (cls.equals("java.sql.Timestamp")) {
            return "TIMESTAMP";
        } else if (cls.equals("java.util.DateTime")) {
            return "TIMESTAMP";
        } else {
            throw new Exception("cls=>" + cls + " canot convert to mysql type! ");
        }
    }
}

Related

  1. columnDisplaySize(int columnType)
  2. columnPrecision(int columnType)
  3. columnScale(int columnType)
  4. columnTypesDiffer(int t1, int t2)
  5. compressType(int type)
  6. convertBoolean(Object value, int srcType, int destType)
  7. convertKnownType(Object one, Class to)
  8. convertNumeric(Object value, int srcType, int destType)
  9. convertOracleValue(Object value, int type)