在myeclipse中
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
Configuration cfg = new Configuration().addFile("src\\Newtable.hbm.xml");
SessionFactory cf = cfg.buildSessionFactory();
Session session = cf.openSession();
Transaction tx = session.beginTransaction();
Newtable test = new Newtable();
test.setName("haha");
test.setTel("134");
session.save(test);
tx.commit();
session.close();

}
catch(Exception ex)
{
System.out.print(ex.toString());
}请高手指教上面是什么问题

解决方案 »

  1.   

    检查 配置文件中 hibernate.hbm.xml,是否配置了数据库名、用户名、密码.
      

  2.   

    我已经配过了<session-factory>
    <property name="myeclipse.connection.profile">myhib</property>
    <property name="connection.url">
    jdbc:mysql://localhost:3306/test
    </property>
    <property name="connection.username">huang</property>
    <property name="connection.password"></property>
    <property name="connection.driver_class">
    com.mysql.jdbc.Driver
    </property>
    <property name="dialect">
    org.hibernate.dialect.MySQLDialect
    </property>
    <mapping resource="/Newtable.hbm.xml" />
    </session-factory>