我已经使用eclipse ide说明了mysql与java的连接并添加了一些记录,但结果不正确。 当我显示表列表时,表字段没有显示,这里我得到了数据库名称。
out.println("<body><tt><table border=1 width=90%><tr>");
try {
ResultSet rs = com.db.Admin.getData();
ResultSetMetaData mdata = rs.getMetaData();
int NOC = mdata.getColumnCount();
for (int i = 1; i <= NOC; i++) {
out.println("<th>" + mdata.getCatalogName(i));
}
while (rs.next()) {
out.println("<tr>");
for (int i = 1; i <= NOC; i++)
out.print("<td>" + rs.getString(i));
out.println("</tr>");
}
} catch (Exception e) {
// TODO: handle exception
out.print(e.toString());
}
最佳答案
Gets the designated column's table's catalog name.
您可能想要getColumnLabel() :
Gets the designated column's suggested title for use in printouts and displays. The suggested title is usually specified by the SQL AS clause. If a SQL AS is not specified, the value returned from getColumnLabel will be the same as the value returned by the getColumnName method.
当您阅读文档时,一切都会变得更简单。
关于java - JDBC 中的表列标题不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35874773/