{"id":1703,"date":"2020-10-16T16:59:41","date_gmt":"2020-10-16T07:59:41","guid":{"rendered":"https:\/\/knowhow.hirohiro716.com\/?p=1703"},"modified":"2024-05-05T10:50:05","modified_gmt":"2024-05-05T01:50:05","slug":"libreoffice%e3%81%a7postgresql%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%abjdbc%e3%81%a7%e6%8e%a5%e7%b6%9a","status":"publish","type":"post","link":"https:\/\/weblog.hirohiro716.com\/?p=1703","title":{"rendered":"LibreOffice\u3067PostgreSQL\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306bJDBC\u3067\u63a5\u7d9a"},"content":{"rendered":"<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOn Error Goto ErrorHandler\r\n'Properties\r\nDim properties(2) As New com.sun.star.beans.PropertyValue\r\nproperties(0).Name = &quot;user&quot;\r\nproperties(0).value = &quot;UserName&quot;\r\nproperties(1).Name = &quot;password&quot;\r\nproperties(1).value = &quot;Pass&quot;\r\nproperties(2).name = &quot;JavaDriverClass&quot;\r\nproperties(2).value = &quot;org.postgresql.Driver&quot;\r\n'Driver manager\r\nDim driverManager As Object\r\ndriverManager = createUnoService(&quot;com.sun.star.sdbc.DriverManager&quot;)\r\n'Connection\r\nDim connection As Object\r\nconnection = driverManager.getConnectionWithInfo(&quot;jdbc:postgresql:\/\/192.168.0.1:5432\/database-name&quot;, properties())\r\n'Statement\r\nDim statement As Object\r\nstatement = connection.createStatement()\r\n'Execute and number of update records\r\nPrint statement.executeUpdate(&quot;DELETE FROM table1;&quot;)\r\n'ResultSet\r\nDim resultSet As Object\r\nresultSet = statement.executeQuery(&quot;SELECT * FROM table2;&quot;)\r\nWhile resultSet.Next\r\n    Print resultSet.getString(1)\r\nWend\r\n'Close\r\nstatement.close()\r\nconnection.close()\r\nconnection.dispose()\r\nExit Sub\r\n'Error handle\r\nErrorHandler:\r\nIf IsNull(statement) = false Then\r\n    statement.close()\r\nEnd If\r\nIf IsNull(connection) = false Then\r\n    If connection.isClosed() = false Then\r\n        connection.close()\r\n        connection.dispose()\r\n    End If\r\nEnd If\r\nIf InStr(Error$, &quot;org.postgresql.Driver&quot;) &gt; 0 Then\r\n    MsgBox(&quot;\u30c4\u30fc\u30eb\u2192\u30aa\u30d7\u30b7\u30e7\u30f3\u2192LibreOffice\u2192\u8a73\u7d30\u2192\u30af\u30e9\u30b9\u30d1\u30b9\u304b\u3089PostgreSQL\u306eJDBC\u30c9\u30e9\u30a4\u30d0\u30fc\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002&quot;, 64, &quot;\u521d\u671f\u8a2d\u5b9a&quot;)\r\nElseif Len(Error$) &gt; 0 Then\r\n    MsgBox(Error$, 16, &quot;\u30a8\u30e9\u30fc&quot;)\r\nEnd If\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>On Error Goto ErrorHandler &#8216;Properties Dim properties(2) As New com.sun.star.beans.PropertyValue properties(0) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-1703","post","type-post","status-publish","format-standard","hentry","category-libreoffice-calc"],"views":1702,"_links":{"self":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts\/1703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1703"}],"version-history":[{"count":9,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts\/1703\/revisions"}],"predecessor-version":[{"id":2510,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts\/1703\/revisions\/2510"}],"wp:attachment":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}