VastbaseG100

基于openGauss内核开发的企业级关系型数据库。

Menu

附录2:调用示例

import (
	"fmt"
	"os"
	_ "pq"
	"database/sql"
)

func main(){
	var err error
connStr := "host=127.0.0.1 port=5432 user=vbadmin password=Aa123456 dbname=vastbase sslmode=disable"
db, err := sql.Open("vastbase", connStr)
if err != nil {
log.Fatal(err)
}
 //创建表
	  stmt1,err := db.Prepare("create table student(id int)")
res1,err := stmt1.Exec()

//插入数据
stmt2,err := db.Prepare("insert into test_int values($1)")
res2,err := stmt2.Exec(3)
//更新数据
stmt3,err := db.Prepare("update test_int set Num= $2 where Num = $1")
res3,err := stmt3.Exec(3,1)
//查询数据Get方法
var n int
err = db.QueryRow("select Num from test_int").Scan(&n)
fmt.Println(n)
}