Golang database/sql.Rows.Close function usage examples
package database/sql
Close closes the Rows, preventing further enumeration. If Next returns false, the Rows are closed automatically and it will suffice to check the result of Err. Close is idempotent and does not affect the result of Err.
Golang database/sql.Rows.Close function usage examples
Example 1:
rows, err := db.Query("select id, name from users 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)
}
Example 2:
microsecsSupported := false
if rows, err := dbt.db.Query(`SELECT cast("00:00:00.1" as TIME(1)) = "00:00:00.1"`); err == nil {
rows.Scan(µsecsSupported)
rows.Close()
}
Reference :
Advertisement
Something interesting
Tutorials
+17.6k Golang : delete and modify XML file content
+14.3k Golang : Get uploaded file name or access uploaded files
+40.5k Golang : Convert to io.ReadSeeker type
+5.4k Python : Delay with time.sleep() function example
+6.3k Golang : Selection sort example
+8.4k Golang : Generate Datamatrix barcode
+13.7k Golang : Check if an integer is negative or positive
+12.4k Golang : Encrypt and decrypt data with x509 crypto
+14k Golang : Compress and decompress file with compress/flate example
+29.4k Golang : JQuery AJAX post data to server and send data back to client example
+20k Golang : How to run your code only once with sync.Once object
+9.7k Golang : Load ASN1 encoded DSA public key PEM file example