dqd82461 2019-02-11 07:38 采纳率: 0%
浏览 189

为什么在我使用库golang go-mssqldb连接到sql server之后,为什么打印<nil>?

I have problem , after I connection to sql server , they print <nil> , what wrong with my code or problem with my connection to sql server because they just print <nil>?

error can see in here enter image description here

package main

import (
    "database/sql"
    "fmt"
    _ "github.com/denisenkom/go-mssqldb"
    "github.com/gin-gonic/gin"
    "net/http"
)

func main()  {
    db, err :=  sql.Open("sqlserver","sqlserver://sa:@localhost:1433?database=CONFINS&connection+timeout=30")
    if err != nil{
        fmt.Print(err.Error())
    }


    err = db.Ping()

    if err != nil {
        fmt.Print(err.Error())
    }
    defer db.Close()

    type SMSBlast struct {
        SequenceID  string
        MobilePhone string
        Output  string
        WillBeSentDate string
        SentDate string
        Status string
        DtmUpd string
    }

    router := gin.Default()

    //Get a SMSBlast  detail
    router.GET("/SMSBlast2/:SequenceID", func(context *gin.Context) {
        var(
            smsblast SMSBlast
            result gin.H
        )

        SequenceID := context.Param("SequenceID")
        fmt.Println(db.Ping())
        row := db.QueryRow("select SequenceID, MobilePhone, Output, WillBeSentDate, SentDate, Status, DtmUpd from SMSBlast2 = ?;",SequenceID)
        err = row.Scan(&smsblast.SequenceID, &smsblast.MobilePhone, &smsblast.Output, &smsblast.WillBeSentDate, &smsblast.SentDate, &smsblast.Status, &smsblast.DtmUpd)
        if err != nil{
            //if no results send null
            result = gin.H{
                "result": nil,
                "count":  0,
            }
            }else{
                result = gin.H{
                    "result" : smsblast,
                    "count" : 1,
                }
            }

        context.JSON(http.StatusOK, result)
    })
    router.Run(":8080")

}
  • 写回答

2条回答 默认 最新

  • donglugou6652 2019-02-11 08:15
    关注
        fmt.Println(db.Ping())
    

    Prints the error returned by db.Ping(), which normally is nil.

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?