java.lang.NoClassDefFoundError: Could not initialize class cn.elvis.utils.JdbcUt

拿铁 2012-05-30 07:56:19
写的jdbc工具类,前期写了测试正确,但发布到tomcat中就报这样的错误。
javax.servlet.ServletException: Servlet execution threw an exception


root cause

java.lang.NoClassDefFoundError: Could not initialize class cn.elvis.utils.JdbcUtils
cn.elvis.dao.impl.UserDaoImpl.find(UserDaoImpl.java:180)
cn.elvis.service.impl.BusinessServiceImpl.register(BusinessServiceImpl.java:15)
cn.elvis.web.controller.RegisterServlet.doGet(RegisterServlet.java:40)
cn.elvis.web.controller.RegisterServlet.doPost(RegisterServlet.java:77)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

下面是我的工具类代码

public final class JdbcUtils {

private static String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static String url="jdbc:sqlserver://localhost:1433;DatabaseName=JspWebDb";
private static String user="sa";
private static String psw="12345";

private JdbcUtils(){}

private static JdbcUtils instanse=new JdbcUtils();

public static JdbcUtils getInstanse()
{
return instanse;
}

static{
try{
Class.forName(driver);
}
catch(ClassNotFoundException e)
{
throw new ExceptionInInitializerError(e);
}

}

public static Connection getConnection() throws SQLException
{
return DriverManager.getConnection(url,user,psw);
}


public static void free(ResultSet rs,Statement st,Connection conn)
{
if(rs!=null)
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
finally
{
if(st!=null)
try {
st.close();
} catch (SQLException e) {

e.printStackTrace();
}
finally
{
if(conn!=null)
try {
conn.close();
} catch (SQLException e) {

e.printStackTrace();
}
}
}
}




}


...全文
1039 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
拿铁 2012-05-30
  • 打赏
  • 举报
回复
终于找出问题了,就是驱动包没有导入。谢谢楼上几位的帮助!
古布 2012-05-30
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

驱动包要自己手动放入吗?
[/Quote]
对,放在tomcat\common\lib下
拿铁 2012-05-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
在tomcat的webapps下面 找到你工程,
然后去WEB-INF/class/cn/elvis/utils/中看看类的class文件是否存在。
[/Quote]
文件存在。我看了。
拿铁 2012-05-30
  • 打赏
  • 举报
回复
驱动包要自己手动放入吗?
七_号 2012-05-30
  • 打赏
  • 举报
回复
在tomcat的webapps下面 找到你工程,
然后去WEB-INF/class/cn/elvis/utils/中看看类的class文件是否存在。
古布 2012-05-30
  • 打赏
  • 举报
回复
是不是报错了?放开试试。
另外驱动包放到tomcat下了把
static{
try{
Class.forName(driver);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
throw new ExceptionInInitializerError(e);
}

}
拿铁 2012-05-30
  • 打赏
  • 举报
回复
没有,只用javabean的。纠结啊!
古布 2012-05-30
  • 打赏
  • 举报
回复
貌似没错,LZ没用hibernate吧?

81,094

社区成员

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

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