0

我正在尝试将 Hibernate 配置为连接到 MS SQL Server 2005 Management Studio Express,但我无法登录。我到处寻找解决方案,但找不到任何我能找到有用的东西。

我知道密码和用户名是正确的,但它们似乎不起作用。如果有人可以提供帮助,我将不胜感激。

这是我的配置文件:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
  <!-- Database connection settings -->
  <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
  <property name="connection.url">jdbc:jtds:sqlserver://***********/**********; databaseName=Scores</property>
  <property name="connection.username">*****</property>
  <property name="connection.password">******</property>

  <!-- JDBC connection pool (use the built-in) -->
  <property name="connection.pool_size">1</property>

  <!-- SQL dialect -->
  <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>

  <!-- Enable Hibernate's automatic session context management -->
  <property name="current_session_context_class">thread</property>

  <!-- Disable the second-level cache -->
  <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

  <!-- Echo all executed SQL to stdout -->
  <property name="show_sql">true</property>

  <!-- Drop and re-create the database schema on startup -->
  <property name="hbm2ddl.auto">update</property>

  <!-- Mapping files -->
  <mapping resource="player.hbm.xml"/>

 </session-factory>
</hibernate-configuration>

这是输出(它很长,所以我已经包含了它的一小部分)

50 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
54 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Environment - hibernate.properties not found
59 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
83 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
278 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
278 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
1373 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : player.hbm.xml
1480 [http-bio-8080-exec-10] INFO org.hibernate.cfg.HbmBinder - Mapping class: database.Player -> users
1525 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
1697 [http-bio-8080-exec-10] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
1697 [http-bio-8080-exec-10] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 1
1697 [http-bio-8080-exec-10] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
1700 [http-bio-8080-exec-10] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: net.sourceforge.jtds.jdbc.Driver at URL: jdbc:jtds:sqlserver://    50 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
54 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Environment - hibernate.properties not found
59 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
83 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
278 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
278 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
1373 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : player.hbm.xml
1480 [http-bio-8080-exec-10] INFO org.hibernate.cfg.HbmBinder - Mapping class: database.Player -> users
1525 [http-bio-8080-exec-10] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
1697 [http-bio-8080-exec-10] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
1697 [http-bio-8080-exec-10] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 1
1697 [http-bio-8080-exec-10] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
1700 [http-bio-8080-exec-10] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: net.sourceforge.jtds.jdbc.Driver at URL: jdbc:jtds:sqlserver://********-PC/*********; databaseName=Scores
1700 [http-bio-8080-exec-10] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=****, password=****}
2169 [http-bio-8080-exec-10] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
java.sql.SQLException: Login failed for user '****'.
    at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372)
    at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2893)
    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2335)
    at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:609)
    at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:369)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:183)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source); databaseName=Scores
1700 [http-bio-8080-exec-10] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=****, password=****}
2169 [http-bio-8080-exec-10] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
java.sql.SQLException: Login failed for user '****'.
    at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372)
    at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2893)
    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2335)
    at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:609)
    at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:369)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:183)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)

3293 [http-bio-8080-exec-10] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - could not complete schema update
java.sql.SQLException: Login failed for user '*****'.
    at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372)
    at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2893)
    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2335)
    at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:609)
    at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:369)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:183)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)

3447 [http-bio-8080-exec-10] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 18456, SQLState: 28000
3447 [http-bio-8080-exec-10] ERROR org.hibernate.util.JDBCExceptionReporter - Login failed for user '*****'.
org.hibernate.exception.GenericJDBCException: Cannot open connection
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
    at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
    at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)
    at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
    at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354)
    at database.ScoreDB.addPlayerScore(ScoreDB.java:17)
4

1 回答 1

0

尝试另一个驱动程序并检查它是否有效,也许。我使用这个并且它有效:

com.microsoft.sqlserver.jdbc.SQLServerDriver

连接:

jdbc:sqlserver://SERVER[\\INSTANCE];DatabaseName=dbname

如果仍然无法正常工作,请检查您是否遗漏了任何配置或拼写错误的内容,但它似乎应该可以工作。

于 2013-05-03T09:51:31.407 回答