php editor Baicao is here to answer a common question: "Why does the connection to the Oracle database from golang fail?" When using golang to connect to the Oracle database, sometimes the connection fails. question. This could be due to a variety of reasons, such as database misconfiguration, network connection issues, or driver incompatibility. This article will analyze the possible causes in detail and provide solutions to help readers solve this problem and make the process of connecting to the Oracle database smoother.
Question content
dsn := ` user=admin, password=temp1!a, (description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=adb.ap-seoul-1.oraclecloud.com))(connect_data=(service_name=gee9edfb93f3cf6_redglqweyxqefhhf_high.adb.oraclecloud.com))(security=(ssl_server_cert_dn="cn=adb.ap-seoul-1.oraclecloud.com, ou=oracle adb seoul, o=oracle corporation, l=redwood city, st=california, c=us"))) ` db, err := sql.open("godror", dsn) if err != nil { fmt.println(err) return } defer db.close()
I created an autonomous database, I tried to connect with the above code in golang, but could not connect, the following error occurred, how to connect, I can't find a detailed manual, can you help me? p>
go run main.go parsing parameters "user=ADMIN,\n\tpassword=temp1!a,\n\t(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=adb.ap-seoul-1.oraclecloud.com))(connect_data=(service_name=gee9edfb93f3cf6_redglqweyxqefhhf_high.adb.oraclecloud.com))(security=(ssl_server_cert_dn=\"CN=adb.ap-seoul-1.oraclecloud.com, OU=Oracle ADB SEOUL, O=Oracle Corporation, L=Redwood City, ST=California, C=US\")))": logfmt syntax error at pos 44 on line 3: unexpected '='
Solution
I am a new user of oracle and golang, everything is new and I am having difficulty finding the documentation for connecting oracle and golang. There is a manual but I don't quite understand it.
If you post a question on stackoverflow, the answer is just a link to the manual. For beginners, it is really difficult to experience a new environment
I finally found the solution, my code is as follows. Even if you can't read the code, it's good to think about it one by one as you look at the examples.
package main import ( "database/sql" "fmt" go_ora "github.com/sijms/go-ora/v2" ) type DbInfo struct { Username string Password string } func main() { serverInfo := DbInfo{ Username: "databaseUser", Password: "databaseUserPassword", } urlOptions := map[string]string{ "TRACE FILE": "trace.log", "SSL VERIFY": "FALSE", } connectString := "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=adb.ap-seoul-1.oraclecloud.com))(connect_data=(service_name=gvsd1dfc9c3cdf6_racc7y8cxsvb16f0z_medium.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)))" db, err := sql.Open("oracle", go_ora.BuildJDBC(serverInfo.Username, serverInfo.Password, connectString, urlOptions)) if err != nil { panic(err.Error()) } defer db.Close() r, err := db.Exec(`create table users ( nickname varchar(20) )`) if err != nil { panic(err.Error()) } fmt.Println(r.LastInsertId()) }
The code above does not require a wallet for tls access. I will also upload below how to access it through the wallet for beginners who need it.
The above is the detailed content of Why does connecting to Oracle Autonomous Database from golang fail?. For more information, please follow other related articles on the PHP Chinese website!

Mastering the strings package in Go language can improve text processing capabilities and development efficiency. 1) Use the Contains function to check substrings, 2) Use the Index function to find the substring position, 3) Join function efficiently splice string slices, 4) Replace function to replace substrings. Be careful to avoid common errors, such as not checking for empty strings and large string operation performance issues.

You should care about the strings package in Go because it simplifies string manipulation and makes the code clearer and more efficient. 1) Use strings.Join to efficiently splice strings; 2) Use strings.Fields to divide strings by blank characters; 3) Find substring positions through strings.Index and strings.LastIndex; 4) Use strings.ReplaceAll to replace strings; 5) Use strings.Builder to efficiently splice strings; 6) Always verify input to avoid unexpected results.

ThestringspackageinGoisessentialforefficientstringmanipulation.1)Itofferssimpleyetpowerfulfunctionsfortaskslikecheckingsubstringsandjoiningstrings.2)IthandlesUnicodewell,withfunctionslikestrings.Fieldsforwhitespace-separatedvalues.3)Forperformance,st

WhendecidingbetweenGo'sbytespackageandstringspackage,usebytes.Bufferforbinarydataandstrings.Builderforstringoperations.1)Usebytes.Bufferforworkingwithbyteslices,binarydata,appendingdifferentdatatypes,andwritingtoio.Writer.2)Usestrings.Builderforstrin

Go's strings package provides a variety of string manipulation functions. 1) Use strings.Contains to check substrings. 2) Use strings.Split to split the string into substring slices. 3) Merge strings through strings.Join. 4) Use strings.TrimSpace or strings.Trim to remove blanks or specified characters at the beginning and end of a string. 5) Replace all specified substrings with strings.ReplaceAll. 6) Use strings.HasPrefix or strings.HasSuffix to check the prefix or suffix of the string.

Using the Go language strings package can improve code quality. 1) Use strings.Join() to elegantly connect string arrays to avoid performance overhead. 2) Combine strings.Split() and strings.Contains() to process text and pay attention to case sensitivity issues. 3) Avoid abuse of strings.Replace() and consider using regular expressions for a large number of substitutions. 4) Use strings.Builder to improve the performance of frequently splicing strings.

Go's bytes package provides a variety of practical functions to handle byte slicing. 1.bytes.Contains is used to check whether the byte slice contains a specific sequence. 2.bytes.Split is used to split byte slices into smallerpieces. 3.bytes.Join is used to concatenate multiple byte slices into one. 4.bytes.TrimSpace is used to remove the front and back blanks of byte slices. 5.bytes.Equal is used to compare whether two byte slices are equal. 6.bytes.Index is used to find the starting index of sub-slices in largerslices.

Theencoding/binarypackageinGoisessentialbecauseitprovidesastandardizedwaytoreadandwritebinarydata,ensuringcross-platformcompatibilityandhandlingdifferentendianness.ItoffersfunctionslikeRead,Write,ReadUvarint,andWriteUvarintforprecisecontroloverbinary


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools
