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
+31.9k Golang : Convert an image file to []byte
+19.2k Golang : Check whether a network interface is up on your machine
+12.1k Golang : md5 hash of a string
+12.7k Golang : Remove or trim extra comma from CSV
+11.9k Golang : Convert(cast) bigint to string
+5.6k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+12.1k Golang : Pagination with go-paginator configuration example
+16.4k Golang : Convert slice to array
+14.8k Golang : Normalize unicode strings for comparison purpose
+5.2k Responsive Google Adsense
+10.6k Golang : Get local time and equivalent time in different time zone
+7.1k Golang : Get environment variable