python连接h2数据库
首先到有h2的jar包的目录下,启动h2数据库 ,要允许tcp连接(win系统如下图)
java -cp h2*.jar org.h2.tools.Server -tcpAllowOthers
然后python操作
先安装pip install jaydebeapi
按照下面模板,干就完事了
import jaydebeapi driver = 'org.h2.Driver' url = 'jdbc:h2:tcp://ip:port/~/dbname' username = 'sa' password = 'sa' jar = 'c:/h2/bin/h2-1.4.199.jar' conn = jaydebeapi.connect(driver, url, [username, password], jar) curs = conn.cursor() try: sql = 'CREATE TABLE TEST2(ID INT PRIMARY KEY,NAME VARCHAR(255));' curs.execute(sql) finally: curs.close() conn.close()