golang????mysql????????
???????????? ???????[ 2014/2/20 14:30:27 ] ???????????????? ???????
package main
import (
"fmt"
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
type TestMysql struct {
db * sql.DB
}
func Init()(*TestMysql?? error) {
test := new (TestMysql)
db?? err := sql.Open("mysql"??"root:@tcp(172.16.3.8:3306)/jackma?charset=utf8")
if err != nil {
fmt.Println(err.Error())
return test??nil
}
test.db = db
return test?? nil
}
func (test* TestMysql)Create(){
if test.db == nil {
return
}
stmt ?? err := test.db.Prepare("insert into test(name?? id) values (??? ?)")
if err != nil {
fmt.Println(err.Error())
return
}
defer stmt.Close()
if result?? err := stmt.Exec("jack"??20); err == nil {
if id?? err := result.LastInsertId(); err == nil {
fmt.Println("insert id :"??id)
}
}
if result?? err := stmt.Exec("jack2"??30); err == nil {
if id?? err := result.LastInsertId(); err == nil {
fmt.Println("insert id :"??id)
}
}
if result?? err := stmt.Exec("jack3"??40); err == nil {
if id?? err := result.LastInsertId(); err == nil {
fmt.Println("insert id :"??id)
}
}
if result?? err := stmt.Exec("jack4"??60); err == nil {
if id?? err := result.LastInsertId(); err == nil {
fmt.Println("insert id :"??id)
}
}
}
func (test *TestMysql)Update(){
if(test.db == nil){
return
}
stmt?? err := test.db.Prepare("update test set name =? where id = ?")
if err != nil {
fmt.Println(err.Error())
return
}
defer stmt.Close()
if result?? err := stmt.Exec("jackma4888"??60); err == nil {
if c?? err := result.RowsAffected(); err == nil {
fmt.Println("update count:"??c)
}
}
}
func (test* TestMysql)Read(){
if test.db == nil{
return
}
rows ?? err := test.db.Query("select id?? name from test")
if err != nil {
fmt.Println(err.Error())
return
}
defer rows.Close()
fmt.Println("")
clos?? _ := rows.Columns()
for i := range clos {
fmt.Print(clos[i])
fmt.Print(" ")
}
fmt.Println("")
var id int;
var name string;
for rows.Next() {
if err := rows.Scan(&id?? &name); err != nil {
fmt.Print(id)
fmt.Print(" ")
fmt.Print(name)
fmt.Print(" ")
fmt.Print("
")
}
}
}
func (test *TestMysql) Delete(){
if test.db == nil{
return
}
stmt ?? err := test.db.Prepare("delete from test where id = ?")
if err != nil {
fmt.Println(err.Error())
return
}
defer stmt.Close()
if result?? err := stmt.Exec(20); err == nil {
if c?? err := result.RowsAffected(); err == nil {
fmt.Println("delete count :"??c)
}
}
}
func (test *TestMysql)Close(){
if test.db != nil {
test.db.Close()
}
}
func main(){
if test?? err := Init(); err == nil {
fmt.Println("create:")
test.Create()
fmt.Println("update:")
test.Update()
fmt.Println("read:")
test.Read()
fmt.Println("delete:")
test.Delete()
test.Read()
fmt.Println("close:")
test.Close()
}
}
|
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
???д?ò??????????????????????д?淶??α??????????????????????????????????????????????????????е?Ч?????в????г??????????????????????в?????????????в????г????????????????????????????в????е???????????????????????????????????????ж??????????????????????????????ALM(??????????????)????????????????excel????????ALM(??????????????)????????????????????????????????????????????????д????????????????????????????????????????????????????????????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????