This is a creation in Article, where the information may have evolved or changed.
1. Install the driver
go get -d github.com/asifjalil/cli
2. Liteide using Win32 compilation environment, modify WIN32.ENV, add (change according to the installation path of native DB 9.7)
Db2home=d:/progra~2/ibm/sqllib
Cgo_ldflags=-l%db2home%/lib
Cgo_cflags=-i%db2home%/include
3. Open the $GOPATH/src/github.com/asifjalil/cli directory, replacing all of the *.go files
#cgo Ldflags:-LDB2
For
#cgo Ldflags:-ldb2cli
#cgo Ldflags:-ldb2api
4. Cirl+f8 (Go Install)
5. Test code Run
Package Main
Import (
"Database/sql"
"FMT"
_ "Github.com/asifjalil/cli"
)
Func Main () {
ConnStr: = ' driver={ibm DB2 ODBC Driver}; Hostname=localhost; port=50000; Protocol=tcpip;database=oatest; Currentschema=oa; Uid=oa; Pwd=oa; '
DB, err: = SQL. Open ("CLI", CONNSTR)
If err! = Nil {
Panic (ERR)
}
Defer db. Close ()
sql: = "Select StaffID, Staffname from Wf_staff where staffid= ' ADMIN '"
Fmt. PRINTLN (SQL)
Type rslt struct {
StaffID String
Staffname string
}
Rows, err: = db. Query (SQL)
If err! = Nil {
Panic (ERR)
}
For rows. Next () {
var r rslt
Err = rows. Scan (&r.staffid, &r.staffname)
If err! = Nil {
Panic (ERR)
}
Fmt. Println (R)
}
}