Skip to content

Exec

Exec 方法用给定的参数执行一条准备好的 SQL 语句,并返回一个 Result 类型的结果对象。

函数语法

func (s *Stmt) Exec(args ...interface{}) (Result, error)

示例

package main

import (
   _ "./go-driver-xugusql"
   "database/sql"
   “log”
)

func main() {
   db, _ := sql.Open("xugusql", "IP=192.168.78.130;DB=SYSTEM;User=SYSDBA;"
       + "PWD=SYSDBA;Port=5138;AUTO_COMMIT=on;CHAR_SET=UTF8")

   stmt, err := db.Prepare(“insert into go_test values(?, ?);”)
   if err != nil {
       log.Fatal(err)
   }

   res, _ := stmt.Exec(4, “Exec”)
   id, _ := res.LastInsertId()

   stmt.Close()
   db.Close()

}