acerbic coffee
          走自己的路,讓別人跑步
          posts - 26,comments - 14,trackbacks - 0
          ??????用java獲取表中各個字段的數據類型,在網上逛了半天終于在csdn上找到了一篇文章,有了一些思路,下面是部分代碼1
          ?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) 得到的是字段的其他信息,顯而易見,不多廢話了!
          posted on 2007-02-25 16:40 acerbic coffee 閱讀(5107) 評論(0)  編輯  收藏 所屬分類: articles
          主站蜘蛛池模板: 巩留县| 融水| 吴江市| 合作市| 张北县| 康乐县| 墨脱县| 特克斯县| 台北市| 蓬安县| 沅陵县| 石林| 丁青县| 岳西县| 乌鲁木齐县| 阿拉尔市| 长治市| 洪洞县| 炎陵县| 奉化市| 黄浦区| 齐河县| 比如县| 勃利县| 平舆县| 巍山| 香港| 增城市| 嵩明县| 甘泉县| 社会| 会昌县| 陆丰市| 蒙山县| 焦作市| 四子王旗| 屯留县| 类乌齐县| 遵化市| 长武县| 东方市|