{"id":26822,"date":"2021-05-02T23:10:06","date_gmt":"2021-05-03T03:10:06","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/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-programming-code-examples-java-j2e\/"},"modified":"2021-05-02T23:10:06","modified_gmt":"2021-05-03T03:10:06","slug":"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-programming-code-examples-java-j2e","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=26822","title":{"rendered":"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"},"content":{"rendered":"<pre>\n# 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. \n\npackage cwp;\n\nimport java.sql.*;\n\n\/** A JDBC example that connects to either an Oracle or\n *  a Sybase database and prints out the values of\n *  predetermined columns in the &quot;fruits&quot; table.\n *  <p>\n *\/\n\npublic class FruitTest {\n\n  \/** Reads the hostname, database name, username, password,\n   *  and vendor identifier from the command line. It\n   *  uses the vendor identifier to determine which\n   *  driver to load and how to format the URL. The\n   *  driver, URL, username, host, and password are then\n   *  passed to the showFruitTable method.\n   *\/\n  \n  public static void main(String[] args) {\n    if (args.length &lt; 5) {\n      printUsage();\n      return;\n    }\n    String vendorName = args[4];\n    int vendor = DriverUtilities.getVendor(vendorName);\n    if (vendor == DriverUtilities.UNKNOWN) {\n      printUsage();\n      return;\n    }\n    String driver = DriverUtilities.getDriver(vendor);\n    String host = args[0];\n    String dbName = args[1];\n    String url = DriverUtilities.makeURL(host, dbName, vendor);\n    String username = args[2];\n    String password = args[3];\n    showFruitTable(driver, url, username, password);\n  }\n\n  \/** Get the table and print all the values. *\/\n  \n  public static void showFruitTable(String driver,\n                                    String url,\n                                    String username,\n                                    String password) {\n    try {\n      \/\/ Load database driver if not already loaded\n      Class.forName(driver);\n      \/\/ Establish network connection to database\n      Connection connection =\n        DriverManager.getConnection(url, username, password);\n      \/\/ Look up info about the database as a whole.\n      DatabaseMetaData dbMetaData = connection.getMetaData();\n      String productName =\n        dbMetaData.getDatabaseProductName();\n      System.out.println(&quot;Database: &quot; + productName);\n      String productVersion =\n        dbMetaData.getDatabaseProductVersion();\n      System.out.println(&quot;Version: &quot; + productVersion + &quot;n&quot;);\n      System.out.println(&quot;Comparing Apples and Orangesn&quot; +\n                         &quot;============================&quot;);\n      Statement statement = connection.createStatement();\n      String query = &quot;SELECT * FROM fruits&quot;;\n      \/\/ Send query to database and store results\n      ResultSet resultSet = statement.executeQuery(query);\n      \/\/ Look up information about a particular table\n      ResultSetMetaData resultsMetaData =\n        resultSet.getMetaData();\n      int columnCount = resultsMetaData.getColumnCount();\n      \/\/ Column index starts at 1 (ala SQL) not 0 (ala Java).\n      for(int i=1; i&lt;columnCount+1; i++) {\n        System.out.print(resultsMetaData.getColumnName(i) +\n                         &quot;  &quot;);\n      }\n      System.out.println();\n      \/\/ Print results\n      while(resultSet.next()) {\n        \/\/ Quarter\n        System.out.print(&quot;    &quot; + resultSet.getInt(1));\n        \/\/ Num Apples\n        System.out.print(&quot;     &quot; + resultSet.getInt(2));\n        \/\/ Apple Sales\n        System.out.print(&quot;   $&quot; + resultSet.getFloat(3));\n        \/\/ Num Oranges\n        System.out.print(&quot;    &quot; + resultSet.getInt(4));\n        \/\/ Orange Sales\n        System.out.print(&quot;    $&quot; + resultSet.getFloat(5));\n        \/\/ Top Salesman\n        System.out.println(&quot;      &quot; + resultSet.getString(6));\n      }\n    } catch(ClassNotFoundException cnfe) {\n      System.err.println(&quot;Error loading driver: &quot; + cnfe);\n    } catch(SQLException sqle) {\n      System.err.println(&quot;Error connecting: &quot; + sqle);\n    }\n  }\n\n  private static void printUsage() {\n    System.out.println(&quot;Usage: FruitTest host dbName &quot; +\n                       &quot;username password oracle|sybase.&quot;);\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=10200<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># 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. package cwp; import java.sql.*; \/** A JDBC example that connects to either an Oracle or * a Sybase database and prints out the values of * predetermined columns in &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=26822\">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-26822","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":10106,"url":"http:\/\/bangla.sitestree.com\/?p=10106","url_meta":{"origin":26822,"position":0},"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":26826,"url":"http:\/\/bangla.sitestree.com\/?p=26826","url_meta":{"origin":26822,"position":1},"title":"FruitCreation.java:  Creates a simple table named fruits in either an Oracle or a Sybase database. #Programming Code Examples #Java\/J2EE\/J2ME #JDBC","author":"Author-Check- Article-or-Video","date":"May 2, 2021","format":false,"excerpt":"FruitCreation.java Creates a simple table named fruits in either an Oracle or a Sybase database. ************************************** package cwp; import java.sql.*; \/** Creates a simple table named \"fruits\" in either * an Oracle or a Sybase database. * *\/ public class FruitCreation { public static void main(String[] args) { if (args.length\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":10110,"url":"http:\/\/bangla.sitestree.com\/?p=10110","url_meta":{"origin":26822,"position":2},"title":"FruitCreation.java: Creates a simple table named fruits in either an Oracle or a Sybase database.","author":"","date":"August 3, 2015","format":false,"excerpt":"FruitCreation.java Creates a simple table named fruits in either an Oracle or a Sybase database. package cwp; import java.sql.*; \/** Creates a simple table named \"fruits\" in either \u00a0*\u00a0 an Oracle or a Sybase database. \u00a0* \u00a0 \u00a0*\/ public class FruitCreation { \u00a0 public static void main(String[] args) { \u00a0\u00a0\u00a0\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":26846,"url":"http:\/\/bangla.sitestree.com\/?p=26846","url_meta":{"origin":26822,"position":3},"title":"EmployeeTest2.java:  A test case for the database utilities. Prints results formatted as an HTML table. #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.*; \/** Connect to Oracle or Sybase and print \"employees\" table * as an HTML table. * *\/ public class EmployeeTest2 { public static void main(String[] args) { if (args.length < 5) { printUsage(); return; } String vendorName = args[4]; int vendor = DriverUtilities.getVendor(vendorName); if (vendor ==\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":26844,"url":"http:\/\/bangla.sitestree.com\/?p=26844","url_meta":{"origin":26822,"position":4},"title":"EmployeeTest.java:  A test case for the database utilities. Prints results in plain text. #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.*; \/** Connect to Oracle or Sybase and print \"employees\" table. * *\/ public class EmployeeTest { public static void main(String[] args) { if (args.length < 5) { printUsage(); return; } String vendorName = args[4]; int vendor = DriverUtilities.getVendor(vendorName); if (vendor == DriverUtilities.UNKNOWN) { printUsage(); return; }\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":26850,"url":"http:\/\/bangla.sitestree.com\/?p=26850","url_meta":{"origin":26822,"position":5},"title":"QueryViewer.java: An interactive database query viewer #Programming Code Examples #Java\/J2EE\/J2ME #JDBC","author":"Author-Check- Article-or-Video","date":"May 3, 2021","format":false,"excerpt":"# QueryViewer.java An interactive database query viewer. Connects to the specified Oracle or Sybase database, executes a query, and presents the results in a JTable. Uses the following file: * DBResultsTableModel.java Simple class that tells a JTable how to extract relevant data from a DBResults object (which is used to\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":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26822","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=26822"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26822\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26822"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}