{"id":416,"date":"2012-12-26T02:09:29","date_gmt":"2012-12-26T02:09:29","guid":{"rendered":"http:\/\/codeatelier.wordpress.com\/?p=416"},"modified":"2012-12-26T02:09:29","modified_gmt":"2012-12-26T02:09:29","slug":"executing-a-select-statement-in-java","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/executing-a-select-statement-in-java\/","title":{"rendered":"Executing a Select statement in Java"},"content":{"rendered":"<pre>\n public class JAVADB2\n {\n   public static void main(String args[]) throws SQLException \n   {\t\n     try\t\n     {\n\tConnection conn = null;\t\t\n\tResultSet  rs \t= null;\n\tStatement  stmt\t= null;\n\t\t\t\n\tString strSQL = \"SELECT * FROM employee\";\n\tconn = incDB.getConnection();\n\tstmt = (Statement)conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.FETCH_FORWARD);\t\t\t\n\t\t\t\n \trs = stmt.executeQuery(strSQL);\t\t\t\n\tdisplay.getRecords(rs);\n      } \n      catch (SQLException e) \n      {\n\tincDB.getException(e);\n      }\n    }\t\n}\nUtility Methods\n<pre>\n public class incDB\n{\t\n\tprivate static String USER_NAME = \"root\";\n\tprivate static String USER_PASS = \"pass\";\n\tprivate static String CONN_STRING = \"jdbc:mysql:\/\/localhost\/test\";\n\t\n\tpublic static Connection getConnection() throws SQLException\n\t{\n\t\treturn DriverManager.getConnection(CONN_STRING, USER_NAME, USER_PASS);\n\t}\n\t\n\tpublic static void getException(SQLException e)\n\t{\n\t\tSystem.out.println(\"Message :\"+e.getMessage());\n\t\tSystem.out.println(\"Error Code :\"+e.getErrorCode());\n\t\tSystem.out.println(\"State : \"+e.getSQLState());\n\t}\n}\n\npublic class incDB\n{\t\n\tprivate static String USER_NAME = \"root\";\n\tprivate static String USER_PASS = \"\";\n\tprivate static String CONN_STRING = \"jdbc:mysql:\/\/localhost\/test\";\n\t\n\tpublic static Connection getConnection() throws SQLException\n\t{\n\t\treturn DriverManager.getConnection(CONN_STRING, USER_NAME, USER_PASS);\n\t}\n\t\n\tpublic static void getException(SQLException e)\n\t{\n\t\tSystem.out.println(\"Message :\"+e.getMessage());\n\t\tSystem.out.println(\"Error Code :\"+e.getErrorCode());\n\t\tSystem.out.println(\"State : \"+e.getSQLState());\n\t}\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>public class JAVADB2 { public static void main(String args[]) throws SQLException { try { Connection conn = null; ResultSet rs = null; Statement stmt = null; String strSQL = &#8220;SELECT * FROM employee&#8221;; conn = incDB.getConnection(); stmt = (Statement)conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.FETCH_FORWARD); rs = stmt.executeQuery(strSQL); display.getRecords(rs); } catch (SQLException e) { incDB.getException(e); } } } Utility Methods&hellip; <a href=\"https:\/\/codethataint.com\/blog\/executing-a-select-statement-in-java\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[],"class_list":["post-416","post","type-post","status-publish","format-standard","hentry","category-database","category-java"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=416"}],"version-history":[{"count":0,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/416\/revisions"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}