Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何使用play framework和scala将数据插入数据库_Mysql_Scala_Playframework - Fatal编程技术网

Mysql 如何使用play framework和scala将数据插入数据库

Mysql 如何使用play framework和scala将数据插入数据库,mysql,scala,playframework,Mysql,Scala,Playframework,嗨,我正在使用play框架和scala。 将用户配置文件数据插入数据库无效。 登录和注册功能正在运行,数据库 插入和连接正确。。在控制台中,成功创建了mysql连接 可见,因此mysql连接没有问题 the method inside the application def saveUserProfile = Action { implicit request => if (request.session.get("userId") =

嗨,我正在使用play框架和scala。 将用户配置文件数据插入数据库无效。 登录和注册功能正在运行,数据库 插入和连接正确。。在控制台中,成功创建了mysql连接 可见,因此mysql连接没有问题

    the method  inside the application 

    def saveUserProfile = Action { implicit request =>
                if (request.session.get("userId") == None) {
                  Results.Redirect("/")
                } else {


                  val user_account_id = request.session.get("userId").get.toLong
                  val useraccount = UserAccount.findByUserAccountId(user_account_id).get

                  userProfileForm.bindFromRequest.fold(

                    errors => BadRequest(views.html.userProfile(errors, useraccount)),

     the real problem starts Here... when i am debug this program  the next line not executed..
                    userprofile => {

                      val userProfileOpt = UserAccount.userProfile(11)
                      println(userProfileOpt)

                    in here userProfileOpt contain null value.. that is the real problem..
                    that is userProfileOpt=null not contain the id..


                      userProfileOpt match {


                        case None =>

                          val updateduserProfile = UserProfile(NotAssigned,
                              Option(user_account_id), 
                            userprofile.name,
                            userprofile.date_of_birth, userprofile.gender, 
                            userprofile.image,userprofile.status)

                            UserProfile.insert(updateduserProfile)
                          val alert: Alert = new Alert("success", " User Profile Saved")
                          Common.setAlert(alert)


                        case Some(userProfileFound: UserProfile) =>

                          val updatedUserProfile = UserProfile(userProfileFound.id,
                            userProfileFound.user_account_id, userProfileFound.name,
                            userProfileFound.date_of_birth, userProfileFound.gender,
                            userProfileFound.image,userProfileFound.status)

                            UserProfile.update(updatedUserProfile)
                          val alert: Alert = new Alert("success", " User Profile Updated")
                          Common.setAlert(alert)
                      }
                      Results.Redirect("/userProfile")
                    })
                }
              }



and my userProfile form method is inside the application ,

  /**
   * UserProfile Form
   */
  val userProfileForm = Form(
    Forms.mapping(
      "id" -> ignored(NotAssigned: Pk[Long]),
      "user_account_id" ->optional(longNumber),
      "name" -> nonEmptyText,
      "data of birth" -> date,
      "gender" -> nonEmptyText,
      "image" -> nonEmptyText,
      "status" -> nonEmptyText )(UserProfile.apply)(UserProfile.unapply))

  def index = Action {
    val alert: Alert = new Alert("", "")
    Common.setAlert(alert)
    Ok(views.html.index(signInForm, "Friends+"))
      } 

....and the method is under..
this method inside the model and the model name is userprofile.....

 def userProfile(user_account_id:Long)={
    DB.withConnection{ implicit connection =>
    val userDetail = SQL(
    """
        select * from USER_PROFILE
        where USER_ACCOUNT_ID = {user_account_id}
    """).on(
        'user_account_id -> user_account_id).as(UserProfile.simple.singleOpt)  
        userDetail
    }
  }
    ....i am really strugle   this problem with 
     days ...
       i don't know how to handle with this problem..

我有同样的问题,我通过以下方式解决:

           val userProfileForm = Form(
            Forms.mapping(
              "id" -> ignored(NotAssigned: Pk[Long]),
              "user_account_id" -> optional(longNumber),
              "name" -> nonEmptyText,
这里的问题是出生日期的类型是日期,格式如下:

              "date_of_birth" -> date("YYYY/MM/dd"),
              "gender" -> nonEmptyText,
              "image" -> nonEmptyText,
              "status" -> nonEmptyText)
                      (UserProfile.apply)(UserProfile.unapply))
                       println("1")

我有同样的问题,我通过以下方式解决:

           val userProfileForm = Form(
            Forms.mapping(
              "id" -> ignored(NotAssigned: Pk[Long]),
              "user_account_id" -> optional(longNumber),
              "name" -> nonEmptyText,
这里的问题是出生日期的类型是日期,格式如下:

              "date_of_birth" -> date("YYYY/MM/dd"),
              "gender" -> nonEmptyText,
              "image" -> nonEmptyText,
              "status" -> nonEmptyText)
                      (UserProfile.apply)(UserProfile.unapply))
                       println("1")