Connect Python to H2

I am trying to establish a connection from python2.7 to H2 (h2-1.4.193.jar is the last one)

H2 (works and is available): 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

For python, I use 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)

As a result, every time I get an error message: Process finished with exit code -1073741819 (0xC0000005) Do you have any ideas on this matter? Or maybe there is something else that I can use instead jaydebeapi?

+4
source share
1 answer

Answering my question: First of all, I could not do anything through jaydebeapi. I read that H2 supports the PostgreSQL network protocol. My next steps were porting h2 and python to pgsql:

H2 pg:

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 was enabled to connect to the web console.

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"))')

- . , .

-:

Generic PostgreSQL
org.postgresql.Driver
jdbc:postgresql://localhost:5435/h2pg
name: sa, pass: sa

- , : "CURRENT_SCHEMAS" is not found etc.... PG admin 4 . SQuirrel - db, .

+3

Source: https://habr.com/ru/post/1665922/


All Articles