java程序如何判断mysql数据库中字段的数据类型?

2024-12-20 19:28:40
推荐回答(1个)
回答1:

public ParameterList getFieldList(String tableName)throws SQLException{
ResultSet rs = executeQuery("SELECT * FROM " + tableName);
ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount();
ParameterList result = new ParameterList();
for (int i = 0; i < columnCount; i++)
{
DBTableFieldStruct field = new DBTableFieldStruct();
int cursor = i + 1;
field.type = meta.getColumnType(cursor);
result.append(field);
}
return result;
}