设为首页 加入收藏

TOP

go语言操作mysql范例(增删查改)(三)
2017-09-30 13:44:48 】 浏览:4399
Tags:语言 操作 mysql 范例 增删 查改
bsp;       }  
  •                 row := make(map[string]string) //每行数据  
  •                 for k, v := range values {     //每行数据是放在values里面,现在把它挪到row里  
  •                         key := column[k]  
  •                         row[key] = string(v)  
  •                 }  
  •                 results[i] = row //装入结果集中  
  •                 i++  
  •         }  
  •         for k, v := range results { //查询出来的数组  
  •                 fmt.Println(k, v)  
  •         }  
  • }  
  • 4 运行程序

        4.1 编译运行

    [plain]  view plain copy
    1. [root@localhost /]# go build MysqlGoTest.go  
    2. [root@localhost /]# ls  
    3. MysqlGoTest.go  MysqlGoTest  
    4. [root@localhost /]# ./MysqlGoTest  


     

    4.2 直接运行

    [plain]  view plain copy
    1. [root@localhost /]# go run MysqlGoTest.go  
    2. <*sql.Rows Value>  
    3. --增加数据测试--  
    4. 0 map[c1:101 c2:姓名1 c3:address1]  
    5. 1 map[c1:102 c2:姓名2 c3:address2]  
    6. 2 map[c1:103 c2:姓名3 c3:address3]  
    7. 3 map[c1:104 c2:姓名4 c3:address4]  
    8. --删除数据测试--  
    9. 0 map[c1:102 c2:姓名2 c3:address2]  
    10. 1 map[c1:103 c2:姓名3 c3:address3]  
    11. 2 map[c1:104 c2:姓名4 c3:address4]  
    12. --更新数据测试--  
    13. 0 map[c1:102 c2:姓名2 c3:address2]  
    14. 1 map[c1:103 c2:姓名3 c3:address4]  
    15. 2 map[c1:104 c2:姓名4 c3:address4]  
    16. --清空数据测试--  

     

    5 补充知识

        5.1 避免中文乱码

        为确保程序写入数据库以及从数据库读出时不出现乱码,需要做如下配置:     go客户端程序级别:     go程序文件设置编码 utf8,如

    [plain]  view plain copy
    1. db, err := sql.Open("mysql", "
    首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
    】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
    上一篇Google Go Programming In Eclipse 下一篇Go学习笔记之基础数据类型

    最新文章

    热门文章

    Hot 文章

    Python

    C 语言

    C++基础

    大数据基础

    linux编程基础

    C/C++面试题目