I would like to connect to dashDB from the .py program on Bluemix.

Asked 2 years ago, Updated 2 years ago, 73 views

We have launched a service for python's application.
I am writing a program called Test.py, but I would like to connect to the dashDB and run SQL.
By the way, it works where it is not Bluemix.
At that time, I did the following.

dsn='sqldb'# ODBC User Dataset SQLDB definition required
usr = 'dash013754'
psw = 'XXXXXXXXXX'
try:
    conn=ibm_db.connect(dsn,usr,psw)
except:     
    print "no connection:", ibm_db.conn_errormsg()
else:
    print "The connection was successful" 

def selectSQLDB():
    now=datetime.datetime.today()
        print now
    sql="SELECT NAME FROM SYSIBM.SYTABLES"
    stmt = ibm_db.prepare(conn,sql)
    body="body of Tweet"
    ibm_db.bind_param(stmt,1,body)
    try:
        ibm_db.execute(stmt)        
#       stmt=ibm_db.exec_immediate(conn,sql)     
    except:
        print "Transaction couldn't be completed:", ibm_db.stmt_errormsg()
        print stmt
        print sql
    else:
        print "Transaction complete."

Thank you for your cooperation.

python bluemix

2022-09-30 20:52

1 Answers

The Bluemix documentation page contains code snippets that connect to the dashDB.
Select Python from the language selection pulldown menu in the upper right corner.

https://www.ng.bluemix.net/docs/ #services/dashDB/index.html#dashDB

Because the credentials for dashDB connections are subject to change, it is recommended that you obtain them from the environment variable VCAP_SERVICES, as shown in the example above URL.

If you want to check by actually moving it, please use the sample at the URL below.
https://hub.jazz.net/project/ibmdatabase/dashDB/overview#https://hub.jazz.net/git/ibmdatabase%252FdashDB/list/master/samples/dashDBPython


2022-09-30 20:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.