0

I am using eclipse, wamp and tomcat to manage a project. I can run my java class and call java class with JSP. But when I use JSP call Java class, SQL in Java class not execute.

My code SQL in Java class

public P_Process() {
   try {
      Class.forName("com.mysql.jdbc.Driver");
      con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myproject?autoReconnect=true&useSSL=false",
         "root", "");
      st = con.createStatement();
   } catch (Exception ex) {
      System.out.println("Error: " + ex);
   }
}

Output :

Table A Get Data Complete!!!!!
names : 1611
Table B Get Data Complete!!!!!
tf_idf2 : 102560
Table C Get Data Complete!!!!!
idf2 : 4804
value of segmentation ............ red|black|
input >>>>>>>> red,black
input size : 2

My code JSP call Java class

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.sample.P_Process"%>

<!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=UTF-8">
      <title>Insert title here</title>
   </head>
   <body>
      <%
         P_Process start = new P_Process();
         out.print(start.process("red,black"));
      %>
   </body>
</html>

Output :

Error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
java.lang.NullPointerException
Table A Get Data Complete!!!!!
names : 0
java.lang.NullPointerException
Table B Get Data Complete!!!!!
tf_idf2 : 0
java.lang.NullPointerException
Table C Get Data Complete!!!!!
idf2 : 0
value of segmentation ............ red|black|
input >>>>>>>> red,black,
input size : 2
  • 1
    Don't you think we should see the code for `process`? Can't you use `Exception#printStackTrace` and not `System.out.println("Error: " + ex)` to figure out where the NullPointerException occurs? –  Nov 27 '16 at 19:18
  • It's show "Error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" I'm so sorry I forget uncomment println(ex) – Rasistar W'mo Nov 28 '16 at 06:34
  • You didn't provide the specific `jar` for you database. – AxelH Nov 28 '16 at 06:36
  • 1
    Possible duplicate of [Jdbc Driver Not Found](http://stackoverflow.com/questions/9937438/jdbc-driver-not-found) or [java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse](http://stackoverflow.com/q/17484764/4391450) – AxelH Nov 28 '16 at 06:37
  • this error is related to mysql jar file.have you add mysql jar file? – Sanjay Nov 28 '16 at 06:29

0 Answers0