| // Copyright 2013 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| rows, err := db.Query("SELECT name FROM users WHERE age=?", age) |
| if err := rows.Scan(&name); err != nil { |
| fmt.Printf("%s is %d\n", name, age) |
| if err := rows.Err(); err != nil { |
| func ExampleDB_QueryRow() { |
| err := db.QueryRow("SELECT username FROM users WHERE id=?", id).Scan(&username) |
| case err == sql.ErrNoRows: |
| log.Printf("No user with that ID.") |
| fmt.Printf("Username is %s\n", username) |