Talking to IBM DB2 with Golang
2 min readAug 15, 2018
In my recent project, I need to talk to DB2 database to construct some REST API services.
First of all, we need a DB2 driver for golang program to talk to DB2. There are some previous art done by people. However it was either not actively maintained or doesn’t support on all the major platforms. I decided to use the common ODBC driver to communicate with the DB2.
Setup ODBC/CLI for DB2
Download the DB2 ODBC/CLI driver from IBM site.
Then simply untar/unzip it to a directory.
Configure DB2 ODBC/CLI on Windows
My development and testing environment is on Windows. I setup the db2 driver on Windows first.
- change directory to where you unzip the driver
- As a administrator, run
bin\db2cli install -setup
- Find out where is the db2cli.ini located by running
bin\db2cli validate | findstr "Common App"
Common App Data Path : C:\ProgramData\IBM\DB2\Some_Directory_Name
db2cli.ini Path : <Common App Data Path>\cfg\db2cli.ini
4. Edit the db2cli.ini file where you identified from last step
[MyDB]
Protocol=TCPIP
Hostname=192.168.xxx.xxx
Port=50000
Database=mydb
CurrentSchema=myschema
5. Register the DB into ODBC as a system level DB