QMCoder
2016-05-30 13:50
采纳率: 33.3%
浏览 1.5k
已采纳

java.lang.NoClassDefFoundError

package hx.nan.JDBCUtils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;

public class DBConnection {
public static String URL;
public static String USERNAME;
public static String PASSWORD;
public static String DRIVER;

private DBConnection(){}

static{
    ResourceBundle rb = ResourceBundle.getBundle("JDBCUtils.jdbc_config");
    URL = rb.getString("URL");
    USERNAME = rb.getString("USERNAME");
    PASSWORD = rb.getString("PASSWORD");
    DRIVER = rb.getString("DRIVER");
    try {
        Class.forName(DRIVER);
    } catch (ClassNotFoundException e) {
        System.out.println("驱动加载失败");
        e.printStackTrace();
    }
}
public static Connection getConnection(){
    Connection con = null;
    try {
        con = DriverManager.getConnection(URL,USERNAME,PASSWORD);
    } catch (SQLException e) {
        e.printStackTrace();
        System.out.println("获取数据库连接失败");
    }
    return con;
}
public static void close(ResultSet rs,Statement state,Connection con){
    try {
        if(rs!=null){
            rs.close();
        }
        state.close();
        con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

}
java.lang.NoClassDefFoundError: Could not initialize class hx.nan.JDBCUtils.DBConnection
hx.nan.JDBCUtils.JdbcTemplete.update(JdbcTemplete.java:30)
hx.nan.Dao.UserDaoImp.add(UserDaoImp.java:33)
hx.nan.action.RegisterAction.doPost(RegisterAction.java:29)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
如果没有静态块的话不会报错,正常运行,这是怎么回事?而且try catch也没有捕获到异常

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题