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
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
© 2024 OneMinuteCode. All rights reserved.