eclipse连接mysql数据库总是报404错误,求帮助!
连接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]

[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]
...全文
相关推荐
解决在启动eclipse的tomcat进行访问时出现404问题的方法
在排查过程中,日志文件(如`catalina.out`)通常会提供有用的线索,帮助诊断问题的根源。总之,遇到404错误时,不应立即认为是代码问题,而是要先检查配置和环境设置。
Java web项目 常见问题汇总
二、**网页报‘500’错误**500错误通常表示服务器内部出现问题。这可能与数据库连接有关:1. **数据库驱动缺失**:确保项目中包含连接数据库所需的驱动库。2.
毕业论文ssm404民宿住宿管理系统.docx
技术选型方面,MySQL作为关系型数据库,提供了稳定的数据存储支持。SpringBoot框架简化了开发流程,提高了开发效率。Eclipse作为开发工具,提供了集成开发环境,方便代码编写和调试。
Tomcat部署笔记
**数据库配置**: - 使用Navicat工具连接MySQL数据库,创建名为`test`的数据库。 - 在该数据库中创建名为`tcis`的数据表,并通过运行SQL文件的方式导入数据。
404安卓Andriod网上订餐点菜系统毕业课程源码设计+论文资料
程序测试环境: Win7 + Eclipse + 安卓Android2.3以上模拟器 + tomcat + mysql数据库程序功能说明: 使用安卓手机客户端实现的一个网络订餐系统,客户端可以


其他
