File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting column type info from db

 
Bobby Anderson
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get the java.sql.Types info from the DB for a given column name.

is this really the best way to do this:

DatabaseMetaData dbMeta = conn.getMetaData();
ResultSet cols = dbMeta.getColumns(null, null, tablename, columnname);
ResultSetMetaData rsMeta = cols.getMetaData();
int colType = rsMeta.getColumnType(0); // Hopefully only have one row

This seems very ugly! Is there an easier way. I am also not checking for null objects along the way which I should probably do which would make this more ugly.

Any ideas?

Thanks,
Billy
 
Vinod K Singh
Ranch Hand
Posts: 198
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ResultSetMetaData is the standard way to get such information. BTW indexes start from 1 not from 0.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic