jdbc获取表中列名

   1. pment = conn.prepareStatement("select * from A0001 where 1 = 2");  
2. rs = pment.executeQuery();
3. ResultSetMetaData metaData = rs.getMetaData();
4. int colum = metaData.getColumnCount();
5. for (int i = 1; i <= colum; i++)
6. {
7. String typeStr = ""; //类型
8. //获取列名
9. String columName = metaData.getColumnName(i);
10. //获取每一列的数据类型
11. int type = metaData.getColumnType(i);
12. //判断
13. if(Types.INTEGER == type)
14. {
15. typeStr = "Integer";
16. }
17. else if(Types.VARCHAR == type)
18. {
19. typeStr = "String";
20. }
21. }

你可能感兴趣的:(MySQL)