【问题标题】:Groovy sql errors on remote Mysql server?远程Mysql服务器上的Groovy sql错误?
【发布时间】:2011-01-22 11:35:39
【问题描述】:

我正在使用 groovy gsql 来查询 Mysql 数据库。 localhost(测试模式)上一切顺利,不幸的是,当我切换到远程 db groovy 时,不要查询 db.

代码如下:

def sqlModule = Sql.newInstance("jdbc:mysql://localhost/module-test", "b", "b", "com.mysql.jdbc.Driver")

def sampleQuery(int dataset) {

  def SampleQueryList = []
    // Sql query
    sqlModule.eachRow("""
        select b.*
        from dataset_group_set_details a, array_data b
        where dataset_id = "${dataset}"
        and group_set_id = 1
        and a.array_data_id = b.array_data_id ;""")
        {
          def addSample= new Sample(it.toRowResult())
          addSample.id = "${it.array_data_id}" as int
          addSample.dateCreatedSample = dateFormat.parse("${it.date_created}")
          addSample.tissueTypeId = "${it.tissue_type_id}" as int
          ...
          // Add Sample to SampleList
          SampleQueryList << addSample
        }

   return SampleQueryList

在 localhost 模式下,“return SampleQueryList”会返回一个好的列表,但在远程模式下(例如:jdbc:mysql://192.168.209.32/module-test)我的列表是空的。
注意:本地主机和远程数据库中的数据库是相等的。另外,我在远程模式下没有错误。

为什么,在 localhost 模式下 groovy 查询我的数据库而不是在远程模式下?
有什么想法吗?

【问题讨论】:

    标签: sql grails groovy


    【解决方案1】:

    如果没有更多信息,就不可能肯定地说出哪里出了问题。有没有尝试过简单的

    select * from tablename
    

    查询以确保您连接到数据库?您可能尝试使用错误的用户名和密码进行连接。如果您不控制数据库限制,则可能会限制您可以使用给定用户帐户在远程服务器上执行的查询的长度和复杂性。

    【讨论】:

    • 远程数据库不等于我的本地数据库,一些列已更改,一些数据也已更改。我在查询无效的 id,这解释了为什么我的列表是空的。
    猜你喜欢
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-29
    相关资源
    最近更新 更多