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]