2016-12-12 7 views
0

jdbcを使用してteradataからメタデータフェッチを実行していますが、すべてのデータ型を取得したいと考えています。しかし、DECIMAL(10,4)を含むDBフィールドの場合、精度を得ることができません。コードスニペットを添付しています。提案は大歓迎です!JDBCメタデータフェッチ10進精度

DatabaseMetaData md = con.getMetaData(); 

    ResultSet tbls = md.getTables(null, schema, name, null); 
      if(false == tbls.next()){ 
       nonExistingRdbmsTables.add(name); 
       LOGGER.error("Table with name {} in schema {} does not exists in source database", name, schema); 
       continue; 
      } 

      RdbmsTableMetadata tableMD = new RdbmsTableMetadata(); 
      List<String> pkList = new ArrayList(); 
      ResultSet primaryKeys = md.getPrimaryKeys(null, schema, name); 
      while(primaryKeys.next()){ 
       String pk = primaryKeys.getString("COLUMN_NAME"); 
       pkList.add(pk); 
      } 
      tableMD.setPkList(pkList); 
      LOGGER.info("*****Primary key list for table {} is {}", name, pkList); 

      tableMD.setSchema(schema); 
      tableMD.setName(name); 
      tableMD.setTargetName(targetName); 
      tableMD.setTargetSchema(targetSchema); 
      List<Column> colList = new ArrayList<>(); 

      ResultSet cols = md.getColumns(null, schema, name, null); 
      while (cols.next()) { 
       String columnName = cols.getString("COLUMN_NAME"); 
       String columnType = cols.getString("TYPE_NAME"); 
       String columnLength = cols.getString("COLUMN_SIZE"); 
} 

jdbcメタデータから精度の詳細を問い合せる方法はありますか?

+0

どのDBMSを使用していますか?また、 'cols.getInt(" DECIMAL_DIGITS ")'はあなたに何を提供しますか? –

+0

'COLUMN_SIZE'と' DECIMAL_DIGITS'にはどんな価値がありますか? –

+0

DECIMAL_DIGITSは正常に機能します。みんなありがとう!これは私の情報スキーマをよく知らないために得られるものです! – Ayon

答えて

0

ResultSetMetaDataは、getScale(int col)およびgetPrecision(int col)の方法を提供する。それらがあなたが望むものをあなたに与えないなら、おそらくあなたは運が悪いでしょう。将来referencersについては

+0

これは、関心のある列を持つテーブルに開いている 'ResultSet'を必要とします。 –

+0

結果セットを開くのは好きではありません。他の理由から、私はDataBaseメタデータを使うことに決めました。これを再エンジニアリングする他の方法はありますか? – Ayon

2

: -

int precision = cols.getInt("DECIMAL_DIGITS"); 

これがうまく働きました!アレックスとマークのおかげです。

関連する問題