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

阿茶朵 2018-01-03 11:03:31
连接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]
...全文
770 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hookee 2018-01-04
  • 打赏
  • 举报
回复
404错误是url路径不对, 文件没找到,还没到连接mysql这步,可能是servlet配错了。
阿茶朵 2018-01-04
  • 打赏
  • 举报
回复
引用 1 楼 hookee的回复:
404错误是url路径不对, 文件没找到,还没到连接mysql这步,可能是servlet配错了。
可就只是测试下连接,怎么配置servlet
阿茶朵 2018-01-04
  • 打赏
  • 举报
回复
可是就是测试连接啊,servlet怎么配置?

10,612

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧