数据库连接的方法不是很懂. 如果有描述错误, 请见谅.
jdbc:as400://hostname/database
https://github.com/ibmdb/go_ibm_db
去访问的时候, package main
import (
"database/sql"
"fmt"
_ "github.com/ibmdb/go_ibm_db"
)
const (
HOSTNAME = "HOSTNAME"
DATABASE = "DATABASE"
UID = "UID"
PWD = "PWD"
)
func main() {
con := "HOSTNAME=HOSTNAMEl;DATABASE=DATABASE;PORT=50000;UID=UID;PWD=PWD"
type Db *sql.DB
var re Db
re = Create_Con(con)
err := display(re)
if err != nil {
fmt.Println(err)
}
}
func Create_Con(con string) *sql.DB {
db, err := sql.Open("go_ibm_db", con)
if err != nil {
fmt.Println(err)
return nil
}
return db
}
func display(db *sql.DB) error {
st, err := db.Prepare("select * from RIDCPNM")
if err != nil {
return err
}
err = execquery(st)
if err != nil {
return err
}
return nil
}
func execquery(st *sql.Stmt) error {
rows, err := st.Query()
if err != nil {
return err
}
cols, _ := rows.Columns()
fmt.Println(cols)
return nil
}
抛错
SQLDriverConnect: {08001} [IBM][CLI Driver] SQL30081N A communication error has been detected. Communicati
on protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was d
etected: "HOSTNAME". Communication function detecting the error: "recv". Protocol specific error code(
s): "10054", "*", "0". SQLSTATE=08001
是目标 as400 所在的机器, 没有开通啥(防火墙, 端口)吗?
1
HardyN 2023-05-30 18:50:28 +08:00
"HOSTNAME=HOSTNAMEl" ?是不是多了个 l
|