jdbc获取表中列名
程序员文章站
2022-04-20 08:29:14
...
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. }
下一篇: vim的一些常见的操作