eclipse连接mysql数据库总是报404错误,求帮助!

阿茶朵 阿茶朵 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
连接eclipse和mysql数据库测试时总是显示404错误,已经困扰了好几天了。

[color=#CCFFFF]package hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public class HibernateUtil {
private static SessionFactory sessionfactory;
private static final ThreadLocal<Session> threadlocal=new ThreadLocal<Session>();
static{
try{
Configuration cfg=new Configuration().configure();
ServiceRegistry srg=new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties()).build();
sessionfactory=cfg.buildSessionFactory(srg);
}catch(Exception e){
throw new ExceptionInInitializerError(e);
}
}

public static SessionFactory getSessionFactory(){
return sessionfactory;
}

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;
}

public static void closeSession() throws HibernateException{
Session session=(Session)threadlocal.get();
threadlocal.set(null);
if(session!=null){
session.close();
}
}


public static void rebuildSessionFactory(){
try{
sessionfactory=new Configuration().configure("/src/hibernate.cfg.xml").buildSessionFactory();
}catch(Exception e){
System.out.println("Error Creating sessionfactory");
e.printStackTrace();
}
}

public static void shutdown(){
getSessionFactory().close();
}
}
[/color]
...全文
评论 3
收藏 已收藏
分享
返回顶部
阿茶朵
其他 10,611 成员 29,026 内容