本帖最后由 imxjs2011 于 2011-03-08 15:58:08 编辑

解决方案 »

  1.   

    HibernateSessionFactory:
        private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
    private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
        private static Configuration configuration = new Configuration();    
        private static org.hibernate.SessionFactory sessionFactory;
        private static String configFile = CONFIG_FILE_LOCATION; static {
        System.out.println("走了"+configuration);
         try {
    configuration.configure(configFile);
    sessionFactory = configuration.buildSessionFactory();
    } catch (Exception e) {
    System.err.println("%%%% Error Creating SessionFactory %%%%");
    e.printStackTrace();
    }
        }
        private HibernateSessionFactory() {
        }

    /**
         * Returns the ThreadLocal Session instance.  Lazy initialize
         * the <code>SessionFactory</code> if needed.
         *
         *  @return Session
         *  @throws HibernateException
         */
        public static Session getSession() throws HibernateException {
            Session session = (Session) threadLocal.get(); if (session == null || !session.isOpen()) {
    if (sessionFactory == null) {
    rebuildSessionFactory();
    }
    session = (sessionFactory != null) ? sessionFactory.openSession()
    : null;
    threadLocal.set(session);
    }        return session;
        } /**
         *  Rebuild hibernate session factory
         *
         */
    public static void rebuildSessionFactory() {
    try {
    configuration.configure(configFile);
    sessionFactory = configuration.buildSessionFactory();
    } catch (Exception e) {
    System.err.println("%%%% Error Creating SessionFactory %%%%");
    e.printStackTrace();
    }
    } /**
         *  Close the single hibernate session instance.
         *
         *  @throws HibernateException
         */
        public static void closeSession() throws HibernateException {
            Session session = (Session) threadLocal.get();
            threadLocal.set(null);        if (session != null) {
                session.close();
            }
            System.out.println("关闭session");
        }
      

  2.   

    no suitable driver,没找到合适的驱动程序
    你hibernate配置文件中connection.driver_class写错了,改为:
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
      

  3.   

    给个hibernate官方文档中的辅助类吧public class HibernateUtils {
        private static final SessionFactory sessionFactory = buildSessionFactory();
        private static SessionFactory buildSessionFactory() {
            try {
                // Create the SessionFactory from hibernate.cfg.xml
                return new Configuration().configure().buildSessionFactory();
            }
            catch (Throwable ex) {
                // Make sure you log the exception, as it might be swallowed
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
        }
        public static SessionFactory getSessionFactory() {
            return sessionFactory;
        }
    }
     
      

  4.   

    no suitable driver,没找到合适的驱动程序
    你hibernate配置文件中connection.driver_class写错了,改为:
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    你的驱动写错了
      

  5.   

    上面三味大侠驱动写成 oracle.jdbc.driver.OracleDriver 也一样
    无语
      

  6.   

    驱动包已经放到lib下了 classess12.jar
      

  7.   


     <!-- 方言 -->
            <property name="dialect">org.hibernate.dialect.OracleDialect</property>
            <!-- 驱动 -->
            <property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
            <!-- URL -->
            <property name="connection.url">jdbc:oralce:[email protected]:1521:db</property>
            <!-- 用户名 -->
            <property name="connection.username">owner</property>
            <!-- 密码 -->
            <property name="connection.password">owner</property>
            <!-- 是否打印SQL -->
            <property name="show_sql">true</property>
            
            <mapping resource="org/struts/sjgl/service/Title.hbm.xml" />
    数据库驱动字符串写错了:<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
      

  8.   

    你oracle的驱动程序放到lib下了吗
      

  9.   

    放到lib下了啊~  classess12.jar
      

  10.   

    错误说的很明显  驱动问题
      不是写错了就是项目lib下面没有相应的jar文件
      

  11.   

    问题很明显:驱动有问题哈:
     Caused by: java.sql.SQLException: No suitable driver
    开发工具有自带的驱动测试向导可以测试赛,如果LZ 用的是Oracle Database 的话可以去安装目录找所需要的jar文件哈 希望lZ尽快恢复ok哈哈 给分哦 
      

  12.   

    解决了哈~  原因如下://oracle写错  thin后应该加上 ":"
    jdbc:oralce:thin@127.0.0.1:1521:db
    jdbc:oracle:thin:@127.0.0.1:1521:db