Koushik Reddy Koushik Reddy - 10 months ago 30
Java Question

My questions is related to jsp code in registration form

This is JSP Code (process.jsp)

<%@ page import ="java.sql.*" %>
<%@page import ="java.io.*" %>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%!
%>
<% String FirstName=request.getParameter("FirstName");
String LastName=request.getParameter("LastName");
String Email=request.getParameter("Email");
String Username=request.getParameter("Username");
String Password=request.getParameter("Password");
String RepeatPassword=request.getParameter("RepeatPassword");
String MobileNumber=request.getParameter("MobileNumber");
Class.forName("com.mysql.jdbc.Driver");
ResultSet rs;
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","root");
PreparedStatement st = con.prepareStatement("INSERT INTO customers(FirstName, LastName, Email, Username,Password,RepeatPassword,MobileNumber) VALUES(?,?,?,?,?,?,?)");
st.setString(1,FirstName);
st.setString(2,LastName);
st.setString(3,Email);
st.setString(4,Username);
st.setString(5,Password);
st.setString(6,RepeatPassword);
st.setString(7,MobileNumber);
34) int i=st.executeUpdate();
if(i!=0)
{
//session.setAttribute("Username", Username);
response.sendRedirect("welcome.jsp");
//out.print("Registration Successfull!"+"<a href='index.jsp'>Go to Login</a>");
}
else
{
response.sendRedirect("login.jsp");
}
%>
<h1>registration successful</h1>
</body>
</html>

%>


I am using Eclipse IDE,Tomcat server, MySQL db. When I run reg.jsp on server it is running and asking registration details but while directing from reg.jsp to process.jsp the problem arises at (
int i=st.executeUpdate
). The server is throwing
An Exception Occured Processing JSP Page at line 34


int i=st.executeUpdate();


Firstly, I am registering at jsp registration page it is asking me registration details when I give my details it should take details and check for JDBC connectivity in process.jsp and store it in MySQL DB but it is showing me an error.

org.apache.jasper.JasperException: An exception occurred processing JSP page [/process.jsp] at line [34]

31: st.setString(5,Password);
32: st.setString(6,RepeatPassword);
33: st.setString(7,MobileNumber);
34: int i=st.executeUpdate();
35: if(i!=0)
36: {
37: //session.setAttribute("Username", Username);


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:588)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)


Root Cause
javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'Password' cannot be null
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:669)
org.apache.jsp.process_jsp._jspService(process_jsp.java:184)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)


Root Cause
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'Password' cannot be null
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
org.apache.jsp.process_jsp._jspService(process_jsp.java:155)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

34: int i=st.executeUpdate();


The code is throwing me an error at line 34. Exception raised
An exception occurred processing JSP page [/process.jsp] at line [34]
. It has to check the user details and if all the details are greater than 1 it should throw me
registration successful, go to login
.

Answer Source

The error is very clear through your stacktrace:

Root Cause

com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'Password' cannot be null

You are trying to pass the value of column Password as null and hence the exception MySQLIntegrityConstraintViolationException thrown as well.

You would have defined your table with the column Password as NOT NULL and hence the error. Pass a meaningful value to your column Password and the issue should be resolved.

Recheck the JSP code if you are correctly passing the Password field or if the value is being passed correctly or not on the UI itself.

Hope this helps!!!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download