Caused by: java.sql.SQLException: Access denied for user 'sa'@'localhost' (using password: NO)

做了一个简单的SSH项目,在运行时候出现了一个问题:Caused by: java.sql.SQLException: Access denied for user 'sa'@'localhost' (using password: NO)

jdbc.properties

mysql.driver=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://localhost:3306/crm
mysql.user=root
mysql.password=root


    
    
    	
    
    
    
		    
		
		
		
    
    
    
		    	
		
			
				true
				update
				org.hibernate.dialect.MySQLDialect
			
		
    

在application.xml配置中dataSource使用了c3po连接池,配置了mysql数据库

在hibernate3和spring整合是可以成功连接数据库的,但是hibernate4和spring整合就会报错。

原因:

hibernate.properties中有一个默认的sa账号,在hibernate在加载配置时候,默认的sa覆盖了dataSource的user和passworrd导致连接数据库出错。

解决方法:

在sessionFactory中的hibernateProperties中加入hibernate.connection.username和hibernate.connection.password


		    	
		
			
				true
				update
				org.hibernate.dialect.MySQLDialect
				root
				root
			
		
    

你可能感兴趣的:(Caused by: java.sql.SQLException: Access denied for user 'sa'@'localhost' (using password: NO))