Get the Schema/Metadata out of a SQL Query without executing it
Writing by shivdev on Thursday, 7 of June , 2012 at 5:06 pm
You can use PreparedStatement to compile the SQL and then get the ResultSetMetaData from it.
// Get the Connection Connection conn = getConnection(); // Get the MetaData PreparedStatement ps = conn.prepareStatement(sql); ResultSetMetaData rsmd = ps.getMetaData(); // Get the alias & type for (int i=0; i<rsmd.getColumnCount(); i++) { String alias = rsmd.getColumnName(i+1); String strType = rsmd.getColumnTypeName(i+1); int type = rsmd.getColumnType(i+1) }
Leave a comment
- Add this post to
- Del.icio.us -
- Digg -
- -
- Tweet -
-
-