Table of Contents
Question content
Solution
Home Backend Development Golang Why does connecting to Oracle Autonomous Database from golang fail?

Why does connecting to Oracle Autonomous Database from golang fail?

Feb 09, 2024 pm 12:40 PM
overflow

Why does connecting to Oracle Autonomous Database from golang fail?

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()
Copy after login

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?

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 '='
Copy after login

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())
}
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
Is H5 page production a front-end development? Is H5 page production a front-end development? Apr 05, 2025 pm 11:42 PM

Yes, H5 page production is an important implementation method for front-end development, involving core technologies such as HTML, CSS and JavaScript. Developers build dynamic and powerful H5 pages by cleverly combining these technologies, such as using the <canvas> tag to draw graphics or using JavaScript to control interaction behavior.

How to control the top and end of pages in browser printing settings through JavaScript or CSS? How to control the top and end of pages in browser printing settings through JavaScript or CSS? Apr 05, 2025 pm 10:39 PM

How to use JavaScript or CSS to control the top and end of the page in the browser's printing settings. In the browser's printing settings, there is an option to control whether the display is...

Why are the inline-block elements misaligned? How to solve this problem? Why are the inline-block elements misaligned? How to solve this problem? Apr 04, 2025 pm 10:39 PM

Regarding the reasons and solutions for misaligned display of inline-block elements. When writing web page layout, we often encounter some seemingly strange display problems. Compare...

How to use the clip-path attribute of CSS to achieve the 45-degree curve effect of segmenter? How to use the clip-path attribute of CSS to achieve the 45-degree curve effect of segmenter? Apr 04, 2025 pm 11:45 PM

How to achieve the 45-degree curve effect of segmenter? In the process of implementing the segmenter, how to make the right border turn into a 45-degree curve when clicking the left button, and the point...

How to customize the resize symbol through CSS and make it uniform with the background color? How to customize the resize symbol through CSS and make it uniform with the background color? Apr 05, 2025 pm 02:30 PM

The method of customizing resize symbols in CSS is unified with background colors. In daily development, we often encounter situations where we need to customize user interface details, such as adjusting...

How to compatible with multi-line overflow omission on mobile terminal? How to compatible with multi-line overflow omission on mobile terminal? Apr 05, 2025 pm 10:36 PM

Compatibility issues of multi-row overflow on mobile terminal omitted on different devices When developing mobile applications using Vue 2.0, you often encounter the need to overflow text...

The latest price of Bitcoin in 2018-2024 USD The latest price of Bitcoin in 2018-2024 USD Feb 15, 2025 pm 07:12 PM

Real-time Bitcoin USD Price Factors that affect Bitcoin price Indicators for predicting future Bitcoin prices Here are some key information about the price of Bitcoin in 2018-2024:

How to achieve segmentation effect with 45 degree curve border? How to achieve segmentation effect with 45 degree curve border? Apr 04, 2025 pm 11:48 PM

Tips for Implementing Segmenter Effects In user interface design, segmenter is a common navigation element, especially in mobile applications and responsive web pages. ...

See all articles