当前位置: 代码迷 >> Java Web开发 >> java.lang.NoClassDefFoundError: Could not initialize class cn.elvis.utils.JdbcUt,该如何处理
  详细解决方案

java.lang.NoClassDefFoundError: Could not initialize class cn.elvis.utils.JdbcUt,该如何处理

热度:5608   发布时间:2013-02-25 21:19:17
java.lang.NoClassDefFoundError: Could not initialize class cn.elvis.utils.JdbcUt
写的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)

下面是我的工具类代码
Java code
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();                            }                    }            }    }                }


------解决方案--------------------------------------------------------
探讨

驱动包要自己手动放入吗?
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!