c3p0.SQLWarnings服务器用户ID 29不是数据库'defaultdb'中的有效用户

时间:2014-02-12 15:18:57

标签: hibernate sybase c3p0

我正在使用Sybase ASE和Hibernate-core 4.2.8.Final,hiberante-c3po 4.2.8.Final,hibernate-search 4.4.2.Final

我的hibernate.cfg.xml文件看起来像这样

    <property name="hibernate.connection.driver_class">com.sybase.jdbc4.jdbc.SybDataSource</property>
    <property name="hibernate.dialect">org.hibernate.dialect.SybaseDialect</property>
    <property name="hibernate.connection.url">jdbc:sybase:Tds:server:5000/dev</property>     
    <property name="hibernate.connection.username">user</property>
    <property name="hibernate.connection.password">password</property> 

    <property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
    <property name="hibernate.c3p0.min_size">10</property>
    <property name="hibernate.c3p0.max_statements">50</property>        
    <property name="hibernate.c3p0.max_size">100</property>
    <property name="hibernate.c3p0.idle_test_period">1800</property>
    <property name="hibernate.c3p0.timeout">3600</property>

当我添加hibernate.c3p0时,我得到以下SQLWarning,但当我删除它时,异常就消失了。有谁知道如何摆脱警告或defaultdb来自哪里?

c3p0.SQLWarnings Server user id 29 is not a valid user in database 'defaultdb'

java.sql.SQLWarning: Server user id 29 is not a valid user in database 'defaultdb'

    at com.sybase.jdbc4.jdbc.SybConnection.convertToWarnings(SybConnection.java:2893)
    at com.sybase.jdbc4.jdbc.SybConnection.chainWarnings(SybConnection.java:2909)
    at com.sybase.jdbc4.tds.Tds.processLoginAckToken(Tds.java:5125)
    at com.sybase.jdbc4.tds.Tds.doLogin(Tds.java:724)
    at com.sybase.jdbc4.tds.Tds.login(Tds.java:578)
    at com.sybase.jdbc4.jdbc.SybConnection.tryLogin(SybConnection.java:415)
    at com.sybase.jdbc4.jdbc.SybConnection.handleHAFailover(SybConnection.java:3226)
    at com.sybase.jdbc4.jdbc.SybConnection.<init>(SybConnection.java:341)
    at com.sybase.jdbc4.jdbc.SybConnection.<init>(SybConnection.java:248)
    at com.sybase.jdbc4.jdbc.SybDriver.connect(SybDriver.java:233)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
c3p0.SQLWarnings Cannot open default database 'defaultdb'.

2 个答案:

答案 0 :(得分:2)

无论您是否使用c3p0,几乎肯定会遇到警告,但c3p0非常挑剔定期检查Connections以获取警告并记录它们。

SQLWarnings是通常从不抛出的异常对象。它们被链接到链接列表并与Connection对象关联。在任何Connection上,您可以致电myConnection.getWarnings()来查看警告,并通过致电myConnection.clearWarnings()清除警告。

在实践中,很少有应用程序需要检查并清除警告,但c3p0会这样做,所以如果你的应用程序由于某种原因产生警告,当你打开c3p0时你会看到它们,但它们似乎会消失没有它。

如果这很烦人并且您想忽略警告,只需在您使用的任何日志记录库中关闭记录器com.mchange.v2.c3p0.SQLWarnings的日志记录。

如果您想了解这些警告而不是忽略它们,那么,您必须等待比我更了解Sybase的人做出响应。

答案 1 :(得分:1)

我对hibernate部分一无所知,但错误是由于Sybase用户配置错误造成的。 您将需要admin sql访问权限才能解决此问题。用户(suser_name(29))尚未添加到&#39; defaultdb&#39;应用程序尝试连接的(数据库名称)。

使用管理员登录,您应该执行,

sp_modifylogin suser_name(29), defdb, "defaultdb"
go

另一个机会是,用户名尚未添加到数据库&#34; defaultdb&#34;,在本例中为admin,

use "defaultdb"
go
sp_adduser user_name or suser_name(29)
go