Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
What's wrong with my code that it keeps giving me this error?




org.apache.jasper.JasperException: Exception in JSP: /datainsert.jsp:37

34: String check = request.getParameter("check");
35:
36: Statement movieInsert = null;
37: movieInsert = connection.createStatement();
38:
39: try{
40: Class.forName("com.mysql.jdbc.Driver").newInstance();


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause

java.lang.NullPointerException
org.apache.jsp.datainsert_jsp._jspService(datainsert_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
Posted
Comments
Mohibur Rashid 29-Apr-15 20:29pm    
Look at this:
java.lang.NullPointerException
org.apache.jsp.datainsert_jsp._jspService(datainsert_jsp.java:79)
Member 11653108 29-Apr-15 22:55pm    
java.sql.Connection connection=null;

String connectionURL = ";

String Driver="come.mysql.jdbc.Driver";

String username=";

String password="";

String newMovieName = request.getParameter("newMovieName");

String NewMainActor = request.getParameter("NewMainActor");

String NewMainActress = request.getParameter("NewMainActress");

String NewRating = request.getParameter("NewRating");

String check = request.getParameter("check");

Statement movieInsert = null;
movieInsert = connection.createStatement();

try{
Class.forName("com.mysql.jdbc.Driver").newInstance();

connection = DriverManager.getConnection(connectionURL, username, password);

if(connection!=null)
{
out.println("Connected!");
}
else
{
out.println("Could Not Connect!");
}
}
catch(Exception e)
{
e.printStackTrace();
}



try{
if(check.equals("add")){
movieInsert.executeUpdate("INSERT INTO MovieTitles (MovieTitle, MainActor, MainActress, Rating) values('"+newMovieName+"', '"+NewMainActor+"' , '"+NewMainActress+"' , '"+NewRating+"' ");

} else if(check.equals("delete")){
movieInsert.executeUpdate("DELETE FROM MovieTitles WHERE MovieTitle = '"+newMovieName+"'");

}


}
catch (Exception e){
e.printStackTrace();
}

%>













</body>
</html>


That is my full code, I was looking at that but there is no line 79 in my form. Any other ideas as to what could be throwing the error? I ommitted the connection URL, name and pass on purpose btw.
Mohibur Rashid 30-Apr-15 0:18am    
Your first line says :
java.sql.Connection connection=null; // you have set connection to null

and then in
movieInsert = connection.createStatement(); // you are trying to access an method.

In between you never initialize your connection variable. Initialize it. The problem would be fixed.
Sergey Alexandrovich Kryukov 29-Apr-15 21:05pm    
Just run it under the debugger; inspect all objects before the line throwing the exception. Such problems are the easiest to detect and fix.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900