package init_serve import ( "database/sql" "eta/eta_bridge/global" "fmt" "github.com/godror/godror" "time" ) func OracleJy() { conf := global.CONFIG.OracleJY err := connOracle(conf.Account, conf.Password, conf.Conn, conf.LibDir) if err != nil { fmt.Println("oracle 数据库连接失败") global.LOG.Info("oracle 数据库连接失败,Err: " + err.Error()) panic("oracle 数据库连接失败" + err.Error()) } } func connOracle(username, pwd, connectionStr, libDir string) (err error) { var P godror.ConnectionParams P.Username, P.Password = username, godror.NewPassword(pwd) P.ConnectString = connectionStr /* P.SessionTimeout = 42 * time.Second P.SetSessionParamOnInit("NLS_NUMERIC_CHARACTERS", ",.") P.SetSessionParamOnInit("NLS_LANGUAGE", "FRENCH")*/ P.Timezone = time.Local P.LibDir = libDir oracleJyDb := sql.OpenDB(godror.NewConnector(P)) err = oracleJyDb.Ping() if err != nil { global.LOG.Error("oracle 数据库连接失败,Err: ", err) panic(err) } fmt.Print("连接成功") global.LOG.Info("oracle 数据库连接成功") global.OracleJy = oracleJyDb return }