Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The notebooks all have the necessary drivers and libraries for connection to DB2 pre-installed. They currently only support ODBC drivers.

The following are some code examples showing how you can connect directly to DB2.

...

Code Block
languagepy
themeMidnight
linenumberstrue
import ibm_db
import pandas as pd

db = 'PR_SAIL'
hostname = 'db2.database.ukserp.ac.uk'
port = '60070'
protocol = 'TCPIP'
uid = 'YOUR USERNAME HERE'
pwd = 'YOUR PASSWORD HERE'
security = 'ssl'
ssl_client_keystoredb = '/db2conn/chi.kdb'
ssl_client_keystash = '/db2conn/chi.sth'

conn_str = ("DATABASE={0};"
			"HOSTNAME={1};"
			"PORT={2};"
			"PROTOCOL={3};"
			"Security={4};"
			"UID={5};"
			"PWD={6};"
			"SSLClientKeystoredb={7};"
			"SSLClientKeystash={8};").format(db, hostname, port, protocol, uid, pwd, ssl_client_keystoredb, ssl_client_keystash)

conn = ibm_db.connect(conn_str, '', '') 
pd_conn = ibm_db_dbi.Connection(conn)

q = 'SELECT * FROM syscat.tables LIMIT 5'
df = pd.read_sql(q, pd_conn)
print(df)

...

After the initial connection to run a query a read it straight into a Pandas DataFrame all you have to do is:

Code Block
languagepy
q = 'SELECT * FROM syscat.columns LIMIT 2'
df = pd.read_sql(q, pd_conn)
print(df)



R

TBC


Content by Label
showLabelsfalse
max5
spacesHDK
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel = "kb-how-to-article" and type = "page" and space = "HDK"
labelskb-how-to-article

...