obj = J4E.fromExcel(in, Class.forName(classname),null); OBJ到底有多少个字段如何得到?我需遍历整个数据表的每个字段,得到这份表的每个字段字符个数的最大值,然后修改表的字段最大值,再导表,省得只看见报错,截断字符串,好烦燥的
20 回复
试了一下, mysql的话可以这样写
@Test
public void test_get_column_info_from_mysql() {
Sql sql = Sqls.queryRecord("select * from information_schema.columns where table_schema = @db and table_name =@tname");
sql.forceExecQuery();
sql.setParam("db", "nutztest");
sql.setParam("tname", dao.getEntity(Pet.class).getTableName());
dao.execute(sql);
List<Record> list = sql.getList(Record.class);
System.out.println(list);
}
每行记录(就是一个字段)的数据类似于
{
"table_catalog": "def",
"table_schema": "nutztest",
"table_name": "t_pet",
"column_name": "alias",
"ordinal_position": 3,
"column_default": null,
"is_nullable": "YES",
"data_type": "varchar",
"character_maximum_length": 128, // 长度
"character_octet_length": 384,
"numeric_precision": null,
"numeric_scale": null,
"datetime_precision": null,
"character_set_name": "utf8",
"collation_name": "utf8_general_ci",
"column_type": "varchar(128)",
"column_key": "",
"extra": "",
"privileges": "select,insert,update,references",
"column_comment": "",
"generation_expression": ""
}
添加回复
请先登陆