mysql字段类型转java类型函数

CREATE DEFINER=`root`@`%` FUNCTION `getJavaType`(sqlType VARCHAR(30)) RETURNS varchar(30) CHARSET utf8
    DETERMINISTIC
BEGIN
		DECLARE javaType VARCHAR(30);
		SET javaType=(
				CASE upper(sqlType)
						WHEN 'VARCHAR' THEN 'String'
						WHEN 'CHAR' THEN 'String'
						WHEN 'TEXT' THEN 'String'
						WHEN 'TINYINT' THEN 'Integer'
						WHEN 'SMALLINT' THEN 'Integer'
						WHEN 'MEDIUMINT' THEN 'Integer'
						WHEN 'BOOLEAN' THEN 'Integer'
						WHEN 'BIGINT' THEN 'BigInteger'
						WHEN 'INTEGER' THEN 'Long'
						WHEN 'ID' THEN 'Long'
						WHEN 'FLOAT' THEN 'Float'
						WHEN 'DOUBLE' THEN 'Double'
						WHEN 'DECIMAL' THEN 'BigDecimal'
						WHEN 'BIT' THEN 'Boolean'
						WHEN 'BLOB' THEN 'byte[]'
						WHEN 'DATE' THEN 'Date'
						WHEN 'YEAR' THEN 'Date'
						WHEN 'TIME' THEN 'Time'
						WHEN 'DATETIME' THEN 'Timestamp'
						WHEN 'TIMESTAMP' THEN 'Timestamp'
						ELSE 'String ' END
				);
		RETURN javaType;
	END

 

你可能感兴趣的:(数据库)