我正在 - “java.lang.ClassNotFoundException:com.mysql.jdbc.Driver”错误.Below是我的代码

时间:2014-03-03 07:42:01

标签: jsp war

我已经通过goin添加了必要的jar文件(mysql-connector-java-5.1.16-bin.jar)到build-path(添加外部jar ...)

<%@ page import="java.sql.*"%>
<%
    Connection con=null;
    Statement stmt=null;
    String pwd=null;
    ResultSet rs=null;
    try{
        String ck=request.getParameter("UserID") ; 
        String pd=request.getParameter("password") ;    
            Class.forName("com.mysql.jdbc.Driver");

           con=DriverManager.getConnection("jdbc:mysql://localhost/db_name", "username",
                       "password");
           stmt = con.createStatement();
           String sql = "select password from prac1 where empid='"+ck+"'";
           rs=stmt.executeQuery(sql);
    while(rs.next()){


         pwd=rs.getString("password");  


    }
    if(pd.equals(pwd)){

        System.out.println("Welcome"+ck+"Your password is:"+pwd);
        response.sendRedirect("abc.jsp"); 
    }
    else{
        System.out.println("Wrong username or password");
       }
    }
    catch(Exception e){
        e.printStackTrace();
    }
    finally{
        rs.close();
        stmt.close();
        con.close();
    }
 %>

感谢Adv !!!

P.s:我是jsp,jdbc的初学者!

0 个答案:

没有答案