{"id":411,"date":"2012-07-29T21:29:57","date_gmt":"2012-07-29T15:59:57","guid":{"rendered":"http:\/\/ramkulkarni.com\/blog\/?p=411"},"modified":"2012-07-29T21:29:57","modified_gmt":"2012-07-29T15:59:57","slug":"developing-database-applications-with-webapprunner","status":"publish","type":"post","link":"http:\/\/ramkulkarni.com\/blog\/developing-database-applications-with-webapprunner\/","title":{"rendered":"Developing Database Applications with WebAppRunner"},"content":{"rendered":"<p><a href=\"http:\/\/ramkulkarni.com\/blog\/webapprunner-run-your-web-applications-standalone\">WebAppRunner<\/a> is the Eclipse RCP application I created to run web applications as standalone desktop applications. I had explained earlier how this application could be used by creating a demo <a href=\"http:\/\/ramkulkarni.com\/MyApps\/WebAppRunner\/SampleApps\/FileListApp.zip\" target=\"_blank\">FileList<\/a> application. In this post I am going to show how WebAppRunner can be used to create Database applications.<\/p>\n<p>I have created a demo application, <a href=\"http:\/\/ramkulkarni.com\/MyApps\/WebAppRunner\/SampleApps\/SQLiteApp.zip\">SQLiteApp<\/a>.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/138.197.85.232\/blog\/wp-content\/uploads\/2012\/07\/SQLiteDemoApp.jpg\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"412\" data-permalink=\"http:\/\/ramkulkarni.com\/blog\/developing-database-applications-with-webapprunner\/sqlitedemoapp\/\" data-orig-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2012\/07\/SQLiteDemoApp.jpg?fit=605%2C303\" data-orig-size=\"605,303\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"SQLiteDemoApp\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2012\/07\/SQLiteDemoApp.jpg?fit=300%2C150\" data-large-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2012\/07\/SQLiteDemoApp.jpg?fit=525%2C263\" class=\"alignnone size-medium wp-image-412\" title=\"SQLiteDemoApp\" src=\"https:\/\/i0.wp.com\/138.197.85.232\/blog\/wp-content\/uploads\/2012\/07\/SQLiteDemoApp-300x150.jpg?resize=300%2C150\" alt=\"\" width=\"300\" height=\"150\" srcset=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2012\/07\/SQLiteDemoApp.jpg?resize=300%2C150 300w, https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2012\/07\/SQLiteDemoApp.jpg?w=605 605w\" sizes=\"(max-width: 300px) 100vw, 300px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p><!--more--><\/p>\n<p>This is a simple application that allows CRUD operations on a simple Employee table. User interface for this application is created using HTML\/JS. The database APIs are implemented in empDBManager.jar included in <a href=\"http:\/\/ramkulkarni.com\/MyApps\/WebAppRunner\/SampleApps\/SQLiteApp.zip\">SQLiteApp.zip<\/a>. To see how this application works, execute it by passing path of this Zip file to WebAppRunner. &#8216;Open DB&#8217; allows you to open existing SQLite (employee) database. Click &#8216;Create DB&#8217; to create a new employee database. Click &#8216;Add&#8217; button to add a new employee record.<\/p>\n<p>I have made a few changes to WebAppRunner.<\/p>\n<ul>\n<li>I have added three new APIs in WebAppRunner.\n<ul>\n<li>setJavaProperty : To set value of a public field of Java object<\/li>\n<li>getApplicationPath : To get path of the application that is opened in the WebAppRunner<\/li>\n<li>exitWebAppRunner : To exit WebAppRunner<\/li>\n<\/ul>\n<\/li>\n<li>Objects created\/retrieved with Java APIs for WebAppRunner can now be passed as arguments by prefixing $ to the variable name.<\/li>\n<li>You can specify if menu bar of WebAppRunner be displayed by specifying Show-Menubar: false\/true in the application&#8217;s manifest.mf<\/li>\n<\/ul>\n<p>I have updated <a href=\"http:\/\/ramkulkarni.com\/blog\/webapprunner-run-your-web-applications-standalone\">WebAppRunner post<\/a> with detailed description of above changes. I have also uploaded the new version (1.1 Beta) of WebAppRunner with these changes at the same locations &#8211;<\/p>\n<ul>\n<li><a href=\"http:\/\/ramkulkarni.com\/MyApps\/WebAppRunner\/WebAppRunner-Windows.zip\">WebAppRunner (Windows)<\/a><\/li>\n<li><a href=\"http:\/\/ramkulkarni.com\/MyApps\/WebAppRunner\/WebAppRunner-Mac.zip\" target=\"_blank\">WebAppRunner (Mac)<\/a><\/li>\n<\/ul>\n<h3>Packaging of Java APIs for SQLiteApp<\/h3>\n<p>As mentioned earlier, Java classes to create SQLite DB and perform CRUD operations are in empDBManager.jar. This jar is packaged in the root of application zip. So you don&#8217;t need to specify extra Classpath in manifest.mf. All jars in the root of application folder are loaded. I have included Java source code also in this jar and also uploaded as <a href=\"http:\/\/ramkulkarni.com\/MyApps\/WebAppRunner\/SampleApps\/empDBManager-src.zip\">empDBManager-src.zip<\/a><\/p>\n<p>SQLite JDBC driver is in sqlitejdbc-v056.jar, which is also packaged in the application zip file. Classes in empDBManager use this JDBC driver.<\/p>\n<h3>Calling Java APIs for SQLite Database operations<\/h3>\n<p>Take a look at emp.js (again, in SQLiteApp,zip) to see how Database APIs in empDBManager.jar are called.<\/p>\n<p>First, get path of the application (zip\/folder)<\/p>\n<pre style=\"color: #000020; background: #f6f8ff;\">appPath <span style=\"color: #308080;\">=<\/span> getApplicationPath<span style=\"color: #308080;\">(<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span><\/pre>\n<p>Next, if database file path is saved from the previous session, then get the path &#8211;<\/p>\n<pre style=\"color: #000020; background: #f6f8ff;\"><span style=\"color: #200080; font-weight: bold;\">var<\/span> dbPath <span style=\"color: #308080;\">=<\/span> executeStaticJava<span style=\"color: #308080;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">ram.kulkarni.war.sql.demo.SQLDemoUtils<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> <span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">getSavedDBPath<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> appPath<span style=\"color: #308080;\">,<\/span> <span style=\"color: #0f4d75;\">null<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span><\/pre>\n<p>Note that SQLDemoUtils class is in empDBManager.jar.<\/p>\n<p>Create\/open DB file in createDB function &#8211;<\/p>\n<pre style=\"color: #000020; background: #f6f8ff;\"><span style=\"color: #200080; font-weight: bold;\">var<\/span> ret <span style=\"color: #308080;\">=<\/span> createJava<span style=\"color: #308080;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">ram.kulkarni.war.sql.demo.EmployeeDBManager<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> filePath<span style=\"color: #308080;\">,<\/span> <span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">empMgr<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span><\/pre>\n<p>The above function call creates an instance of EmployeeDBManager (by passing filePath as the argument to the constructor), which can be referenced as empMgr.<\/p>\n<p>Save DB file path in a properties file after DB is created\/opened<\/p>\n<pre style=\"color: #000020; background: #f6f8ff;\"><span style=\"color: #200080; font-weight: bold;\">if<\/span> <span style=\"color: #308080;\">(<\/span>appPath <span style=\"color: #308080;\">&amp;&amp;<\/span> filePath<span style=\"color: #308080;\">)<\/span>\n    executeStaticJava<span style=\"color: #308080;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">ram.kulkarni.war.sql.demo.SQLDemoUtils<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> <span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">saveDBPath<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> appPath<span style=\"color: #308080;\">,<\/span>filePath<span style=\"color: #308080;\">,<\/span><span style=\"color: #0f4d75;\">null<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span><\/pre>\n<p>Notice above how SQLiteApp remembers last opened DB file in properties file using some of the new APIs added to WebAppRunner.<\/p>\n<p>Add an employee &#8211;<\/p>\n<pre style=\"color: #000020; background: #f6f8ff;\"><span style=\"color: #595979;\">\/\/Create a new EmployeeVO object<\/span>\n<span style=\"color: #200080; font-weight: bold;\">var<\/span> ret <span style=\"color: #308080;\">=<\/span> createJava<span style=\"color: #308080;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">ram.kulkarni.war.sql.demo.EmployeeVO<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> <span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">empVO<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span>\n<span style=\"color: #595979;\">\/\/Set properties of EmployeeVO<\/span>\nexecuteJava<span style=\"color: #308080;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">empVO<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> <span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">setFirstName<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> firstName<span style=\"color: #308080;\">,<\/span> <span style=\"color: #0f4d75;\">null<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span>\nexecuteJava<span style=\"color: #308080;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">empVO<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> <span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">setLastName<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> lastName<span style=\"color: #308080;\">,<\/span> <span style=\"color: #0f4d75;\">null<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span>\nexecuteJava<span style=\"color: #308080;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">empVO<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> <span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">setAddress<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> address<span style=\"color: #308080;\">,<\/span> <span style=\"color: #0f4d75;\">null<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span>\n<span style=\"color: #595979;\">\/\/Call addEmployee on empMgr, passing empVO as argument<\/span>\n<span style=\"color: #200080; font-weight: bold;\">var<\/span> id <span style=\"color: #308080;\">=<\/span> executeJava<span style=\"color: #308080;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">empMgr<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> <span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">addEmployee<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> <span style=\"color: #800000;\">\"<\/span><span style=\"color: #1060b6;\">$empVO<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #308080;\">,<\/span> <span style=\"color: #0f4d75;\">null<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span><\/pre>\n<p>I hope this example gives a glimpse of how you can create powerful database standalone applications using HTML\/JS UI with Java backend.<\/p>\n<p>-Ram Kulkarni<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WebAppRunner is the Eclipse RCP application I created to run web applications as standalone desktop applications. I had explained earlier how this application could be used by creating a demo FileList application. In this post I am going to show how WebAppRunner can be used to create Database applications. I have created a demo application, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/ramkulkarni.com\/blog\/developing-database-applications-with-webapprunner\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Developing Database Applications with WebAppRunner&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[38,10,1],"tags":[40,41,44],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2g9O8-6D","jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts\/411"}],"collection":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/comments?post=411"}],"version-history":[{"count":1,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts\/411\/revisions"}],"predecessor-version":[{"id":2065,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts\/411\/revisions\/2065"}],"wp:attachment":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/media?parent=411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/categories?post=411"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/tags?post=411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}