Py学习  »  DATABASE

scala-调用mysql存储过程获取错误:在“?)”附近使用在第1行

mcvkr • 4 年前 • 335 次点击  

当我运行此代码时

 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(?) 我搜过了,好像丢了什么东西。

顺便说一下,输出是

136 - DDL is : sql : 'CALL testdb.test_procedure(?)', parameters : ['123456']
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50720
 
335 次点击  
文章 [ 1 ]  |  最新文章 4 年前
mcvkr
Reply   •   1 楼
mcvkr    4 年前

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

当这条线从,

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()