43640


先のご回答をいただき、おかげさまでコンパイルエラーがなくなりました。ありがとうございます！

[ProvisionException: Unable to provision / Error injecting constructor,
java.lang.NullPointerException](https://ja.stackoverflow.com/questions/43546/provisionexception-
unable-to-)  
provision-error-injecting-constructor-java-lang

ブラウザにviewは表示されるようになったのですが、以下のようなエラーが出ている状況です。

[code]

    [debug] application - Directory for migration files found. db/migration/default
    [info] play.api.Play - Application started (Dev)
    [error] s.ActiveSession - Failed preparing the statement (Reason: Could not set parameter at position 1 (values was '0')    
    Query - conn:8897(M)  - "insert into" customer (id3, status, name, sexType, zipCode1 + zipCode2, prefCode, cityName, addressName, building, email, phone, loginName, password, favoriteCategoryId)
    values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"):
    
      ()
    
     java.sql.SQLException: Could not set parameter at position 1 (values was '0')
     Query - conn:8897(M)  - "insert into" customer (id3, status, name, sexType, zipCode1 + zipCode2, prefCode, cityName, addressName, building, email, phone, loginName, password, favoriteCategoryId)
    values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
    at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getSqlException(ExceptionMapper.java:211)
    at org.mariadb.jdbc.MariaDbPreparedStatementClient.setParameter(MariaDbPreparedStatementClient.java:438)
    at org.mariadb.jdbc.BasePrepareStatement.setString(BasePrepareStatement.java:1379)
    at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setString(HikariProxyPreparedStatement.java)
    at scalikejdbc.DBConnectionAttributesWiredPreparedStatement.setString(DBConnectionAttributesWiredPreparedStatement.scala:73)
    at scalikejdbc.StatementExecutor.scalikejdbc$StatementExecutor$$bind(StatementExecutor.scala:95)
    at scalikejdbc.StatementExecutor$$anonfun$bindParams$2.apply(StatementExecutor.scala:68)
    at scalikejdbc.StatementExecutor$$anonfun$bindParams$2.apply(StatementExecutor.scala:67)
    at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:778)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:777)
    at scalikejdbc.StatementExecutor.bindParams(StatementExecutor.scala:67)
    at scalikejdbc.StatementExecutor.initialize(StatementExecutor.scala:51)
    at scalikejdbc.StatementExecutor.<init>(StatementExecutor.scala:45)
    at scalikejdbc.DBSession$class.createStatementExecutor(DBSession.scala:107)
    at scalikejdbc.DBSession$class.updateWithFilters(DBSession.scala:476)
    at scalikejdbc.ActiveSession.updateWithFilters(DBSession.scala:716)
    at scalikejdbc.DBSession$class.updateWithFilters(DBSession.scala:456)
    at scalikejdbc.ActiveSession.updateWithFilters(DBSession.scala:716)
    at scalikejdbc.SQLUpdate.apply(SQL.scala:638)
    at com.github.j5ik2o.spetstore.application.controller.SignupCustomerJson$$anonfun$1.apply(SignupControllerSupport.scala:140)
    at com.github.j5ik2o.spetstore.application.controller.SignupCustomerJson$$anonfun$1.apply(SignupControllerSupport.scala:130)
    at scalikejdbc.DBConnection$$anonfun$3.apply(DBConnection.scala:326)
    at scalikejdbc.DBConnection$class.scalikejdbc$DBConnection$$rollbackIfThrowable(DBConnection.scala:290)
    at scalikejdbc.DBConnection$class.localTx(DBConnection.scala:319)
    at scalikejdbc.DB.localTx(DB.scala:60)
    at scalikejdbc.DB$.localTx(DB.scala:263)
    at com.github.j5ik2o.spetstore.application.controller.SignupCustomerJson$.insert(SignupControllerSupport.scala:130)
    at com.github.j5ik2o.spetstore.application.controller.SignupController.insert(SignupController.scala:89)
    at com.github.j5ik2o.spetstore.application.controller.SignupController$$anonfun$signupresult$1$$anonfun$apply$2.apply(SignupController.scala:79)
    at com.github.j5ik2o.spetstore.application.controller.SignupController$$anonfun$signupresult$1$$anonfun$apply$2.apply(SignupController.scala:76)
    at play.api.data.Form.fold(Form.scala:139)
    at com.github.j5ik2o.spetstore.application.controller.SignupController$$anonfun$signupresult$1.apply(SignupController.scala:72)
    at com.github.j5ik2o.spetstore.application.controller.SignupController$$anonfun$signupresult$1.apply(SignupController.scala:71)
    at play.api.mvc.ActionBuilder$$anonfun$apply$13.apply(Action.scala:371)
    at play.api.mvc.ActionBuilder$$anonfun$apply$13.apply(Action.scala:370)
    at play.api.mvc.Action$.invokeBlock(Action.scala:498)
    at play.api.mvc.Action$.invokeBlock(Action.scala:495)
    at play.api.mvc.ActionBuilder$$anon$2.apply(Action.scala:458)
    at play.api.mvc.Action$$anonfun$apply$2$$anonfun$apply$5$$anonfun$apply$6.apply(Action.scala:112)
    at play.api.mvc.Action$$anonfun$apply$2$$anonfun$apply$5$$anonfun$apply$6.apply(Action.scala:112)
    at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
    at play.api.mvc.Action$$anonfun$apply$2$$anonfun$apply$5.apply(Action.scala:111)
    at play.api.mvc.Action$$anonfun$apply$2$$anonfun$apply$5.apply(Action.scala:110)
    at scala.Option.map(Option.scala:146)
    at play.api.mvc.Action$$anonfun$apply$2.apply(Action.scala:110)
    at play.api.mvc.Action$$anonfun$apply$2.apply(Action.scala:103)
    at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251)
    at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
    at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.apply$mcV$sp(BatchingExecutor.scala:91)
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.apply(BatchingExecutor.scala:91)
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.apply(BatchingExecutor.scala:91)
    at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72)
    at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:90)
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:39)
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:415)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
    
[/code]

またhelperで受け取っているデータは、以下のクラスで定義されている型に合わせているのですが、

[code]

     case class CustomerJson(
      id: Option[String],
      name: String,
      sexType: Int,
      zipCode1: String,
      zipCode2: String,
      prefCode: Int,
      cityName: String,
      addressName: String,
      buildingName: Option[String],
      email: String,
      phone: String,
      loginName: String,
      password: String,
      favoriteCategoryId: Option[String],
      version: Option[Long]
    )
    
[/code]

ご指摘の通り、DBInitializer.scalaの方では、

[code]

                    sql"""    
    CREATE TABLE `customer` (
      `pk`                    BIGINT        NOT NULL AUTO_INCREMENT,
      `id`                    BIGINT        NOT NULL,    
      `status`                INT           NOT NULL,
      `name`                  VARCHAR(256)  NOT NULL,
      `sex_type`              INT       NOT NULL,
      `zip_code`              VARCHAR(20)   NOT NULL,
      `pref_code`             INT           NOT NULL,
      `city_name`             VARCHAR(256)  NOT NULL,
      `address_name`          VARCHAR(256)  NOT NULL,
      `building_name`         VARCHAR(256),
      `email`                 VARCHAR(64)   NOT NULL,
      `phone`                 VARCHAR(64)   NOT NULL,
      `login_name`            VARCHAR(64)   NOT NULL,
      `password`              VARCHAR(64)   NOT NULL,
      `favorite_category_id`  BIGINT,
      PRIMARY KEY(`pk`),
      UNIQUE(`id`)
     );
     """.execute().apply()
    
[/code]

idがBIG
INTになっているので、どうやって合わせれば良いのだろう・・・と考えてしまっているところです(サンプルが不完全なのか、自分で改変してしまっても問題ないのか、自信がないところでもあるのですが…）

なお、当初INSERT文に加えていた pkは、AUTO
INCREMENTであるため、外した方がいいのかと思われ外しました（判断があってるのかもわかりません）。id3となっているのは、

<https://github.com/scalikejdbc/scalikejdbc/issues/561>

こちらを参考にして、

[code]

    val point = SQLSyntax.createUnsafely(s"PointFromText(POINT($lat $long))")
    
[/code]

この point にあたるものを(($lat $long)の部分に$idを入れて）改めて置いて見ただけなのですが、q.statement
の部分をsqliterpolationで書く場合、どうしていいかもわからず無視してしまってるので、結局意味がない状況です。


CC BY-SA 3.0
2018-04-28T16:37:37.713
43639
2018-04-28T18:01:52.883
2018-04-28T17:00:41.183
28048
28048
question
scala playframework mariadb scalikejdbc
s.ActiveSession - Failed preparing the statement (Reason: Could not set parameter at position 1 (values was '0')


恐らくですが、insert文の2番目の列名である`status`がMySQL(MariaDB)のキーワードであることが原因で、preparing the
statementが正しく設定できてない可能性があります。

SQLでキーワードや予約語を使用する場合、バッククォートで囲む必要があります。  
※今回のケースでは`status`, `name`, `password`が該当します

SQLを実行している箇所のソースコードを以下のように変更してみてください。

[code]

    def insert(customerJson: CustomerJson): Unit = {
      try {
        DB localTx { implicit session =>
          val id = System.currentTimeMillis()
          val status = 0
    
          import customerJson._
          sql"""insert into customer (id, `status`, `name`, sex_type, zip_code, pref_code, city_name, address_name, building_name, email, phone, login_name, `password`, favorite_category_id)
               |values ($id, $status, $name, $sexType, ${zipCode1 + zipCode2}, $prefCode, $cityName, $addressName, $buildingName, $email, $phone, $loginName, $password, $favoriteCategoryId)"""
            .stripMargin
            .update()
            .apply()
        }
      } catch {
        case e: Exception => e.printStackTrace()
      }
    }
    
[/code]

MySQLのキーワードや予約語については以下のページをご参照ください。  
<https://dev.mysql.com/doc/refman/8.0/en/keywords.html>


CC BY-SA 3.0
2018-04-28T18:01:52.883
43640
2018-04-28T18:01:52.883
3068
43639
answer