如何在前传中使用通配符查询?

时间:2013-07-10 17:50:48

标签: scala wildcard prequel

在前传中,使用scala进行JDBC访问的精简库,以下语句有效:

val stmt = "SELECT content FROM email WHERE to_email = '" + toEmail + "' AND subject LIKE 'Hi " + firstName + ", please activate your Account...' AND from_user_id IS NULL"
val activationRows = selectNewsDB(stmt)   

而'%foo%' -

val stmt = "SELECT content FROM email WHERE to_email = '" + toEmail + "' AND subject LIKE '%please activate%' AND from_user_id IS NULL"

失败并显示以下错误消息:

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'p'

如果我打印语句并将其复制/粘贴到mysql-console,它也能正常工作。

为了完整性,这是前缀代码,newsDB的类型为DatabaseConfig

  def selectNewsDB(stmt: String):Seq[String] ={
    newsDB.transaction { tx =>
      tx.select( stmt ) { r =>
         r.nextString.get
      }
    }
  }

1 个答案:

答案 0 :(得分:0)

找到解决方案:要使用%,我必须使用其中的两个:

  val stmt = "... subject LIKE '%%please activate%%' AND from_user_id IS NULL"