这是hibernate.cfg.xml配置文件,用户名和密码都用jdbc测试过可以连接上
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.uesrname">root</property>
<property name="hibernate.connection.password">liangqichan</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/cql1</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="com/cql/crm/domain/SysUserGroup.hbm.xml"/>
</session-factory>
</hibernate-configuration>
这是报错信息:
2016-6-30 11:56:43 org.hibernate.cfg.Environment
信息: Hibernate 3.5.6-Final
2016-6-30 11:56:43 org.hibernate.cfg.Environment
信息: hibernate.properties not found
2016-6-30 11:56:43 org.hibernate.cfg.Environment buildBytecodeProvider
信息: Bytecode provider name : javassist
2016-6-30 11:56:43 org.hibernate.cfg.Environment
信息: using JDK 1.4 java.sql.Timestamp handling
2016-6-30 11:56:43 org.hibernate.cfg.Configuration configure
信息: configuring from resource: /hibernate.cfg.xml
2016-6-30 11:56:43 org.hibernate.cfg.Configuration getConfigurationInputStream
信息: Configuration resource: /hibernate.cfg.xml
2016-6-30 11:56:43 org.hibernate.cfg.Configuration addResource
信息: Reading mappings from resource : com/cql/crm/domain/SysUserGroup.hbm.xml
2016-6-30 11:56:43 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
信息: Mapping class: com.cql.crm.domain.SysUserGroup -> sys_user_group
2016-6-30 11:56:43 org.hibernate.cfg.Configuration doConfigure
信息: Configured SessionFactory: null
2016-6-30 11:56:43 org.hibernate.connection.DriverManagerConnectionProvider configure
信息: Using Hibernate built-in connection pool (not for production use!)
2016-6-30 11:56:43 org.hibernate.connection.DriverManagerConnectionProvider configure
信息: Hibernate connection pool size: 20
2016-6-30 11:56:43 org.hibernate.connection.DriverManagerConnectionProvider configure
信息: autocommit mode: false
2016-6-30 11:56:43 org.hibernate.connection.DriverManagerConnectionProvider configure
信息: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/cql1
2016-6-30 11:56:43 org.hibernate.connection.DriverManagerConnectionProvider configure
信息: connection properties: {uesrname=root, password=****}
2016-6-30 11:56:43 org.hibernate.cfg.SettingsFactory buildSettings
警告: Could not obtain connection to query metadata
java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES
补充:
这是我测试hibernate时的代码
package junit;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.junit.Test;
import com.cql.crm.domain.SysUserGroup;
public class TestHibernate {
@Test
public void testHibernateConf(){
Configuration config=new Configuration();
//config.configure("hibernate.cfg.xml");
config.configure();
SessionFactory sf=config.buildSessionFactory();
Session s=sf.openSession();
Transaction tx=s.beginTransaction();
SysUserGroup sysUserGroup=new SysUserGroup();
sysUserGroup.getName();
sysUserGroup.getPrincipal();
sysUserGroup.getIncumbent();
s.save(sysUserGroup);
tx.commit();
s.close();
}
}
这是我jdbc连接时的代码:
public class jdbc {
public static void main(String[] args) {
String url="jdbc:mysql://localhost:3306/cql";
String user="root";
String password="liangqichan";
String sql="Select * from sys_user_group";
Connection conn=null;
Statement st=null;
ResultSet rs=null;
try {
conn=(Connection) DriverManager.getConnection(url, user, password);
st=(Statement) conn.createStatement();
rs=st.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getString("id"));
System.out.println(rs.getString("name"));
System.out.println(rs.getString("remark"));
}
rs.close();
st.close();
conn.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}