Golang Postgres连接字符串未打开返回null

I am sure that there is something with the connectionString as the values I am giving are the same values that I use in Java to log into the same database. This is my code

package main

import(
    "fmt"
    "database/sql"
    _ "github.com/lib/pq"

    "log"
)




func main() {


    db, err := sql.Open("postgres", "user=postgres password=password dbname=name sslmode=disable")

    if err != nil {
        log.Fatal(err)
    }

     defer db.Close()
    age := 21
    rows, err := db.Query("SELECT city FROM streams WHERE id=69", age)

    fmt.Println(rows)

}

I am using what I found here https://godoc.org/github.com/lib/pq my postgres version is 9.4 and my Go Version is 1.6 . I have no idea why it is happening.

Could you add the ping code and see what error is returned?

package main

import (
    "fmt"
    "database/sql"
    _ "github.com/lib/pq"

    "log"
)

func main() {

    db, err := sql.Open("postgres", "user=postgres password=password dbname=name sslmode=disable")

    if err != nil {
        log.Fatal(err)
    }

    err = db.Ping()
    if err != nil {
        log.Fatal(err)
    }

    defer db.Close()
    age := 21
    rows, err := db.Query("SELECT city FROM streams WHERE id=$1", age)

    fmt.Println(rows)

}

Your

 rows, err := db.Query("SELECT city FROM streams WHERE id=69", age)

has to be:

 rows, err := db.Query("SELECT city FROM streams WHERE id = ?", age)

also

 defer db.Close()

goes after you execute the query.