| |
[不指定 2015/11/03 18:01 | by ipaddr ]



DB is a database handle representing a pool of zero or more underlying connections. It's safe for concurrent use by multiple goroutines.

The sql package creates and frees connections automatically; it also maintains a free pool of idle connections. If the database has a concept of per-connection state, such state can only be reliably observed within a transaction. Once DB.Begin is called, the returned Tx is bound to a single connection. Once Commit or Rollback is called on the transaction, that transaction's connection is returned to DB's idle connection pool. The pool size can be controlled with SetMaxIdleConns.

可以通过SetMaxIdelConns, SetMaxOpenConns来限制DB的连接数。


 _, err := db.Query("SELECT uId FROM tUser WHERE userName='tomzhou'")


rows, err := db.Query("SELECT uId FROM tUser WHERE userName='tomzhou'")

defer rows.Close()

Net | 评论(0) | 引用(0) | 阅读(11960)