no suitable driver,没找到合适的驱动程序 你hibernate配置文件中connection.driver_class写错了,改为: <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
给个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; } }
no suitable driver,没找到合适的驱动程序 你hibernate配置文件中connection.driver_class写错了,改为: <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> 你的驱动写错了
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");
}
你hibernate配置文件中connection.driver_class写错了,改为:
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
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;
}
}
你hibernate配置文件中connection.driver_class写错了,改为:
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
你的驱动写错了
无语
<!-- 方言 -->
<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>
不是写错了就是项目lib下面没有相应的jar文件
Caused by: java.sql.SQLException: No suitable driver
开发工具有自带的驱动测试向导可以测试赛,如果LZ 用的是Oracle Database 的话可以去安装目录找所需要的jar文件哈 希望lZ尽快恢复ok哈哈 给分哦
jdbc:oralce:thin@127.0.0.1:1521:db
jdbc:oracle:thin:@127.0.0.1:1521:db