?1
/**?*//**???
?2
????????????*?????取得當前連接數據庫指定表的字段信息。???
?3
????????????*???@param???tableName?????????????????????表名稱???
?4
????????????*???@return???????????????????????????????????????字段信息列表???
?5
????????????*???@exception?????SQLException?????Description???of???the???Exception???
?6
????????????*???@throws?????Exception?????????????????失敗時拋出???
?7
????????????*/???
?8
??????????public???ParameterList???getFieldList(???String???tableName???)???
?9
??????????????????throws???SQLException???
10
??????????
{???
11
??????????????????ResultSet???????????????????rs???=???executeQuery(???"SELECT???*???FROM???"???+???tableName???);???
12
??????????????????ResultSetMetaData???meta?????????????????=???rs.getMetaData(?????);???
13
??????????????????int???????????????????????????????columnCount???=???meta.getColumnCount(?????);???
14
??????????????????ParameterList???????????result?????????????=???new???ParameterList(?????);???
15
????
16
??????????????????for???(???int???i???=???0;???i???<???columnCount;???i++???)???
17
??????????????????
{???
18
??????????????????????????DBTableFieldStruct???field?????=???new???DBTableFieldStruct(?????);??????
19
??????????????????????????int?????????????????????????????????cursor???=???i???+???1;???
20
??????????????????????????field.name???????????????????????=???meta.getColumnName(???cursor???);?????????(2)
21
??????????????????????????field.type???????????????????????=???meta.getColumnType(???cursor???);????????????(1)
22
??????????????????????????field.size???????????????????????=???meta.getColumnDisplaySize(???cursor???);???(3)
23
??????????????????????????field.scale?????????????????????=???meta.getScale(???cursor???);???????????????????????????(4)
24
??????????????????????????field.isNullable???????????=???meta.isNullable(???cursor???);????????????????????????(5)
25
????
26
??????????????????????????//field.precision?????????????=???meta.getPrecision(???cursor???);???
27
??????????????????????????result.append(???field???);???
28
??????????????????}???
29
????
30
??????????????????return???result;???
31
??????????}
所需要的部分在(1)? 處,此處返回一int型數據。這樣通過java.sql.Types類來匹配這個int型數據,便可知道字段的數據類型

?2

?3

?4

?5

?6

?7

?8

?9

10



11

12

13

14

15

16

17



18

19

20

21

22

23

24

25

26

27

28

29

30

31

(2),(3),(4),(5) 得到的是字段的其他信息,顯而易見,不多廢話了!