oracle_jy.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package init_serve
  2. import (
  3. "database/sql"
  4. "eta/eta_bridge/global"
  5. "fmt"
  6. "github.com/godror/godror"
  7. "time"
  8. )
  9. func OracleJy() {
  10. conf := global.CONFIG.OracleJY
  11. err := connOracle(conf.Account, conf.Password, conf.Conn, conf.LibDir)
  12. if err != nil {
  13. fmt.Println("oracle 数据库连接失败")
  14. global.LOG.Info("oracle 数据库连接失败,Err: " + err.Error())
  15. panic("oracle 数据库连接失败" + err.Error())
  16. }
  17. }
  18. func connOracle(username, pwd, connectionStr, libDir string) (err error) {
  19. var P godror.ConnectionParams
  20. P.Username, P.Password = username, godror.NewPassword(pwd)
  21. P.ConnectString = connectionStr
  22. /* P.SessionTimeout = 42 * time.Second
  23. P.SetSessionParamOnInit("NLS_NUMERIC_CHARACTERS", ",.")
  24. P.SetSessionParamOnInit("NLS_LANGUAGE", "FRENCH")*/
  25. P.Timezone = time.Local
  26. P.LibDir = libDir
  27. oracleJyDb := sql.OpenDB(godror.NewConnector(P))
  28. err = oracleJyDb.Ping()
  29. if err != nil {
  30. global.LOG.Error("oracle 数据库连接失败,Err: ", err)
  31. panic(err)
  32. }
  33. fmt.Print("连接成功")
  34. global.LOG.Info("oracle 数据库连接成功")
  35. global.OracleJy = oracleJyDb
  36. return
  37. }