How to get table metadata without sql-statement invoking
2011-08-30 15:14
232 查看
You may use the connection and table name (and column name) to retrieve the meta-data information from the database.
E.g.
/**
* Get meta data of columns via table name
* @param conn database connection
* @param tablename
* @return
* @throws SQLException
*/
// private ResultSet getColumnMetaData(Connection conn, String tablename) throws SQLException
// {
// DatabaseMetaData dmeta = conn.getMetaData();
// return dmeta.getColumns(null, null, tablename, "%");
// }
/**
* Get the field type according to field name
*
* @param cMetaSet
* @param fieldname
* @return
* @throws SQLException
*/
// private int getFieldType(CachedRowSet cMetaSet, String fieldname) throws SQLException
// {
// ResultSet rs = cMetaSet.createCopyNoConstraints();
//
// while (rs.next())
// {
// if (fieldname.equalsIgnoreCase(rs.getString(4)))
// {
// return rs.getInt(5);
// }
// }
//
// throw new SQLException("Can not find the field in the target table : " + fieldname);
// }
/**
* Get the field type according to its index
*
* @param cMetaSet
* @param fldIndex
* @return
* @throws SQLException
*/
// private int getFieldType(CachedRowSet cMetaSet, int fldIndex) throws SQLException
// {
// int index = 0;
// ResultSet rs = cMetaSet.createCopyNoConstraints();
//
// while (rs.next())
// {
// if (fldIndex == index)
// {
// return rs.getInt(5);
// }
// index++;
// }
//
// throw new SQLException("Fields in sql statement is more than the target table");
// }
E.g.
/**
* Get meta data of columns via table name
* @param conn database connection
* @param tablename
* @return
* @throws SQLException
*/
// private ResultSet getColumnMetaData(Connection conn, String tablename) throws SQLException
// {
// DatabaseMetaData dmeta = conn.getMetaData();
// return dmeta.getColumns(null, null, tablename, "%");
// }
/**
* Get the field type according to field name
*
* @param cMetaSet
* @param fieldname
* @return
* @throws SQLException
*/
// private int getFieldType(CachedRowSet cMetaSet, String fieldname) throws SQLException
// {
// ResultSet rs = cMetaSet.createCopyNoConstraints();
//
// while (rs.next())
// {
// if (fieldname.equalsIgnoreCase(rs.getString(4)))
// {
// return rs.getInt(5);
// }
// }
//
// throw new SQLException("Can not find the field in the target table : " + fieldname);
// }
/**
* Get the field type according to its index
*
* @param cMetaSet
* @param fldIndex
* @return
* @throws SQLException
*/
// private int getFieldType(CachedRowSet cMetaSet, int fldIndex) throws SQLException
// {
// int index = 0;
// ResultSet rs = cMetaSet.createCopyNoConstraints();
//
// while (rs.next())
// {
// if (fldIndex == index)
// {
// return rs.getInt(5);
// }
// index++;
// }
//
// throw new SQLException("Fields in sql statement is more than the target table");
// }
相关文章推荐
- How To determine DDIC Check Table, Domain and Get Table Field Text Data For Value?
- Beginning MyBatis 3 Part 3 : How to Get Table’s Generated Ids
- How To determine DDIC Check Table, Domain and Get Table Field Text Data For Value?
- How to get MetaData on client side in WCF?如何在客户端获取WCF service的元数据
- Oracle table fragmentation how to calculate or get the actual used blocks of the table
- How to get the field descriptions of a table?
- How to get the field descriptions of a table?
- How to Get Table’s Generated Ids
- How to get the field descriptions of a table
- How to get the mapping relationship between two columns in a table
- How to Get the Frequency Table of a Categorical Variable as a Data Frame in R
- How to get a handle to a device driver returned by device manager?
- How to Add Route to TCP/IP Routing Table With Windows Routing And Remote Access Console or DOS Promp
- how to get MMC recoverd tools.
- How to get the MouseEvent coordinates for an element that has CSS3 Transform?
- How to Use Oradebug to Get Trace File Name and Location
- How to Create a User Defined Table
- How to get primary key column in Oracle?
- How to update multiple columns of one table using values from another table?
- How to get the Current Controller Name, Action, or ID in ASP.NET MVC