JDBC retrieve table columns information
public void describeTable(String tableName) {
try {
PreparedStatement pstmt = conn
.prepareStatement("select * from <TABLENAME> where 1 = 0");
ResultSet rs = pstmt.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
System.out.printf(
"Column[d]: %s %s(%d, %d)\n", i,
rsmd.getColumnName(i), rsmd.getColumnTypeName(i),
rsmd.getPrecision(i), rsmd.getScale(i));
}
rs.close();
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
转载请注明原文地址: https://ju.6miu.com/read-700125.html