首页 文章

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:'field list'中的未知列'RECEPTORS.r_name'

提问于
浏览
1

我正在使用play 2.3.8框架来创建API并访问mariaDB . 当我在mariaDB控制台上运行查询时,它工作正常但是当我从播放它运行时,我得到错误,字段RECEPTORS.r_name不可用,这是不正确的 .

My code is

package models.dao

import anorm._
import models.Profile
import play.api.db.DB
import play.api.Play.current

object ProfileDAO {

def index(r_name: String): List[Profile] = {
  DB.withConnection { implicit c =>
    val results = SQL(
      """
        | SELECT `RECEPTORS.r_name`,`RECEPTORS.pdbCode`, `LIGANDS.l_id`, `LIGANDS.l_score` 
        | FROM `RECEPTORS`
        | INNER JOIN `LIGANDS`
        | WHERE `RECEPTORS.r_name`={r_name};
      """.stripMargin).on(
        "r_name" -> r_name
      ).apply()

    results.map { row =>
      Profile(row[String]("r_name"), row[String]("pdbCode"),row[String]("l_id"),row[Double]("l_score"))
    }.force.toList
  }
 }

}

Query that I ran on mariaDB console is

SELECT RECEPTORS.r_name, pdbCode, l_id, l_score FROM RECEPTORS INNER JOIN LIGANDS WHERE RECEPTORS.r_name="receptor";

Error which running with Play 2.3.8 is as follows

laeeq @ optiplex:〜/ Desktop / Backup / Project5 / cpvsAPI $ sbt -jvm-debug 9999运行侦听传输dt_socket at address:9999 [info]从/ home / laeeq / Desktop / Backup / Project5 / cpvsAPI /中加载项目定义project [info]将当前项目设置为cpvsAPI(在构建文件中:/ home / laeeq / Desktop / Backup / Project5 / cpvsAPI /)[info]更新{file:/ home / laeeq / Desktop / Backup / Project5 / cpvsAPI /} root ... [info]解析jline#jline; 2.11 ... [info]完成更新 . ---(运行应用程序,启用自动重新加载)--- [info] play - 在/ 0上侦听HTTP:0:0:0:0:0:0:0:9000(服务器启动,使用Ctrl D停止并返回控制台...)SLF4J:在初始化阶段,可能已访问以下一组替代 Logger SLF4J:在此SLF4J:阶段期间记录呼叫不受尊重 . 但是,对这些SLF4J的后续日志记录调用: Logger 将按预期正常工作 . SLF4J:另请参见http://www.slf4j.org/codes.html#substituteLogger SLF4J:org.webjars.WebJarExtractor [info]将1个Scala源编译为/ home / laeeq / Desktop / Backup / Project5 / cpvsAPI / target / scala -2.11 / classes ... [info] play - 数据库[默认]连接在jdbc:mysql:// localhost:3306 / db_profile [info] play - 应用程序启动(Dev)[错误]应用程序 - ! @ 766oc7b8l - 内部服务器错误,对于(GET)[/ profiles / receptor] - > play.api.Application $$ anon $ 1:执行异常[[MySQLSyntaxErrorException:'字段列表中的未知列'RECEPTORS.r_name']] at play.api.Application $ class.handleError(Application.scala:296)〜[play_2.11-2.3.8.jar:2.3.8] at play.api.DefaultApplication.handleError(Application.scala:402)[play_2 . 11-2.3.8.jar:2.3.8] at play.core.server.netty.PlayDefaultUpstreamHandler $$ anonfun $ 14 $$ anonfun $ apply $ 1.applyOrElse(PlayDefaultUpstreamHandler.scala:205)[play_2.11-2.3.8 . jar:2.3.8] at play.core.server.netty.PlayDefaultUpstreamHandler $$ anonfun $ 14 $$ anonfun $ apply $ 1.applyOrElse(PlayDefaultUpstreamHandler.scala:202)[play_2.11-2.3.8.jar:2.3.8]在scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)[scala-library-2.11.1.jar:na]引起:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:未知列'RECEPTORS.r_name'在'field list'中的sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nat ive方法)〜[na:1.8.0_151] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)〜[na:1.8.0_151] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)〜 [na:1.8.0_151] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)〜[na:1.8.0_151] at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)〜 [MySQL的连接器的Java-5.1.18.jar:NA]

1 回答

  • 0

    您需要单独引用表和列,因此使用:

    `RECEPTORS`.`r_name`
    

    否则MySQL认为你试图在一些隐式表中引用名为 RECEPTORS.r_name 的列 .

    您需要为所有(引用的)列引用执行此操作 . 特别是在这种情况下,引用似乎是不必要的,所以你也可以只使用 RECEPTORS.r_name 而不需要反引号 .

相关问题