python-2.7 - 将 Python 连接到 H2

标签 python-2.7 h2 jaydebeapi

我正在尝试建立从 python2.7 到 H2 的连接(h2-1.4.193.jar - 最新)

H2(正在运行且可用):java -Dh2.bindAddress=127.0.0.1 -cp "E:\Dir\h2-1.4.193.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Server -tcpPort 15081 -baseDir E:\Dir\db
对于 python,我使用 jaydebeapi :

import jaydebeapi

conn = jaydebeapi.connect('org.h2.Driver', ['jdbc:h2:tcp://localhost:15081/db/test', 'sa', ''], 'E:\Path\to\h2-1.4.193.jar')
curs = conn.cursor()
curs.execute('create table PERSON ("PERSON_ID" INTEGER not null, "NAME" VARCHAR not null, primary key ("PERSON_ID"))')
curs.execute("insert into PERSON values (1, 'John')")
curs.execute("select * from PERSON")
data = curs.fetchall()
print(data)

结果每次我得到一个错误:Process finished with exit code -1073741819 (0xC0000005)你对这个案子有什么想法吗?或者也许我可以使用其他东西来代替 jaydebeapi ?

最佳答案

回答我自己的问题:
首先,我无法通过 jaydebeapi 做任何事情。 .
我读过 H2 支持 PostgreSQL 网络协议(protocol)。我接下来的步骤是将 h2 和 python 转移到 pgsql 中:

H2 皮克:

java -Dh2.bindAddress=127.0.0.1 -cp h2.jar;postgresql-9.4.1212.jre6.jar org.h2.tools.Server -baseDir E:\Dir\h2\db

TCP server running at tcp://localhost:9092 (only local connections)
PG server running at pg://localhost:5435 (only local connections)
Web Console server running at http://localhost:8082 (only local connections)
postgresql.jar包括尝试从 Web 控制台连接。

python :psycopg2而不是 jaydebeapi :
import psycopg2

conn = psycopg2.connect("dbname=h2pg user=sa password='sa' host=localhost port=5435")
cur = conn.cursor()
cur.execute('create table PERSON ("PERSON_ID" INTEGER not null, "NAME" VARCHAR not null, primary key ("PERSON_ID"))')

结果 - 它现在正在工作。建立连接并创建表。

Web 控制台设置:
Generic PostgreSQL
org.postgresql.Driver
jdbc:postgresql://localhost:5435/h2pg
name: sa, pass: sa

Web 控制台确实连接了,但没有显示表格列表,而是显示了许多错误:"CURRENT_SCHEMAS" is not found etc... . PG admin 4 也无法连接。 SQuirrel 进行救援 - 它已连接到该数据库,并且在那里一切正常。

关于python-2.7 - 将 Python 连接到 H2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41493117/

相关文章:

python - '%.*g' % (6,k) 在 python 中如何工作

python - python中的可恢复文件上传

java - H2 Console Servlet 不显示表格

jdbc - 如何在 Play Framework 2.4 中使用相对于项目根目录到 H2 db 文件配置的路径?

Python SQL 查询性能

python - 将 NetworkX 节点属性放入 Pandas Dataframe 列

python 2.7 : 'Ramón' == u'Ramón'

mysql - 尝试使用 MySQL 数据库而不是 H2 来检索进程信息 [在 AS7 中]--jbpm-console 未部署

python - JPype 和 JayDeBeAPI : AttributeError: 'property' object has no attribute 'isBeanAccessor'