• jaydebeapi 使用Python连接JDBC操作数据库


    Mysql

    import jaydebeapi


    conn=jaydebeapi.connect('com.mysql.jdbc.Driver',['jdbc:mysql://localhost:3306/test','hive','hive'],'/data/users/huser/lan/codes/useJPype/mysql-connector-java-5.1.36/mysql-connector-java-5.1.36-bin.jar')

    # 其中mysql的用户名和密码都是hive,最后一个参数是驱动的jar包

    curs=conn.cursor()
    curs.execute('create table CUSTOMER("ID" INTEGER not null primary key,"NAME" varchar not null)')
    curs.execute("insert into CUSTOMER values(1,'John')")
    curs.execute("select * from CUSTOMER")
    curs.fetchall()

    Oracleimport jaydebeapurl = 'jdbc:oracle:thin:@192.168.48.102:1521/orcl'

    user = 'scott'
    password = 'scott'
    dirver = 'oracle.jdbc.driver.OracleDriver'
    jarFile = 'D:\Program Files (x86)\Python\ojdbc6.jar'
    sqlStr = 'select * from emp'
    # conn=jaydebeapi.connect('oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:@127.0.0.1:1521/orcl',['hwf_model','hwf_model'],'E:/pycharm/lib/ojdbc14.jar')
    conn = jaydebeapi.connect(dirver, url, [user, password], jarFile)
    curs = conn.cursor()
    curs.execute(sqlStr)
    result = curs.fetchall()
    for row in result:
        print(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7])
    curs.close()
    conn.close()

    Phoenix

    import jaydebeapi
    conn = jaydebeapi.connect('org.apache.phoenix.jdbc.PhoenixDriver', \
    'jdbc:phoenix:my_zk_server:2181:test', ['', ''], \
    '/workspace/service/phoenix-client/phoenix-client.jar')

    curs = conn.cursor()
    curs.execute('select * from your_table limit 1')
    curs.fetchall()
  • 相关阅读:
    Linux系统 Docker RabbitMQ容器集群部署
    Linux系统 SSH免密登入
    ubuntu server 乱码
    简单总结在github上托管工程
    在线编译系统之nodejs执行shell
    Ubuntu中软件安装与卸载
    ubuntu软件安装
    “cannot find module ‘npmlog’….”的错误
    关于事件的一点小总结
    mongodb基本操作
  • 原文地址:https://www.cnblogs.com/hushaojun/p/15924145.html
Copyright © 2020-2023  润新知