文件名称:Hibernate自动生成数据库表映射实体类
文件大小:5KB
文件格式:JAVA
更新时间:2021-02-08 18:57:40
自动生成
private static void printTableMetaInfo(Session session) {
Connection connection = session.connection();
try {
DatabaseMetaData metaData = connection.getMetaData();
ResultSet result = metaData.getColumns(null, null, NameOfTable, null);
String strInJava = "";
String typeInJava;
while (result.next()) {
String columnName = result.getString(4);
if ("stampTime".equalsIgnoreCase(columnName)) {
continue;
}
int columnType = result.getInt(5);
String nameFirstLetterLower = columnName.substring(0, 1).toLowerCase() + columnName.substring(1);
switch (columnType) {
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.LONGNVARCHAR:
case Types.NVARCHAR:
case Types.CHAR:
typeInJava = "String";
break;
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
typeInJava = useInteger ? "Integer" : "int";
break;
case Types.TIMESTAMP:
case Types.BINARY:
typeInJava = "Calendar";
break;
case Types.DECIMAL:
typeInJava = "BigDecimal";
break;
case Types.BIGINT:
typeInJava = "BigInteger";
break;
case Types.LONGVARBINARY:
typeInJava = "byte[]";
break;
case Types.DATE:
typeInJava = "Calendar";
break;
default:
throw new Exception("Unknown type " + columnType + " and column is " + columnName);
}
strInJava += " private " + typeInJava + " " + nameFirstLetterLower + ";\n";
// strInHibernate += "