zoukankan      html  css  js  c++  java
  • java数据类型对应postgresql的数据类型

      java8 postgreSQL Oracle
    1 LocalDate date  
    2 LocalTime time  
    3 LocalDateTime timestamp without timezone  
    4 OffsetDateTime timestamp with timezone  
    5 String varchar  
    6 String text  
    7 Integer int2  
    8 Integer int4  
    9 Long int8  
    10 Float float4  
    11 Double float8  
    12 BigDecimal numeric  
    13 Boolean bool  
           
           
           
           
           
           

    总结java数据类型和mysql、oracle、pgsql数据类型对应关系,附数据库字段类型转java类型代码

    https://blog.csdn.net/qq_21187515/article/details/91495237?utm_medium=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-3.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-3.control

    mysql字段类型转java类型的方法代码
    public class MySqlTypeConvert implements ITypeConvert {
        public MySqlTypeConvert() {
        }
    
        /**
         * mysql字段类型转java类型
         * @param fieldType mysql字段类型
         * @return
         */
        public DbColumnType processTypeConvert(String fieldType) {
            String t = fieldType.toLowerCase();
            if (!t.contains("char") && !t.contains("text")) {
                if (t.contains("bigint")) {
                    return DbColumnType.LONG;
                } else if (t.contains("int")) {
                    return DbColumnType.INTEGER;
                } else if (!t.contains("date") && !t.contains("time") && !t.contains("year")) {
                    if (t.contains("text")) {
                        return DbColumnType.STRING;
                    } else if (t.contains("bit")) {
                        return DbColumnType.BOOLEAN;
                    } else if (t.contains("decimal")) {
                        return DbColumnType.BIG_DECIMAL;
                    } else if (t.contains("clob")) {
                        return DbColumnType.CLOB;
                    } else if (t.contains("blob")) {
                        return DbColumnType.BLOB;
                    } else if (t.contains("binary")) {
                        return DbColumnType.BYTE_ARRAY;
                    } else if (t.contains("float")) {
                        return DbColumnType.FLOAT;
                    } else if (t.contains("double")) {
                        return DbColumnType.DOUBLE;
                    } else {
                        return !t.contains("json") && !t.contains("enum") ? DbColumnType.STRING : DbColumnType.STRING;
                    }
                } else {
                    return DbColumnType.DATE;
                }
            } else {
                return DbColumnType.STRING;
            }
        }
    }
    
    
    oracle字段类型转java类型的方法代码
    public class OracleTypeConvert implements ITypeConvert {
        public OracleTypeConvert() {
        }
    
        /**
         * oracle字段类型转java类型
         * @param fieldType oracle字段类型
         * @return
         */
        public DbColumnType processTypeConvert(String fieldType) {
            String t = fieldType.toUpperCase();
            if (t.contains("CHAR")) {
                return DbColumnType.STRING;
            } else if (!t.contains("DATE") && !t.contains("TIMESTAMP")) {
                if (t.contains("NUMBER")) {
                    if (t.matches("NUMBER\(+\d\)")) {
                        return DbColumnType.INTEGER;
                    } else {
                        return t.matches("NUMBER\(+\d{2}+\)") ? DbColumnType.LONG : DbColumnType.DOUBLE;
                    }
                } else if (t.contains("FLOAT")) {
                    return DbColumnType.FLOAT;
                } else if (t.contains("clob")) {
                    return DbColumnType.CLOB;
                } else if (t.contains("BLOB")) {
                    return DbColumnType.OBJECT;
                } else if (t.contains("binary")) {
                    return DbColumnType.BYTE_ARRAY;
                } else {
                    return t.contains("RAW") ? DbColumnType.BYTE_ARRAY : DbColumnType.STRING;
                }
            } else {
                return DbColumnType.DATE;
            }
        }
    }
    
    pgsql字段类型转java类型的方法代码
    public class PostgreSqlTypeConvert implements ITypeConvert {
        public PostgreSqlTypeConvert() {
        }
    
        public DbColumnType processTypeConvert(String fieldType) {
            String t = fieldType.toLowerCase();
            if (!t.contains("char") && !t.contains("text")) {
                if (t.contains("bigint")) {
                    return DbColumnType.LONG;
                } else if (t.contains("int")) {
                    return DbColumnType.INTEGER;
                } else if (!t.contains("date") && !t.contains("time") && !t.contains("year")) {
                    if (t.contains("text")) {
                        return DbColumnType.STRING;
                    } else if (t.contains("bit")) {
                        return DbColumnType.BOOLEAN;
                    } else if (t.contains("decimal")) {
                        return DbColumnType.BIG_DECIMAL;
                    } else if (t.contains("clob")) {
                        return DbColumnType.CLOB;
                    } else if (t.contains("blob")) {
                        return DbColumnType.BYTE_ARRAY;
                    } else if (t.contains("float")) {
                        return DbColumnType.FLOAT;
                    } else if (t.contains("double")) {
                        return DbColumnType.DOUBLE;
                    } else if (!t.contains("json") && !t.contains("enum")) {
                        return t.contains("boolean") ? DbColumnType.BOOLEAN : DbColumnType.STRING;
                    } else {
                        return DbColumnType.STRING;
                    }
                } else {
                    return DbColumnType.DATE;
                }
            } else {
                return DbColumnType.STRING;
            }
        }
    }
    
    public enum DbColumnType {
        BASE_INT("int", (String)null),
        BASE_BOOLEAN("boolean", (String)null),
        BASE_FLOAT("float", (String)null),
        BASE_DOUBLE("double", (String)null),
        STRING("String", (String)null),
        LONG("Long", (String)null),
        INTEGER("Integer", (String)null),
        FLOAT("Float", (String)null),
        DOUBLE("Double", (String)null),
        BOOLEAN("Boolean", (String)null),
        BYTE_ARRAY("byte[]", (String)null),
        CHARACTER("Character", (String)null),
        OBJECT("Object", (String)null),
        DATE("Date", "java.util.Date"),
        TIME("Time", "java.sql.Time"),
        BLOB("Blob", "java.sql.Blob"),
        CLOB("Clob", "java.sql.Clob"),
        TIMESTAMP("Timestamp", "java.sql.Timestamp"),
        BIG_INTEGER("BigInteger", "java.math.BigInteger"),
        BIG_DECIMAL("BigDecimal", "java.math.BigDecimal"),
        LOCAL_DATE("LocalDate", "java.time.LocalDate"),
        LOCAL_TIME("LocalTime", "java.time.LocalTime"),
        LOCAL_DATE_TIME("LocalDateTime", "java.time.LocalDateTime");
    
        private final String type;
        private final String pkg;
    
        private DbColumnType(String type, String pkg) {
            this.type = type;
            this.pkg = pkg;
        }
    
        public String getType() {
            return this.type;
        }
    
        public String getPkg() {
            return this.pkg;
        }
    }
    

      

    注:
    这里参考了mybatis-plus-2.0.6.jar的生成实体类的源码,具体可以查看mybatis-plus的源码

  • 相关阅读:
     selenium webdriver test
    V8 初次接触(Qt5) 1+1=2 博客频道 CSDN.NET
    C++11 FAQ中文版
    做技术的,因为年龄和颈椎问题,想逐渐脱离码农状态,大家对3035岁职业规划有什么好的建议? 知乎
    一些idea
    如何来区分是我写的还是我转载的,
    firecurl
    python为什么叫好不叫座
    QTextCodec中的setCodecForTr等终于消失了 (Qt5) 1+1=2 博客频道 CSDN.NET
    Charles Web Debugging Proxy • HTTP Monitor / HTTP Proxy / HTTPS & SSL Proxy / Reverse Proxy
  • 原文地址:https://www.cnblogs.com/wzihan/p/14872691.html
Copyright © 2011-2022 走看看