Golang database/sql.Rows type example
package database/sql
Rows is the result of a query. Its cursor starts before the first row of the result set. Use Next to advance through the rows:
Golang database/sql.Rows type usage example
var (
id int
username string
)
rows, err := db.Query("select id, username from accounts where id = ?", 1)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(&id, &name)
if err != nil {
log.Fatal(err)
}
log.Println(id, name)
}
err = rows.Err()
if err != nil {
log.Fatal(err)
}
Reference :
Advertisement
Something interesting
Tutorials
+25.6k Golang : convert rune to integer value
+16.5k Golang : Check if a string contains multiple sub-strings in []string?
+10.6k Golang : Get local time and equivalent time in different time zone
+13.9k Golang : Get current time
+6.8k Get Facebook friends working in same company
+13.6k Golang : Query string with space symbol %20 in between
+17k Golang : How to save log messages to file?
+18.6k Golang : Get download file size
+21.3k Golang : Create and resolve(read) symbolic links
+48.1k Golang : How to convert JSON string to map and slice
+10.2k Golang : Check a web page existence with HEAD request example
+5.9k Golang : Extract unicode string from another unicode string example