-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
main.go
36 lines (32 loc) · 878 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"database/sql"
"fmt"
"os"
_ "github.com/mattn/go-oci8"
)
func main() {
if len(os.Args) != 2 {
fmt.Printf("ERROR: Please provide a DSN string in ONE argument:\n\n")
fmt.Println("Shell-Conversion into DSN string:")
fmt.Println(" sqlplus sys/password@tnsentry as sysdba => sys/password@tnsentry?as=sysdba")
fmt.Println(" sqlplus / as sysdba => sys/.@?as=sysdba")
fmt.Println("instead of the tnsentry, you can also use the hostname of the IP.")
os.Exit(1)
}
os.Setenv("NLS_LANG", "")
db, err := sql.Open("oci8", os.Args[1])
if err != nil {
fmt.Println(err)
return
}
defer db.Close()
fmt.Println()
var user string
err = db.QueryRow("select user from dual").Scan(&user)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Successful 'as sysdba' connection. Current user is: %v\n", user)
}