{"id":495,"date":"2012-06-07T17:06:07","date_gmt":"2012-06-07T17:06:07","guid":{"rendered":"http:\/\/shivdev.com\/blog\/?p=495"},"modified":"2012-06-07T17:08:27","modified_gmt":"2012-06-07T17:08:27","slug":"get-the-schemametadata-out-of-a-sql-query-without-executing-it","status":"publish","type":"post","link":"http:\/\/shivdev.com\/blog\/2012\/06\/07\/get-the-schemametadata-out-of-a-sql-query-without-executing-it\/","title":{"rendered":"Get the Schema\/Metadata out of a SQL Query without executing it"},"content":{"rendered":"<p>You can use <a href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/java\/sql\/PreparedStatement.html\">PreparedStatement<\/a> to compile the SQL and then get the <a href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/java\/sql\/ResultSetMetaData.html\">ResultSetMetaData <\/a>from it.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/\/ Get the Connection\r\nConnection conn = getConnection();\r\n\r\n\/\/ Get the MetaData\r\nPreparedStatement ps = conn.prepareStatement(sql);\r\nResultSetMetaData rsmd = ps.getMetaData();\r\n\r\n\/\/ Get the alias &amp; type\r\nfor (int i=0; i&lt;rsmd.getColumnCount(); i++) {\r\n   String alias = rsmd.getColumnName(i+1);\r\n   String strType = rsmd.getColumnTypeName(i+1);\r\n   int type = rsmd.getColumnType(i+1)\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You can use PreparedStatement to compile the SQL and then get the ResultSetMetaData from it.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,6],"tags":[],"_links":{"self":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/495"}],"collection":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/comments?post=495"}],"version-history":[{"count":5,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/495\/revisions"}],"predecessor-version":[{"id":500,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/495\/revisions\/500"}],"wp:attachment":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/media?parent=495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/categories?post=495"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/tags?post=495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}