英文:
I get an error when trying to connect to an oracle database. How to fix it?
问题
dbInfo := DbInfo{
Username: "ADMIN",
Password: "Ddbstjrld1!a",
Server: "adb.ap-seoul-1.oraclecloud.com",
Port: "1522",
Service: "gee9edfb92f3cf6_redglqwayxqefhhf_high.adb.oraclecloud.com",
WalletLocation: "/Users/temp1/Desktop/Wallet_REDGLZWEYXQEFHHF",
}
dbString := fmt.Sprintf(`user="%v" password="%v" connectString="tcps://%s:%s/%s?wallet_location=%s"`, dbInfo.Username, dbInfo.Password, dbInfo.Server, dbInfo.Port, dbInfo.Service, dbInfo.WalletLocation)
db, err := sql.Open("godror", dbString)
if err != nil {
fmt.Println(err.Error())
}
defer db.Close()
r, err := db.Exec(`CREATE TABLE member_table (
seq INT NOT NULL AUTO_INCREMENT,
mb_id VARCHAR(20),
mb_pw VARCHAR(100),
address VARCHAR(100),
mb_tell VARCHAR(20),
PRIMARY KEY(seq)
) ENGINE= MYISAM CHARSET=utf8;`)
if err != nil {
fmt.Println(err.Error())
}
fmt.Println(r)
我第一次使用Oracle。我查看了手册并按照指示操作,但是无法解决问题。
运行查询时出错
ORA-00000: DPI-1047: 无法找到64位Oracle客户端库:"dlopen(libclntsh.dylib, 0x0001): tried: 'libclntsh.dylib' (no such file), '/usr/local/lib/libclntsh.dylib' (no such file), '/usr/lib/libclntsh.dylib' (no such file), '/Users/temp1/project/oracleDatabase/libclntsh.dylib' (no such file)"。请参考https://oracle.github.io/odpi/doc/installation.html#macos获取帮助
temp@temp-MacBookPro oracleDatabase %
通过DBeaver连接时,一切正常,但是使用上述代码在Golang中连接时,返回以下错误。
我已经苦苦挣扎了几天,如果您能给我展示一个简单的示例,我认为我可以在分析中学习,您能帮助我吗?
英文:
dbInfo := DbInfo{
Username: "ADMIN",
Password: "Ddbstjrld1!a",
Server: "adb.ap-seoul-1.oraclecloud.com",
Port: "1522",
Service: "gee9edfb92f3cf6_redglqwayxqefhhf_high.adb.oraclecloud.com",
WalletLocation: "/Users/temp1/Desktop/Wallet_REDGLZWEYXQEFHHF",
}
dbString := fmt.Sprintf(`user="%v" password="%v" connectString="tcps://%s:%s/%s?wallet_location=%s"`, dbInfo.Username, dbInfo.Password, dbInfo.Server, dbInfo.Port, dbInfo.Service, dbInfo.WalletLocation)
db, err := sql.Open("godror", dbString)
if err != nil {
fmt.Println(err.Error())
}
defer db.Close()
r, err := db.Exec(`CREATE TABLE member_table (
seq INT NOT NULL AUTO_INCREMENT,
mb_id VARCHAR(20),
mb_pw VARCHAR(100),
address VARCHAR(100),
mb_tell VARCHAR(20),
PRIMARY KEY(seq)
) ENGINE= MYISAM CHARSET=utf8;`)
if err != nil {
fmt.Println(err.Error())
}
fmt.Println(r)
I am using oracle for the first time. I checked the manual and followed it, but I can't solve it.
Error running query
ORA-00000: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 0x0001): tried: 'libclntsh.dylib' (no such file), '/usr/local/lib/libclntsh.dylib' (no such file), '/usr/lib/libclntsh.dylib' (no such file), '/Users/temp1/project/oracleDatabase/libclntsh.dylib' (no such file)". See https://oracle.github.io/odpi/doc/installation.html#macos for help
temp@temp-MacBookPro oracleDatabase %
When connecting through dbeaver, it works normally, but when connecting with the above code in golang, the following error is returned.
I've been struggling for several days, if you show me a simple example, I think I can study while analyzing it, can you help me?
答案1
得分: 1
更新:正如Christopher Jones所指出的,由于商标问题,goracle
已被弃用。替代方案是godror
。
要使用它,请运行:
go get github.com/godror/godror@latest
然后安装Oracle客户端库。按照其文档建立连接。
根据godror
的文档,您必须注意:
> godror是一个cgo包。如果您想使用godror构建应用程序,您需要gcc(C编译器)。
<s>
根据提到的错误,您需要导入Oracle驱动程序goracle
以便database/sql
可以与Oracle数据库一起使用。
import (
"database/sql"
// 导入Oracle驱动程序
_ "gopkg.in/goracle.v2"
)
附注:我建议在引发该错误的问题陈述中添加行号,以便可以轻松进行调试。
</s>
英文:
Update: As pointed out by Christopher Jones, goracle
has been deprecated because of trademark issues. The replacement is godror
To use it, run:
go get github.com/godror/godror@latest
and then install Oracle Client libraries. Follow its documentation to make a connection.
As per godror
documentation, you must be aware of:
> godror is cgo package. If you want to build your app using godror, you
> need gcc (a C compiler).
<s>
As per the mentioned error, you need to import oracle driver goracle
for database/sql
to work with an oracle database.
import (
"database/sql"
// Import the Oracle driver
_ "gopkg.in/goracle.v2"
)
P.S.: I would suggest to add line number in question statement which raised that error so that it can be debugged easily.
</s>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论