code_junkie

Is there a way to get types/names of an unknown db query without executing it?

Nov 11th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import java.sql.*;
  2. . . .
  3. Connection conn;
  4. . . .
  5. PreparedStatement ps = conn.prepareStatement("SELECT * FROM foo");
  6. ResultSetMetadata rsmd = ps.getMetaData();
  7. int numberOfColumns = rsmd.getColumnCount();
  8.  
  9. DECLARE
  10. lv_stat varchar2(100) := 'select blah blah blah';
  11. lv_cur INTEGER;
  12. lv_col_cnt INTEGER;
  13. lv_desc DBMS_SQL.desc_tab;
  14. BEGIN
  15. DBMS_SQL.parse(lv_cur,lv_stat,DBMS_SQL.NATIVE);
  16. DBMS_SQL.describe_columns(lv_cur,lv_col_cnt,lv_desc);
  17. FOR ndx in lv_desc.FIRST .. lv_desc.LAST LOOP
  18. DBMS_OUTPUT.PUT_LINE(lv_desc(ndx).col_name ||' '||lv_desc(ndx).col_type);
  19. END LOOP;
  20. END;
Add Comment
Please, Sign In to add comment