Validating the Netezza Performance Server Go Driver
Before you try to access a Netezza Performance Server data source using Go application, ensure that the Netezza Performance Server Go Driver installation was successful.
Procedure
-
Go client application imports the package github.com/IBM/nzgo/v12. Driver
name should be
"nzgo"
as shown in the following example. A simple Go application which connects to the Netezza Performance Server using the Go driver:
Output:[nz@sim-rh841 app]$ cat sample.go package main import ( "database/sql" "fmt" _ "github.com/IBM/nzgo/v12" ) func main() { var connstring string = "user=admin " + "port=5480 " + "password='password' " + "dbname=system " + "host=localhost " + "securityLevel=3 " + "sslmode=require " + "logLevel=info " + //"logPath= /tmp/ + "additionalLogFile=stdout" db, err := sql.Open("nzgo", connstring) if err != nil { fmt.Println(err) return } defer db.Close() rows, err := db.Query("select count(*) from _t_object") if err != nil { fmt.Println("Error: ", err) return } var count int for rows.Next() { _ = rows.Scan(&count) fmt.Println("object count : ", count) } }
[nz@sim-rh841 app]$ go run sample.go object count : 2803
- Compile the application.
[nz@sim-rh841 app]$ go mod init sample.go [nz@sim-rh841 app]$ go get github.com/IBM/nzgo/v12 [nz@sim-rh841 app]$ go build sample.go
- Run the application. The code initializes and loads the
nzgo
driver by searching for it in $GOPATH/src path. If it's not found in the $GOPATH/src path, the code errors out.go run sample.go
If the application runs successfully, the Performance Server Go Driver was successfully installed.