JSP web application database connection can not load

Abderrahmen :

I made a simple MySQL connection Class and JSP but it doesn't work.

Do not give me anything no error no result !

Java Class :

package com.indemo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class TestConn {
    public static Connection getConnection(){
           Connection con = null ; 
          try {
              Class.forName("com.mysql.jdbc.Driver");
              con = DriverManager.getConnection("jdbc:mysql://localhost:8012/demojade","root"," ");
              return con ; 
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }

    }
}

JSP page :

<%@page import="java.sql.Connection" %>
<%@page import="com.indemo.TestConn" %>
<%@page import="java.sql.DriverManager" %>

<%@ page language="java" contentType="text/html; charset=windows-1256"
    pageEncoding="windows-1256"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>Insert title here</title>
</head>
<body>
<%
      TestConn db = new TestConn(); 
      Connection conn = db.getConnection(); 

      if(conn != null){
          out.println("Connect");
      }else{
          out.println("Nothing");       }


%>
</body>
</html>

I got this :

enter image description here

tomcat working well and xampp also when eclipse console do not give any error.

Wissam :

Replace e.printStacktrace(); instead of your naive System.out.println(); to see the errors and the messages about how to solve them. By the way, Check the connector version and the MySQL version mismatch. MySQL 8 needs the version 8 from the JDBC connector .jar . check this link

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=105706&siteId=1