如何应对'org.postgresql.util.PSQLException:没有为参数1指定值'? [英] How to cope with 'org.postgresql.util.PSQLException: No value specified for parameter 1'?

查看:968
本文介绍了如何应对'org.postgresql.util.PSQLException:没有为参数1指定值'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注册到我的Grails应用程序后,用户会收到一封带有确认链接的电子邮件。点击该链接,将她带到相应的启用操作。



这完美无瑕。但是,现在似乎有一个非常具体的令牌出现错误,它导致此代码段的user.save()失败:

  assert!user.isDirty()// assertion is ok 
user.enabled = true
user.confirmationToken = null
assert user.isDirty()//断言可以确定

if(user.save()){// FAILS WITH ERROR BELOW
// ...
}

Stacktrace

  [16.09.2011 11 :57:47.591] [http-bio-localhost / 127.0.0.1-8080-exec-3] 
错误
org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver
org。 apache.commons.logging.impl.SLF4JLog $处理请求时发生b
$ b例外:[GET] /用户/启用/ bc73701c-d280-4de0-8951-7af9f2a3d636
堆栈跟踪如下:
org.postgresql.util.PSQLException:否org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:178)为参数1
指定值
。在Ô rg.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:246)
处org.postgresql.jdbc2 org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
。 AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement。的java:在org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96 96)

。在myproj.UserService.enableUser(UserService.groovy:234)
。在的Myproj .UserController $ _closure8.doCall(UserController.groovy:244)
在java.util.concurrent.ThreadPoolExecutor中的$ Worker.runTask(ThreadPoolExecutor.java:885)
在java.util.concurrent.ThreadPoolExecutor中的$工人.run(ThreadPoolExecutor.java:907)
at java.la ng.Thread.run(Thread.java:619)

请注意,我可以在同一个运行实例中创建额外的用户 - 但只有该代码才会出现错误。



解决这个问题?



使用的版本:
$ b $ ul

  • PostgreSQL:9.1beta3

  • JDBC驱动程序:postgresql:9.1-901.jdbc4

  • Grails:2.0.0.BUILD-SNAPSHOT(Build#1378)



  • (由于正在开发构建这些部分,这可能是一个错误,但我不确定这一点。)

    解决方案

    如上所述 JIRA问题这个问题源于为映射类设置的唯一约束。 / p>

    将唯一约束移入映射DC解决了这个问题。


    Upon registration to my Grails app, the user receives an email with a confirmation link. Clicking that link, takes her to the according 'enable' action.

    This worked flawlessly. However, there now seems to be an error with a very specific token, which fails the user.save() of this snippet:

    assert !user.isDirty()  // assertion is ok
    user.enabled = true
    user.confirmationToken = null
    assert user.isDirty()   // assertion is ok
    
    if (user.save()) {  // FAILS WITH ERROR BELOW
        // ...
    }
    

    Stacktrace:

    [ 16.09.2011 11:57:47.591] [http-bio-localhost/127.0.0.1-8080-exec-3] 
    ERROR 
    org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver 
    org.apache.commons.logging.impl.SLF4JLog 
    
     Exception occurred when processing request: [GET] /user/enable/bc73701c-d280-4de0-8951-7af9f2a3d636
    Stacktrace follows:
    org.postgresql.util.PSQLException: No value specified for parameter 1.
            at org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:178)
            at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:246)
            at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
            at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
            at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273)
            at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
            at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
            at myproj.UserService.enableUser(UserService.groovy:234)
            at myproj.UserController$_closure8.doCall(UserController.groovy:244)
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
            at java.lang.Thread.run(Thread.java:619)
    

    Note that I can create additional users in the same running instance - but the error (so far) only occurs with that code.

    Any ideas on how to resolve that?

    Versions in use:

    • PostgreSQL: 9.1beta3
    • JDBC-driver: postgresql:9.1-901.jdbc4
    • Grails: 2.0.0.BUILD-SNAPSHOT (Build #1378)

    (Due to being on development builds for those parts, it might be a bug, but I am unsure about that.)

    解决方案

    As outlined in the mentioned JIRA issue the problem stemmed from a unique-constraint which was set for a mapped class.

    Moving the unique-contraint into the Mapping DC resolved the issue.

    这篇关于如何应对'org.postgresql.util.PSQLException:没有为参数1指定值'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆