Top / JDBC カラム一覧を得る
文字列の
PerlのSQLiteのサンプルコードを参考にする
http://cpansearch.perl.org/src/ADAMK/DBD-SQLite-1.29/lib/DBD/SQLite.pm
TABLE_CAT TABLE_SCHEM TABLE_NAME COLUMN_NAME DATA_TYPE TYPE_NAME COLUMN_SIZE BUFFER_LENGTH DECIMAL_DIGITS NUM_PREC_RADIX NULLABLE REMARKS COLUMN_DEF SQL_DATA_TYPE SQL_DATETIME_SUB CHAR_OCTET_LENGTH ORDINAL_POSITION IS_NULLABLE
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/db2/rbafzmstcatalogodbc.htm
http://code.google.com/p/rubeus/source/browse/trunk/lib/rubeus/jdbc/column.rb?r=237
http://msdn.microsoft.com/ja-jp/library/cc668760.aspx
http://software.fujitsu.com/jp/manual/manualfiles/M100006/J2X02268/09Z202/J2268-e-03-04.html
http://d.hatena.ne.jp/miyohide/20100317
package base; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class HelloColumnList { public static void main(String[] args) { try { // ドライバクラスをロード Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // データベースへ接続 Connection con = DriverManager.getConnection("jdbc:odbc:helloworld"); // ステートメントオブジェクトを生成 Statement stmt = con.createStatement(); DatabaseMetaData dmd = con.getMetaData(); ResultSet rs = null; rs = dmd.getColumns(null, null,"HELLO_WORLD_TABLE",null); try { while(rs.next()){ System.out.println(rs.getString("COLUMN_NAME") + "\n"); } } finally { rs.close(); } stmt.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } } }
package base; import java.sql.ResultSet; import java.sql.SQLException; /**<P> * 検索結果に格納されたカラム情報の結果をキーからJavaのシンボルに切り替える * </P> */ public class ColumnUtil { //TABLE_CAT public static String getTABLE_CAT(ResultSet rsColumns) throws SQLException{ return rsColumns.getString("TABLE_CAT"); } //TABLE_SCHEM public static String getTABLE_SCHEM(ResultSet rsColumns) throws SQLException{ return rsColumns.getString("TABLE_SCHEM"); } //TABLE_NAME public static String getTABLE_NAME(ResultSet rsColumns) throws SQLException{ return rsColumns.getString("TABLE_NAME"); } //COLUMN_NAME public static String getCOLUMN_NAME(ResultSet rsColumns) throws SQLException{ return rsColumns.getString("COLUMN_NAME"); } //DATA_TYPE public static int getDATA_TYPE(ResultSet rsColumns) throws SQLException{ return rsColumns.getInt("DATA_TYPE"); } //TYPE_NAME public static String getTYPE_NAME(ResultSet rsColumns) throws SQLException{ return rsColumns.getString("TYPE_NAME"); } //COLUMN_SIZE public static int getCOLUMN_SIZE(ResultSet rsColumns) throws SQLException{ return rsColumns.getInt("COLUMN_SIZE"); } //BUFFER_LENGTH public static int getBUFFER_LENGTH(ResultSet rsColumns) throws SQLException{ return rsColumns.getInt("BUFFER_LENGTH"); } //DECIMAL_DIGITS public static int getDECIMAL_DIGITS(ResultSet rsColumns) throws SQLException{ return rsColumns.getInt("DECIMAL_DIGITS"); } //NUM_PREC_RADIX public static int getNUM_PREC_RADIX(ResultSet rsColumns) throws SQLException{ return rsColumns.getInt("NUM_PREC_RADIX"); } //NULLABLE public static int getNULLABLE(ResultSet rsColumns) throws SQLException{ return rsColumns.getInt("NULLABLE"); } //REMARKS public static String getREMARKS(ResultSet rsColumns) throws SQLException{ return rsColumns.getString("REMARKS"); } //COLUMN_DEF public static String getCOLUMN_DEF(ResultSet rsColumns) throws SQLException{ return rsColumns.getString("COLUMN_DEF"); } //SQL_DATA_TYPE public static int getSQL_DATA_TYPE(ResultSet rsColumns) throws SQLException{ return rsColumns.getInt("SQL_DATA_TYPE"); } //SQL_DATETIME_SUB public static int getSQL_DATETIME_SUB(ResultSet rsColumns) throws SQLException{ return rsColumns.getInt("SQL_DATETIME_SUB"); } //CHAR_OCTET_LENGTH public static int getCHAR_OCTET_LENGTH(ResultSet rsColumns) throws SQLException{ return rsColumns.getInt("CHAR_OCTET_LENGTH"); } //ORDINAL_POSITION public static int getORDINAL_POSITION(ResultSet rsColumns) throws SQLException{ return rsColumns.getInt("ORDINAL_POSITION"); } //IS_NULLABLE public static String getIS_NULLABLE(ResultSet rsColumns) throws SQLException{ return rsColumns.getString("IS_NULLABLE"); } //JDBC_DATA_TYPE public static int getJDBC_DATA_TYPE(ResultSet rsColumns) throws SQLException{ return rsColumns.getInt("JDBC_DATA_TYPE"); } //PSEUDO_COLUMN public static int getPSEUDO_COLUMN(ResultSet rsColumns) throws SQLException{ return rsColumns.getInt("PSEUDO_COLUMN"); } //COLUMN_TEXT public static String getCOLUMN_TEXT(ResultSet rsColumns) throws SQLException{ return rsColumns.getString("COLUMN_TEXT"); } }