尝试股票 Doobie 示例,并得到一个抱怨“无效列索引”的异常。我的查询非常简单:它从一个 Oracle 表中选择两列,我希望 Doobie 将其映射到具有两个匹配属性的案例类实例序列。我已经在 SQL IDE 中运行了该查询,并且运行良好。我假设 PreparedStatement(由 Doobie 创建)的参数数量与传入的参数数量(一个)不匹配 - 但我不知道为什么。这是我第一次接触 Doobie,所以我可能会误解一些简单的东西。
例外是java.sql.SQLException: Invalid column index
。知道我做错了什么吗?
import doobie._
import doobie.implicits._
import cats.effect.IO
import scala.concurrent.ExecutionContext
/**
* @see https://tpolecat.github.io/doobie/
*/
object DoobieExampleOne {
implicit val cs = IO.contextShift(ExecutionContext.global)
val jdbcUrl = "jdbc:oracle:thin:@(DESCRIPTION=...)"
val xa = Transactor.fromDriverManager[IO](
"oracle.jdbc.driver.OracleDriver", jdbcUrl, "myUser", "myPswd"
)
def main(args: Array[String]): Unit = {
find(idPrefix = "somePfx").transact(xa).unsafeRunSync
}
case class SomeEntity(identifier_value: String, some_id: Long)
def find(idPrefix: String): ConnectionIO[Option[SomeEntity]] =
// This query runs correctly on the command line
sql"SELECT identifier_value, some_id FROM some_table WHERE identifier_value LIKE '$idPrefix'"
.query[SomeEntity].option
}
// Exception in thread "main" java.sql.SQLException: Invalid column index