数据库连接错误与编码相关联 [英] database connection error associated with the encoding

查看:329
本文介绍了数据库连接错误与编码相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Spring + Hibernate 应用程序。

我使用PostgreSQL作为数据存储。

I use PostgreSQL as data store.

应用程序编译好,但是当我将其部署到 Tomcat 并启动它请参阅以下堆栈跟踪:

application compiles good but when I deployed it to Tomcat and launch it I see following stacktrace:

  INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
    WARN : org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 28P01
    ERROR: org.hibernate.util.JDBCExceptionReporter - ?????: ???????????? "my_db" ?? ?????? ???????? ??????????? (?? ??????)
    WARN : org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 28P01
    ERROR: org.hibernate.util.JDBCExceptionReporter - ?????: ???????????? "my_db" ?? ?????? ???????? ??????????? (?? ??????)
    ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection
    at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:597)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:372)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:417)
    .....
    Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
    ....
    at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:556)
    ... 57 more
    Caused by: org.postgresql.util.PSQLException: ?????: ???????????? "my_db" ?? ?????? ???????? ??????????? (?? ??????)
    at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:291)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:108)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
    at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
    at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:30)
    at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
    at org.postgresql.Driver.makeConnection(Driver.java:393)
    ...
    ... 62 more

在另一台电脑上,这个应用程序启动很好。区别:区域设置工作电脑有英文但不是另一个 -

On another PC this application launch good. Difference: locale. Working PC has English language but another - not.

请帮忙找出问题的原因。

Please help to find cause of the problem.

更新

看起来数据库不明白密码:

Looks like database doesn't understand password:

from: PostgreSQL错误代码


28P01 INVALID PASSWORD invalid_password

28P01 INVALID PASSWORD invalid_password



更新



我不知道问题的原因,但数据库恢复后问题消失。

update

I didn't know the cause of the problem but problem disappear after database recreation.

推荐答案

这是一个已知的问题使用PostgreSQL版本3协议,客户端不知道编码以解码服务器在协议握手早期发送的错误消息。

This is a known issue with the PostgreSQL version 3 protocol, where the client doesn't know the encoding to decode error messages sent by the server early in the protocol handshake.

它将被修复版本4协议生成,但这还有很长的路要走。

It will be fixed when the version 4 protocol is produced, but that's a long way off yet.

同时,唯一真正的解决方法以确保客户端的默认编码与服务器的兼容。最简单的方法是将 LC_MESSAGES 设置为 en_US.UTF-8 ,或许通过 lc_messages 选项在 postgresql.conf

In the mean time the only real workaround is to make sure that the client's default encoding is compatible with the server's. The easiest way to do that is to set LC_MESSAGES to something like en_US.UTF-8, perhaps via the lc_messages option in postgresql.conf.

这篇关于数据库连接错误与编码相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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