Golang使用JDBC或ODBC或什么连接类型

go version go1.8.1 windows/amd64 and I am importing

"github.com/mattn/go-oci8" 
"database/sql" 

For connecting to my oracle database. Here when I give db username, password, port and table name in connection string

func openAndConnectToDb(sbconfig ConnectorConfig) *sql.DB {
    logger := sbgoclient.Log
    logger.Println("Open the database")
    //  oraprop := LoadConfig("oraproperties.yml")
    fmt.Println("Load config complete")
    orrrr := sbconfig.DB_Username + "/" + sbconfig.DB_Password + "@" + "//" + sbconfig.DB_Ip + ":" + sbconfig.DB_Port + "/" + sbconfig.DB_Schema
    fmt.Println("orrr formed: ", orrrr)
    db, err := sql.Open(sbconfig.DbType, orrrr)
    if err != nil {
        logger.Println("database connection failed...")
        logger.Fatal(err)
    }

    //Use a backoff/retry strategy - we can start this client before
    //the database is started, and see it eventually connect and process
    //queries
    var dbError error
    maxAttempts := 20
    for attempts := 1; attempts <= maxAttempts; attempts++ {
        logger.Println("pinging database...")
        dbError = db.Ping()
        if dbError == nil {
            logger.Println("database ping successfull........")
            fmt.Println("database ping successfull........")
            break
        }
        logger.Println("Ping failed: ", dbError, "retry in ", attempts, " seconds.")
        time.Sleep(time.Duration(attempts) * time.Second)
    }
    if dbError != nil {
        logger.Fatal(dbError)
    }

    return db
}

It fails to connect, whereas in java if I specify username, password, port, servicename and tablename in JDBC connection string it connects successfully.

The output is

time="2017-10-10T13:43:02+05:30" level=info msg="Open the database" 
time="2017-10-10T13:43:02+05:30" level=info msg="pinging database..." 
time="2017-10-10T13:43:24+05:30" level=info msg="Ping failed:  ORA-12170: TNS:Connect timeout occurred
retry in  1  seconds." 
time="2017-10-10T13:43:25+05:30" level=info msg="pinging database..." 
time="2017-10-10T13:43:46+05:30" level=info msg="Ping failed:  ORA-12170: TNS:Connect timeout occurred 
retry in  2  seconds." 

I cannot tell you exactly why your code ist not working, but I can provide you with some sample code I am involved in in an advisory capacity:

https://github.com/odbaeu/oracledb_metricbeat/blob/master/oracledb.go

Here the code fragment creating a new connection:

// NewDB returns a new oracle database handle. The dsn value (data source name)
// must be valid, otherwise an error will be returned.
//
//   DSN Format: username/password@host:port/service_name
func NewDB(ociURL string) (*sql.DB, error) {
    // NLS_LANG is set to American format. At least NLS_NUMERIC_CHARACTERS has to be ".,".
    os.Setenv("NLS_LANG", "AMERICAN_AMERICA.AL32UTF8")
    os.Setenv("NLS_DATE_FORMAT", "YYYY-MM-DD\"T\"HH24:MI:SS")

    // Open DB connection
    oConn, err := sql.Open("oci8", ociURL)
    if err != nil {
        return oConn, errors.Wrap(err, "sql open failed")
    }

    return oConn, nil
}