我想在mysql中获取列的类似字符串显示的表标签.像这样
但是,当我使用getColumnName时,结果是返回的字符串和下面的字符串之间存在一些差异.像这样:
但是当我调试时,它在Eclipse中的变量浏览器中是正确的,像这样:
我找不到其他方式来获取专栏.它似乎返回字符串originalColumnName,但如何获得ColumnName?谁知道怎么修它?
有我的代码,我知道代码中还有其他问题.请假设所有列的类型都是String.
public ResultSet DisplayShowTables() throws SQLException
{
ResultSet Res = Sta.executeQuery("DESC Code2Name");
ResultSetMetaData ResMeta = Res.getMetaData();
String [] ColumnName = new String [ResMeta.getColumnCount()];
int MetaCount = ResMeta.getColumnCount();
for (int i = 0; i < MetaCount; i++) {
ColumnName [i] = ResMeta.getColumnName(i+1);
}
String LeftAlignFormat = "|";
String Separator = "+";
for (int i = 0; i < MetaCount; i++) {
LeftAlignFormat = LeftAlignFormat.concat(" %-20s |");
Separator =Separator.concat("----------------------+");
}
LeftAlignFormat = LeftAlignFormat.concat("%n");
Separator …Run Code Online (Sandbox Code Playgroud)