简体   繁体   中英

java.sql.SQLException: Login failed for user

I'm trying to configure Hibernate to connect to MS SQL Server 2005 Management Studio Express, but I can't login. I have searched everywhere for a solution, but cant find anything that I can find helpful.

I know the password and username are correct, but they dont seem to work. If anyone can help, I would appreciate it.

This is my configuration file:

<?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>

This is the output (Its very long, so I have included a small part of it)

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)

Try another driver and check if it works, maybe. I use this one and it works:

com.microsoft.sqlserver.jdbc.SQLServerDriver

To connect:

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

If still not working, check if you missed any config or something it's bad spelled, but seems that it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM