Click here to Skip to main content
15,887,214 members
Home / Discussions / Java
   

Java

 
GeneralRe: Hi friends I need some help regarding the following program will you please help me Pin
Leela Krishna Yadav2-Jan-15 5:14
Leela Krishna Yadav2-Jan-15 5:14 
AnswerRe: Hi friends I need some help regarding the following program will you please help me Pin
Richard MacCutchan2-Jan-15 5:46
mveRichard MacCutchan2-Jan-15 5:46 
GeneralRe: Hi friends I need some help regarding the following program will you please help me Pin
Leela Krishna Yadav2-Jan-15 5:59
Leela Krishna Yadav2-Jan-15 5:59 
QuestionHelp option in a JAR FILE Pin
ramina sen30-Dec-14 20:40
ramina sen30-Dec-14 20:40 
AnswerRe: Help option in a JAR FILE Pin
Richard MacCutchan30-Dec-14 22:09
mveRichard MacCutchan30-Dec-14 22:09 
GeneralRe: Help option in a JAR FILE Pin
ramina sen30-Dec-14 22:16
ramina sen30-Dec-14 22:16 
GeneralRe: Help option in a JAR FILE Pin
Richard MacCutchan30-Dec-14 22:47
mveRichard MacCutchan30-Dec-14 22:47 
Questionproblem to connect Java EE application to database Pin
Imad_dz29-Dec-14 6:31
Imad_dz29-Dec-14 6:31 
hi guys,
i have a problem in connecting my web application in javaEE, when i run the servlet i have an error : java.lang.NullPointerException

and this is a screenshot for the error : http://im51.gulfup.com/TnfWrg.jpg

this the code where i try to connect to the database

Java
public class login_servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
 
    public login_servlet() {
        super();
    }
 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 
        //this.getServletContext().getRequestDispatcher( "/login.jsp" ).forward( request, response );
    }
 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 
        java.sql.Connection connexion = null;
        java.sql.Statement statement = null;
        ResultSet resultat = null;
        String userQuery="";
 
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
        }
 
        try {
            connexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/Dlala", "IPLS", "password");
        } catch (SQLException e) {
            e.printStackTrace();
        }
 
        try {
            statement = connexion.createStatement();
 
            // Exécution de la requête
            resultat = statement.executeQuery("SELECT user FROM Client;");
 
            // Récupération des données
            while (resultat.next()) {
                userQuery = resultat.getString("user");
            }
        } catch (SQLException e) {
        } finally {
            // Fermeture de la connexion
            try {
                if (resultat != null)
                    resultat.close();
                if (statement != null)
                    statement.close();
                if (connexion != null)
                    connexion.close();
            } catch (SQLException ignore) {
            }
        }
        //************************************************//
 
        response.setContentType("text/html");   
        PrintWriter out = response.getWriter();   
 
        String n=request.getParameter("user");   
        String p=request.getParameter("pass");  
 
        HttpSession session = request.getSession(false); 
        if(session!=null) 
        session.setAttribute("name", n); 
 
        if( n.equals(userQuery)){   
            RequestDispatcher rd=request.getRequestDispatcher("home.jsp");   
            rd.forward(request,response);   
        }   
        else{  
            out.print("<p style=\"color:red\">Sorry username or password error</p>");   
            RequestDispatcher rd=request.getRequestDispatcher("login.jsp");   
            rd.include(request,response);   
        } 
        out.close(); 
    }
}

SuggestionRe: problem to connect Java EE application to database Pin
Richard MacCutchan29-Dec-14 23:13
mveRichard MacCutchan29-Dec-14 23:13 
Questionpagination in java swing Pin
bilalshameem25-Dec-14 23:44
bilalshameem25-Dec-14 23:44 
AnswerRe: pagination in java swing Pin
Richard MacCutchan26-Dec-14 1:05
mveRichard MacCutchan26-Dec-14 1:05 
Question[EDIT] CLASS cannot be resolved to a type Pin
AmbiguousName23-Dec-14 8:56
AmbiguousName23-Dec-14 8:56 
QuestionRe: CLASS cannot be resolved to a type Pin
Richard MacCutchan23-Dec-14 21:38
mveRichard MacCutchan23-Dec-14 21:38 
AnswerRe: [EDIT] CLASS cannot be resolved to a type Pin
alexey_s22-Jan-15 8:15
alexey_s22-Jan-15 8:15 
QuestionGabor Patch Generator Pin
amirsharifzadeh20-Dec-14 22:01
amirsharifzadeh20-Dec-14 22:01 
SuggestionRe: Gabor Patch Generator Pin
Richard MacCutchan20-Dec-14 22:14
mveRichard MacCutchan20-Dec-14 22:14 
QuestionHow to Use Delimiters in my program(Does not work and Crashes) Pin
Kaytlyn Grace Lau20-Dec-14 7:44
Kaytlyn Grace Lau20-Dec-14 7:44 
AnswerRe: How to Use Delimiters in my program(Does not work and Crashes) Pin
Richard MacCutchan20-Dec-14 21:06
mveRichard MacCutchan20-Dec-14 21:06 
AnswerRe: How to Use Delimiters in my program(Does not work and Crashes) Pin
Richard MacCutchan21-Dec-14 4:01
mveRichard MacCutchan21-Dec-14 4:01 
GeneralRe: How to Use Delimiters in my program(Does not work and Crashes)(SOLVED) Pin
Kaytlyn Grace Lau21-Dec-14 9:18
Kaytlyn Grace Lau21-Dec-14 9:18 
GeneralRe: How to Use Delimiters in my program(Does not work and Crashes)(SOLVED) Pin
Richard MacCutchan21-Dec-14 22:44
mveRichard MacCutchan21-Dec-14 22:44 
Question[SOLVED] Does not redirect properly Pin
Django_Untaken14-Dec-14 20:52
Django_Untaken14-Dec-14 20:52 
QuestionRe: Does not redirect properly Pin
Richard MacCutchan14-Dec-14 22:19
mveRichard MacCutchan14-Dec-14 22:19 
QuestionLogin Details Authentication Pin
JayantiSh13-Dec-14 12:08
JayantiSh13-Dec-14 12:08 
AnswerRe: Login Details Authentication Pin
Richard MacCutchan13-Dec-14 21:33
mveRichard MacCutchan13-Dec-14 21:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.