{"id":1013,"date":"2019-12-02T22:05:00","date_gmt":"2019-12-02T09:05:00","guid":{"rendered":"https:\/\/www.ronella.xyz\/?p=1013"},"modified":"2021-09-28T13:59:45","modified_gmt":"2021-09-28T00:59:45","slug":"using-embedded-derby-in-java-9-with-gradle","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=1013","title":{"rendered":"Using Embedded Derby in Java 9 with Gradle"},"content":{"rendered":"<ol>\n<li>Add the following <strong>dependencies<\/strong> to your <strong>build.gradle<\/strong> file:\n<pre style=\"white-space: pre;\">compile group: 'org.apache.derby', name: 'derby', version: '10.15.1.3'\r\ncompile group: 'org.apache.derby', name: 'derbyshared', version: '10.15.1.3'<\/pre>\n<\/li>\n<li>Add the following entries to your <strong>module-info.java<\/strong> file:\n<pre style=\"white-space: pre;\">requires org.apache.derby.engine;\r\nrequires org.apache.derby.commons;\r\nrequires java.sql;\r\n<\/pre>\n<\/li>\n<li>In your Java class, you can <strong>create a connection<\/strong> like the following:\n<pre style=\"white-space: pre;\">final String DATABASE_NAME = \"sample_table\";\r\nString connectionURL = String.format(\"jdbc:derby:%s;create=true\", DATABASE_NAME);\r\nconnection = DriverManager.getConnection(connectionURL);\r\n<\/pre>\n<\/li>\n<li>Do your needed <strong>database operations<\/strong> with the connection <em>(e.g. create table, execute a query, or call a stored procedure.)<\/em>.<\/li>\n<li>When your done using the connection, <strong>close the connection<\/strong> and <strong>shutdown the Derby engine<\/strong> like the following:\n<pre style=\"white-space: pre;\">connection.close();\r\n\r\nboolean gotSQLExc = false;\r\ntry {\r\n    \/\/shutdown all databases and the Derby engine\r\n    DriverManager.getConnection(\"jdbc:derby:;shutdown=true\");\r\n} catch (SQLException se)  {\r\n    if ( se.getSQLState().equals(\"XJ015\") ) {\r\n        gotSQLExc = true;\r\n    }\r\n}\r\nif (!gotSQLExc) {\r\n    System.out.println(\"Database did not shut down normally\");\r\n}<\/pre>\n<blockquote><p>A clean shutdown always throws SQL exception <strong>XJ015<\/strong>, which can be ignored.<\/p><\/blockquote>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Add the following dependencies to your build.gradle file: compile group: &#8216;org.apache.derby&#8217;, name: &#8216;derby&#8217;, version: &#8216;10.15.1.3&#8217; compile group: &#8216;org.apache.derby&#8217;, name: &#8216;derbyshared&#8217;, version: &#8216;10.15.1.3&#8217; Add the following entries to your module-info.java file: requires org.apache.derby.engine; requires org.apache.derby.commons; requires java.sql; In your Java class, you can create a connection like the following: final String DATABASE_NAME = &#8220;sample_table&#8221;; String connectionURL [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[58,32,43,71],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1013"}],"collection":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1013"}],"version-history":[{"count":6,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1013\/revisions"}],"predecessor-version":[{"id":1019,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1013\/revisions\/1019"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}