If you are looking to connect to your databases like SQL Server, Oracle, DB2, Postgres, MongoDB etc., or SaaS apps like Salesforce, Eloqua, Oracle Sales Cloud, Oracle Service Cloud etc., using a ODBC driver from your Go application, this is the place to get started. In this tutorial, we will walk you through on how you can connect to Oracle database from Go using Progress DataDirect ODBC drivers.
Have GO installed on your machine.
go get github.com/alexbrainman/odbc
package mainimport ( "database/sql" "fmt" _ "github.com/alexbrainman/odbc")func main() { var ( regionID int regionName string ) //Open Connection. Provide DSN, Username and Password db, err := sql.Open("odbc", "DSN=Oracle;Uid=saikrishnabobba;Pwd=<progress>") if err != nil { fmt.Println("Connection Failed :( ", err) } else { fmt.Println("Can Connect :)") } //Provide the Query to execute rows, err := db.Query("select REGION_ID, REGION_NAME from REGIONS") if err != nil { fmt.Println("Unable to Query :( ", err) } //Parse the Resultset defer rows.Close() for rows.Next() { err := rows.Scan(®ionID, ®ionName) if err != nil { fmt.Println("Error when parsing :( ", err) } fmt.Println(regionID, regionName) } err = rows.Err() if err != nil { fmt.Println(err) } //Close the connection defer db.Close()}You can use similar steps with any of DataDirect ODBC suite of drivers available for Relational databases like SQL Server, MySQL, PostgreSQL etc., Big Data sources like Hive, Spark etc., SaaS sources like Salesforce, Eloqua, Oracle Sales Cloud etc., and NoSQL Data sources like MongoDB. Feel free to try any of our drivers with your Go apps for connecting to your datasource of your choice.