{"id":1683,"date":"2011-10-19T17:00:44","date_gmt":"2011-10-19T22:00:44","guid":{"rendered":"http:\/\/www.mrc-productivity.com\/docs\/?page_id=1683"},"modified":"2023-03-28T13:08:55","modified_gmt":"2023-03-28T18:08:55","slug":"sample-external-object-java-source-code","status":"publish","type":"ht_kb","link":"https:\/\/www.mrc-productivity.com\/docs\/knowledge-base\/sample-external-object-java-source-code","title":{"rendered":"Sample External Object (Java) Source Code"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Sample Source Code<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package MRCWORKLIB;\n\nimport java.sql.Connection;\nimport java.sql.ResultSet;\nimport java.sql.SQLException;\nimport java.sql.Statement;\n\nimport org.apache.log4j.Logger;\n\nimport com.mrc.dbo.MrcConnection;\n\/**\n * Delete Order # from MRCWORKLIB.ORDDET\n * 2011-09-22\n * @author RH\n *\n * 2. Define external object\n *\n * Class Name: MRCWORKLIB.DELDETAIL\n * Method Name: run\n * Then define one object parm to pass Order number\n * 3. Use this object in your servlet application\n *\n *\/\npublic class DELDETAIL {\n\n  private Logger log = Logger.getLogger(this.getClass());\n\n  \/****************************************************\n   * Delete from MRCWORKLIB.ORDDET\n   ****************************************************\/\n  public void run(String&#91;] str) {\n\n    if (str.length &lt; 1) {\n      log.info(\"Must pass Order #.\");\n      return;\n    }\n    int ordno = 0;\n    try {\n      ordno = Integer.parseInt(str&#91;0]);\n    } catch (Exception e) {\n      log.info(\"Invalid Order # passed.\");\n      return;\n    }\n    String sql = \"DELETE FROM MRCWORKLIB.ORDERDET where ONUM=\" + ordno;\n    Connection conn = null;\n    try {\n      \/\/Get connection configured in m-power\/mrcjava\/web-inf\/classes\/spring-config.xml                         \n\n      conn = MrcConnection.getConnection(\"as400_remote1\");\n      Statement stmt = conn.createStatement();\n      int deleted = stmt.executeUpdate(sql);\n      log.info(deleted + \" records deleted.\");\n      stmt.close();\n    } catch (SQLException sqle) {\n      log.error(\"sql = \" + sql, sqle);\n    } finally {\n      try {\n        conn.close();\n      } catch (Exception e) {\n        e.printStackTrace();\n      }\n    }\n  } \/****************************************************          * Test          ****************************************************\/\n  public static void main(String&#91;] str) {\n    DELDETAIL delete = new DELDETAIL();\n    String&#91;] str0 = {\n      \"2\"\n    };\n    delete.run(str0);\n  }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sample Source Code<\/p>\n","protected":false},"author":1,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[],"ht-kb-tag":[],"class_list":["post-1683","ht_kb","type-ht_kb","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/comments?post=1683"}],"version-history":[{"count":5,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1683\/revisions"}],"predecessor-version":[{"id":12355,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1683\/revisions\/12355"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/media?parent=1683"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb-category?post=1683"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb-tag?post=1683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}