{"id":26830,"date":"2021-05-02T23:10:06","date_gmt":"2021-05-03T03:10:06","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/dbresults-java-class-to-store-completed-results-of-a-jdbc-query-differs-from-a-resultset-in-several-ways-programming-code-examples-java-j2ee-j2me-jdbc\/"},"modified":"2021-05-02T23:10:06","modified_gmt":"2021-05-03T03:10:06","slug":"dbresults-java-class-to-store-completed-results-of-a-jdbc-query-differs-from-a-resultset-in-several-ways-programming-code-examples-java-j2ee-j2me-jdbc","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=26830","title":{"rendered":"DBResults.java: Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways #Programming Code Examples #Java\/J2EE\/J2ME #JDBC"},"content":{"rendered":"<pre>\n\n# DBResults.java  Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways:\n\n    * ResultSet doesn?t necessarily have all the data; reconnection to database occurs as you ask for later rows.\n    * This class stores results as strings, in arrays.\n    * This class includes DatabaseMetaData (database product name and version) and ResultSetMetaData (the column names).\n    * This class has a toHTMLTable method that turns the results into a long string corresponding to an HTML table. \n\n\n\n\npackage cwp;\n\nimport java.sql.*;\nimport java.util.*;\n\n\/** Class to store completed results of a JDBC Query.\n *  Differs from a ResultSet in several ways:\n *  <ul>\n *    <li>ResultSet doesn't necessarily have all the data;\n *        reconnection to database occurs as you ask for\n *        later rows.\n *    <\/li><li>This class stores results as strings, in arrays.\n *    <\/li><li>This class includes DatabaseMetaData (database product\n *        name and version) and ResultSetMetaData\n *        (the column names).\n *    <\/li><li>This class has a toHTMLTable method that turns\n *        the results into a long string corresponding to\n *        an HTML table.\n *  <\/li><\/ul>\n *  <p>\n *\/\n\npublic class DBResults {\n  private Connection connection;\n  private String productName;\n  private String productVersion;\n  private int columnCount;\n  private String[] columnNames;\n  private Vector queryResults;\n  String[] rowData;\n\n  public DBResults(Connection connection,\n                   String productName,\n                   String productVersion,\n                   int columnCount,\n                   String[] columnNames) {\n    this.connection = connection;\n    this.productName = productName;\n    this.productVersion = productVersion;\n    this.columnCount = columnCount;\n    this.columnNames = columnNames;\n    rowData = new String[columnCount];\n    queryResults = new Vector();\n  }\n\n  public Connection getConnection() {\n    return(connection);\n  }\n  \n  public String getProductName() {\n    return(productName);\n  }\n\n  public String getProductVersion() {\n    return(productVersion);\n  }\n\n  public int getColumnCount() {\n    return(columnCount);\n  }\n\n  public String[] getColumnNames() {\n    return(columnNames);\n  }\n\n  public int getRowCount() {\n    return(queryResults.size());\n  }\n\n  public String[] getRow(int index) {\n    return((String[])queryResults.elementAt(index));\n  }\n\n  public void addRow(String[] row) {\n    queryResults.addElement(row);\n  }\n\n  \/** Output the results as an HTML table, with\n   *  the column names as headings and the rest of\n   *  the results filling regular data cells.\n   *\/\n  \n  public String toHTMLTable(String headingColor) {\n    StringBuffer buffer =\n      new StringBuffer(&quot;<table BORDER=\"1\">n&quot;);\n    if (headingColor != null) {\n      buffer.append(&quot;  <tr BGCOLOR=\"&quot;&quot;\">n    &quot;);\n    } else {\n      buffer.append(&quot;  <\/tr><tr>n    &quot;);\n    }\n    for(int col=0; col&lt;getcolumncount (); col++) {\n      buffer.append(&quot;<th>&quot; + columnNames[col]);\n    }\n    for(int row=0; row&lt;getrowcount (); row++) {\n      buffer.append(&quot;n  <tr>n    &quot;);\n      String[] rowData = getRow(row);\n      for(int col=0; col&lt;getcolumncount (); col++) {\n        buffer.append(&quot;<td>&quot; + rowData[col]);\n      }\n    }\n    buffer.append(&quot;n<\/td><\/tr><\/th><\/tr><\/table>&quot;);\n    return(buffer.toString());\n  } \n}\n    \n  \n<\/p><\/pre>\n<p>Note: Brought from our old site: http:\/\/www.salearningschool.com\/example_codes\/ on Jan 2nd, 2017 From: http:\/\/sitestree.com\/?p=10204<br \/> Categories:Programming Code Examples, Java\/J2EE\/J2ME, JDBC<br \/>Tags:Java\/J2EE\/J2MEJDBC<br \/> Post Data:2017-01-02 16:04:23<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p># DBResults.java Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways: * ResultSet doesn?t necessarily have all the data; reconnection to database occurs as you ask for later rows. * This class stores results as strings, in arrays. * This class includes DatabaseMetaData (database product name and version) &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=26830\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-26830","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10116,"url":"http:\/\/bangla.sitestree.com\/?p=10116","url_meta":{"origin":26830,"position":0},"title":"DBResults.java: Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways","author":"","date":"August 5, 2015","format":false,"excerpt":"# DBResults.java\u00a0 Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways: \u00a0\u00a0\u00a0 * ResultSet doesn?t necessarily have all the data; reconnection to database occurs as you ask for later rows. \u00a0\u00a0\u00a0 * This class stores results as strings, in arrays. \u00a0\u00a0\u00a0 * This\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26854,"url":"http:\/\/bangla.sitestree.com\/?p=26854","url_meta":{"origin":26830,"position":1},"title":"PreparedStatements.java  An example to test the timing differences resulting from repeated raw queries vs. repeated calls #Programming Code Examples #Java\/J2EE\/J2ME #JDBC","author":"Author-Check- Article-or-Video","date":"May 3, 2021","format":false,"excerpt":"package cwp; import java.sql.*; \/** An example to test the timing differences resulting * from repeated raw queries vs. repeated calls to * prepared statements. These results will vary dramatically * among database servers and drivers. With my setup * and drivers, Oracle prepared statements took only half * the\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26822,"url":"http:\/\/bangla.sitestree.com\/?p=26822","url_meta":{"origin":26830,"position":2},"title":"FruitTest.java:  A class that connects to either an Oracle or a Sybase database and prints out the values of predetermined columns in the &quot;fruits&quot; table. #Programming Code Examples #Java\/J2EE\/J2ME #JDBC","author":"Author-Check- Article-or-Video","date":"May 2, 2021","format":false,"excerpt":"# FruitTest.java A class that connects to either an Oracle or a Sybase database and prints out the values of predetermined columns in the \"fruits\" table. package cwp; import java.sql.*; \/** A JDBC example that connects to either an Oracle or * a Sybase database and prints out the values\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10106,"url":"http:\/\/bangla.sitestree.com\/?p=10106","url_meta":{"origin":26830,"position":3},"title":"FruitTest.java: A class that connects to either an Oracle or a Sybase database and prints out the values of predetermined columns in the &#8220;fruits&#8221; table.","author":"","date":"August 2, 2015","format":false,"excerpt":"# FruitTest.java\u00a0 A class that connects to either an Oracle or a Sybase database and prints out the values of predetermined columns in the \"fruits\" table. package cwp; import java.sql.*; \/** A JDBC example that connects to either an Oracle or \u00a0*\u00a0 a Sybase database and prints out the values\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26828,"url":"http:\/\/bangla.sitestree.com\/?p=26828","url_meta":{"origin":26830,"position":4},"title":"DatabaseUtilities.java: Several general-purpose utilities discussed and used in the chapter. #Programming Code Examples #Java\/J2EE\/J2ME #JDBC","author":"Author-Check- Article-or-Video","date":"May 2, 2021","format":false,"excerpt":"package cwp; import java.sql.*; \/** Three database utilities: * 1) getQueryResults. Connects to a database, executes * a query, retrieves all the rows as arrays * of strings, and puts them inside a DBResults * object. Also places the database product name, * database version, and the names of all\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":76673,"url":"http:\/\/bangla.sitestree.com\/?p=76673","url_meta":{"origin":26830,"position":5},"title":"Connect to Sql Server FROM JAVA","author":"Sayed","date":"April 3, 2025","format":false,"excerpt":"https:\/\/learn.microsoft.com\/en-us\/sql\/connect\/jdbc\/connection-url-sample?view=sql-server-ver16 import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class ConnectURL { public static void main(String[] args) { \/\/ Create a variable for the connection string. String connectionUrl = \"jdbc:sqlserver:\/\/<server>:<port>;encrypt=true;databaseName=AdventureWorks;user=<user>;password=<password>\"; try (Connection con = DriverManager.getConnection(connectionUrl); Statement stmt = con.createStatement();) { String SQL = \"SELECT TOP 10 *\u2026","rel":"","context":"In &quot;Root&quot;","block_context":{"text":"Root","link":"http:\/\/bangla.sitestree.com\/?cat=1"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26830","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26830"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26830\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26830"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}