(只剩20分了)问个Hibernate报错的问题 ehcache-1.1.jar这个文件copy到lib里了没? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ehcache-1.1.jar这个文件加到classpath里了 上面的请你看我的报错语言,里不是有"/Administrator/workspace/hi/lib/ehcache-"这句.我lib包里该放该加的都加了,不会有问题的. 我的"hibernate.cfg.xml":<?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="dialect">org.hibernate.dialect.MySQLDialect</property><property name="connection.driver_class">com.mysql.jdbc.Driver</property><property name="connection.url">jdbc:mysql://localhost:3306/wu</property><property name="connection.username">root</property><property name="connection.password">88888881</property><mapping resource="com/weportal/computer/Computer.hbm.xml"/></session-factory></hibernate-configuration>我的Computer.hbm.xml:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping><class name="com.weportal.computer.Computer"><id name="id" type="int"><generator class="native"/></id><property name="cpu" length="50"/></class></hibernate-mapping>我的"log4j.properties"log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.outlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.rootLogger=warn,stdout我的java main: public static void main(String[] args)throws SQLException { try{ PropertyConfigurator.configure("log4j.properties"); System.out.print("1"); Configuration cfg=new Configuration(); System.out.print("2"); cfg.configure(); System.out.print("3"); SessionFactory sf=cfg.buildSessionFactory(); System.out.print("4"); Session sess=sf.openSession(); System.out.print("5"); Computer pc=new Computer(); pc.setCpu("WUZHIHUI"); sess.save(pc); sess.flush(); sess.connection().commit(); sess.close(); System.out.print("9"); } catch(HibernateException h){System.out.print(h.toString());} } 不好意思,我程序没问题.我两个数据库下都有同样的一个表.是我select表时,use的数据库不对. 关于HTML5. 求指引 ssh整合问题 推荐本经典java入门经典的书籍 100分问高手:java怎么登陆windows域 session监听(新手必读) 如何使用xslt把2个xml文件transform,生成1个xml ? 直接在服务器端解析xml和把xml扔给客户端JS解析两者的区别,孰优孰劣? 大家说说在项目使用xml的好处(随便散100分) 高分求Borland Enterprise Server5.1版的注册机!! J2EE和EJB是什么关系,JSP又和两者是什么关系? 求救....学习时间上的矛盾 关于事务的问题?
我lib包里该放该加的都加了,不会有问题的.
<!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="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/wu
</property>
<property name="connection.username">root</property>
<property name="connection.password">88888881</property>
<mapping resource="com/weportal/computer/Computer.hbm.xml"/>
</session-factory>
</hibernate-configuration>我的Computer.hbm.xml:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.weportal.computer.Computer">
<id name="id" type="int">
<generator class="native"/>
</id>
<property name="cpu" length="50"/>
</class>
</hibernate-mapping>
我的"log4j.properties"log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.rootLogger=warn,stdout
我的java main:
public static void main(String[] args)throws SQLException
{
try{
PropertyConfigurator.configure("log4j.properties");
System.out.print("1");
Configuration cfg=new Configuration();
System.out.print("2");
cfg.configure();
System.out.print("3");
SessionFactory sf=cfg.buildSessionFactory();
System.out.print("4");
Session sess=sf.openSession();
System.out.print("5");
Computer pc=new Computer();
pc.setCpu("WUZHIHUI");
sess.save(pc);
sess.flush();
sess.connection().commit();
sess.close();
System.out.print("9");
}
catch(HibernateException h){System.out.print(h.toString());}
}
我两个数据库下都有同样的一个表.
是我select表时,use的数据库不对.