【问题标题】:scala - calling mysql stored procedure getting error : use right near '?)' at line 1scala - 调用mysql存储过程出错:在第1行的'?)'附近使用
【发布时间】:2020-01-14 21:42:45
【问题描述】:

当我运行这段代码时

 conn = connPool.getDBConnection
  val id: String = "123456"
  val query: String = "CALL testdb.test_procedure(?)"
  stmt = conn.prepareStatement(query)
  stmt.setString(1, id)
  logger.info("DDL is : " + stmt.toString)
  val result = stmt.executeUpdate(query)

我明白了

java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?)' at line 1

当我使用CALL testdb.test_procedure(?)从mysql客户端调用相同的过程时,它可以工作,我已经搜索过,看起来我错过了一些东西。

顺便说一下输出

136 - DDL is : sql : 'CALL testdb.test_procedure(?)', parameters : ['123456']

【问题讨论】:

    标签: mysql scala stored-procedures jdbc


    【解决方案1】:

    这是我的错,我混淆了方法签名,编码晚有一些副作用。

    当这条线被替换时它工作得很好,

    val result = stmt.executeUpdate(query)
    

    val result = stmt.executeUpdate()
    

    所以运行代码是

      conn = connPool.getDBConnection
      val id: String = "123456"
      val query: String = "CALL testdb.test_procedure(?)"
      stmt = conn.prepareStatement(query)
      stmt.setString(1, id)
      logger.info("DDL is : " + stmt.toString)
      val result = stmt.executeUpdate()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 2011-01-24
      • 2014-11-23
      • 1970-01-01
      • 1970-01-01
      • 2021-10-05
      相关资源
      最近更新 更多