开发者

Python 3 - Connecting with JDBC

开发者 https://www.devze.com 2023-04-13 02:11 出处:网络
How do you connect to a database using a JDBC driver from within Python 3?JayDeBeApi seems to do the job for Python 2, but at t开发者_Go百科he moment it isn\'t Python 3-compatible.

How do you connect to a database using a JDBC driver from within Python 3? JayDeBeApi seems to do the job for Python 2, but at t开发者_Go百科he moment it isn't Python 3-compatible.

This question is similar to this one, but I am asking specifically about Python 3.


Starting from version 0.2 the official JayDeBeApi now supports Python 3 as well. It is still backwards compatible with Python 2 and Jython.


As I can not delete this answer, I will edit it:

Way back when, I created a Python3-port of JayDeBeApi. But as the other answer points out, the official JayDeBeApi now supports Python3 as well.


Probably too late to be useful, but I was able to connect from Python 3.3 to a MySQL db on my Windows machine (!) using PyMySql (see https://code.google.com/p/pymysql/). Once installed, I used a variation on the code from your reference location here: Python 3 and MySQL. I have a schema called "test" and a table called "users", here was the test code:

import pymysql
conn = pymysql.connect(host='127.0.0.1', user='root', passwd='password', db='mysql')
cur = conn.cursor()
cur.execute("SELECT * FROM test.users")
for r in cur:
    print(r)
cur.close()
conn.close()
0

精彩评论

暂无评论...
验证码 换一张
取 消