{"id":591,"date":"2018-12-04T18:10:41","date_gmt":"2018-12-04T09:10:41","guid":{"rendered":"https:\/\/dong1lkim.oboki.net\/?p=591"},"modified":"2019-09-01T22:20:24","modified_gmt":"2019-09-01T13:20:24","slug":"python-jaydebeapi","status":"publish","type":"post","link":"https:\/\/oboki.net\/workspace\/data-engineering\/database\/tibero\/python-jaydebeapi\/","title":{"rendered":"[Python] JayDeBeApi"},"content":{"rendered":"<h1>JayDeBeApi<\/h1>\n<blockquote><p>\n  The JayDeBeApi module allows you to connect from Python code to databases using Java JDBC. It provides a Python DB-API v2.0 to that database.\n<\/p><\/blockquote>\n<p><a href=\"https:\/\/pypi.org\/project\/JayDeBeApi\/\"><a href=\"https:\/\/pypi.org\/project\/JayDeBeApi\/\">https:\/\/pypi.org\/project\/JayDeBeApi\/<\/a><\/a><\/p>\n<h2>install<\/h2>\n<p>jdbc\ub97c \uc0ac\uc6a9\ud558\ub2e4\ubcf4\ub2c8 java\uac00 \uc124\uce58\ub3fc \uc788\uc5b4\uc57c \ud55c\ub2e4.<\/p>\n<h3>Python Version<\/h3>\n<pre><code class=\"bash\">$ python --version\nPython 3.6.6\n<\/code><\/pre>\n<h3>pip\ub97c \uc774\uc6a9\ud55c \uc124\uce58<\/h3>\n<pre><code class=\"bash\">$ pip install JayDeBeApi\nCollecting JayDeBeApi\n  Downloading https:\/\/files.pythonhosted.org\/packages\/2a\/63\/5fbffcbf0463fe26f55ee8ff08bcbb812cab4df2decddfac645cbac966ed\/JayDeBeApi-1.1.1-py3-none-any.whl\nCollecting JPype1 (from JayDeBeApi)\n  Downloading https:\/\/files.pythonhosted.org\/packages\/c4\/4b\/60a3e63d51714d4d7ef1b1efdf84315d118a0a80a5b085bb52a7e2428cdc\/JPype1-0.6.3.tar.gz (168kB)\n    100% |\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 174kB 4.5MB\/s \nInstalling collected packages: JPype1, JayDeBeApi\n  Running setup.py install for JPype1 ... done\nSuccessfully installed JPype1-0.6.3 JayDeBeApi-1.1.1\n<\/code><\/pre>\n<h2>sample<\/h2>\n<p>tibero\uc5d0 jdbc\ub85c \uc811\uadfc\ud574 \ub2e8\uc21c\ud55c ddl,dml \uc744 \uc218\ud589\ud574\ubcf4\uace0 resultset\uc744 \ubc1b\uc544\uc634. executemany \uba54\uc18c\ub4dc\ub97c \uc774\uc6a9\ud574\uc11c batch insert\ub3c4 \ud560 \uc218 \uc788\ub294 \uac83 \uac19\ub2e4.<\/p>\n<pre><code class=\"py\">#!\/app\/python\/bin\/python\n\nimport jaydebeapi\n\nconn = jaydebeapi.connect(\n    \"com.tmax.tibero.jdbc.TbDriver\",\n    \"jdbc:tibero:thin:@localhost:8629:tibero\",\n    [\"tibero\",\"tmax\"],\n    \"tibero6-jdbc.jar\",\n    )\ncur = conn.cursor()\n\nsql = \"SELECT LEVEL AS NUM,SYSDATE-LEVEL AS DT FROM DUAL CONNECT BY LEVEL &lt; 10\"\ncur.execute(sql)\nprint(cur.fetchall())\n\nsql = \"CREATE TABLE TEST_TAB AS SELECT LEVEL AS NUM,SYSDATE-LEVEL AS DT FROM DUAL CONNECT BY LEVEL &lt; 10\"\ncur.execute(sql)\n\nsql = \"SELECT * FROM TEST_TAB\"\ncur.execute(sql)\nprint(cur.fetchall())\n\ncur.close()\n\nimport datetime\n\ncur = conn.cursor()\ndata = [\n    (str(10),datetime.datetime(2018,11,24).strftime(\"%Y\/%m\/%d\")),\n    (str(11),datetime.datetime(2018,11,23).strftime(\"%Y\/%m\/%d\")),\n    (str(12),datetime.datetime(2018,11,22).strftime(\"%Y\/%m\/%d\")),\n    (str(13),datetime.datetime(2018,11,21).strftime(\"%Y\/%m\/%d\")),\n    (str(14),datetime.datetime(2018,11,20).strftime(\"%Y\/%m\/%d\")),\n    (str(15),datetime.datetime(2018,11,19).strftime(\"%Y\/%m\/%d\")),\n    (str(16),datetime.datetime(2018,11,18).strftime(\"%Y\/%m\/%d\")),\n    (str(17),datetime.datetime(2018,11,17).strftime(\"%Y\/%m\/%d\")),\n    (str(18),datetime.datetime(2018,11,16).strftime(\"%Y\/%m\/%d\")),\n    (str(19),datetime.datetime(2018,11,15).strftime(\"%Y\/%m\/%d\")),\n    ]\nstmt = \"\"\"INSERT INTO TEST_TAB VALUES (?, ?)\"\"\"\ncur.executemany(stmt, data)\n\nsql = \"SELECT * FROM TEST_TAB\"\ncur.execute(sql)\nprint(cur.fetchall())\n\ncur.close()\nconn.close()\n<\/code><\/pre>\n<p>\uc54c\uc544\ubcf4\uae30 \uc5b4\ub835\uc9c0\ub9cc \ub428<\/p>\n<pre><code class=\"bash\">.\/sample.py \n[(1.0, '2018-12-03 18:04:09'), (2.0, '2018-12-02 18:04:09'), (3.0, '2018-12-01 18:04:09'), (4.0, '2018-11-30 18:04:09'), (5.0, '2018-11-29 18:04:09'), (6.0, '2018-11-28 18:04:09'), (7.0, '2018-11-27 18:04:09'), (8.0, '2018-11-26 18:04:09'), (9.0, '2018-11-25 18:04:09')]\n[(1.0, '2018-12-03 18:04:09'), (2.0, '2018-12-02 18:04:09'), (3.0, '2018-12-01 18:04:09'), (4.0, '2018-11-30 18:04:09'), (5.0, '2018-11-29 18:04:09'), (6.0, '2018-11-28 18:04:09'), (7.0, '2018-11-27 18:04:09'), (8.0, '2018-11-26 18:04:09'), (9.0, '2018-11-25 18:04:09')]\n[(1.0, '2018-12-03 18:04:09'), (2.0, '2018-12-02 18:04:09'), (3.0, '2018-12-01 18:04:09'), (4.0, '2018-11-30 18:04:09'), (5.0, '2018-11-29 18:04:09'), (6.0, '2018-11-28 18:04:09'), (7.0, '2018-11-27 18:04:09'), (8.0, '2018-11-26 18:04:09'), (9.0, '2018-11-25 18:04:09'), (10.0, '2018-11-24 00:00:00'), (11.0, '2018-11-23 00:00:00'), (12.0, '2018-11-22 00:00:00'), (13.0, '2018-11-21 00:00:00'), (14.0, '2018-11-20 00:00:00'), (15.0, '2018-11-19 00:00:00'), (16.0, '2018-11-18 00:00:00'), (17.0, '2018-11-17 00:00:00'), (18.0, '2018-11-16 00:00:00'), (19.0, '2018-11-15 00:00:00')]\n<\/code><\/pre>\n<pre><code class=\"sql\">SQL&gt; ls\n\nNAME                               SUBNAME                  TYPE                \n---------------------------------- ------------------------ --------------------\nTEST_TAB                                                    TABLE\n\nSQL&gt; select * from test_tab;\n\n       NUM DT                              \n---------- --------------------------------\n         1 2018\/12\/03\n         2 2018\/12\/02\n         3 2018\/12\/01\n         4 2018\/11\/30\n         5 2018\/11\/29\n         6 2018\/11\/28\n         7 2018\/11\/27\n         8 2018\/11\/26\n         9 2018\/11\/25\n        10 2018\/11\/24\n        11 2018\/11\/23\n        12 2018\/11\/22\n        13 2018\/11\/21\n        14 2018\/11\/20\n        15 2018\/11\/19\n        16 2018\/11\/18\n        17 2018\/11\/17\n        18 2018\/11\/16\n        19 2018\/11\/15\n\n19 rows selected.\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>JayDeBeApi The JayDeBeApi module allows you to connect from Python code to databases using Java JDBC. It provides a Python DB-API v2.0 to that database. https:\/\/pypi.org\/project\/JayDeBeApi\/ install jdbc\ub97c \uc0ac\uc6a9\ud558\ub2e4\ubcf4\ub2c8 java\uac00 \uc124\uce58\ub3fc \uc788\uc5b4\uc57c \ud55c\ub2e4. Python Version $ python &#8211;version Python 3.6.6 pip\ub97c \uc774\uc6a9\ud55c \uc124\uce58 $ pip install JayDeBeApi Collecting JayDeBeApi Downloading https:\/\/files.pythonhosted.org\/packages\/2a\/63\/5fbffcbf0463fe26f55ee8ff08bcbb812cab4df2decddfac645cbac966ed\/JayDeBeApi-1.1.1-py3-none-any.whl Collecting JPype1 (from JayDeBeApi) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,8],"tags":[130,35,34],"class_list":["post-591","post","type-post","status-publish","format-standard","hentry","category-python","category-tibero","tag-jaydebeapi","tag-jdbc","tag-python"],"_links":{"self":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts\/591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/comments?post=591"}],"version-history":[{"count":4,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts\/591\/revisions"}],"predecessor-version":[{"id":1197,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts\/591\/revisions\/1197"}],"wp:attachment":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/media?parent=591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/categories?post=591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/tags?post=591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}