jsp error

gudii9
gudii9 used Ask the Experts™
on
Hi,

My jso application giving below error


username:admin123
username:admin1
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '','01091999','tt','t@t.com','AAA')' at line 1
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)


How to resolve this.
my account.jsp is
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    %>
<!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=ISO-8859-1">
<title>Account Creation Screen</title>
</head>
<body>
	<%@include file="header.jsp" %>
	<div style="width: 300px; margin-left:auto;margin-right:auto;">
		
		<h1>Account Creation Screen</h1>
		<form action="accountCreate.jsp">
			<table>
				<tr>
					<td>			
					Name
					</td>
					<td>
					<input type="text" name="name"><br>
					</td>
				</tr>
				
				<tr>
					<td>
					DOB
					</td>
					<td>
					<input type="text" name="dob" placeholder="Sample Format 1989-01-31"><br>
					</td>
				</tr>
				
				<tr>
					<td>
					Address
					</td>
					<td>
					<textarea type="textarea" name="address" rows=10 style="width:200px; height:100px;"></textarea><br>
					</td>
				</tr>
				
				<tr>
					<td>
					Email ID
					</td>
					<td>
					<input type="textarea" name="email" placeholder="Sample Format test@awesome.com"><br>
					</td>
				</tr>
				
				<tr>
					<td>
					Type of account
					</td>
					<td>
					<select name="accounttype">
					   <option  value="AAA">AAA</option>
					   <option value="BBB">BBB</option>
					   <option value="CCC">CCC</option>
					   <option value="DDD">DDD</option>
					</select> <br>		
					<td>
				</tr>
				<tr>
					<td>
					<input type="submit" value="Create Account">
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>

Open in new window

my accountCreate.jsp is
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@page import="java.sql.DriverManager" %>
<%@page import="java.sql.Connection" %>
<%@page import="java.sql.Statement" %>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String named = request.getParameter("name");
String dobd = request.getParameter("dob");
String addressd = request.getParameter("address");
String emaild = request.getParameter("email");
String toa = (String)request.getParameter("accounttype");
//out.print(named+dobd+addressd+emaild+toa);
	try{
		Class.forName("com.mysql.jdbc.Driver");
		String username = "root";
		String password = "admin";
		Connection con = DriverManager.getConnection("jdbc:mysql://localhost/banking6",username,password);
		Statement st = con.createStatement();
		int i = st.executeUpdate("insert into account_details (name,ac_holder,dob,address,email,type"+named+"','"+dobd+"','"+addressd+"','"+emaild+"','"+toa+"')");
		out.print("Account Created Succesfully"+"<a href='dashboard.jsp'><button>Homepage</button></a>");

	}
	catch(Exception e){
		out.print("User Account is not created <br>Account failed to create please check formatting date is formatted 1989-01-13"+"<br><a href='account'><button>Go Back</button></a>");
		e.printStackTrace();
	}
%>
</body>
</html>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Team Lead
Commented:
the line:

int i = st.executeUpdate("insert into account_details (name,ac_holder,dob,address,email,type"+named+"','"+dobd+"','"+addressd+"','"+emaild+"','"+toa+"')");

Open in new window


looks invalid. it also seems that ac_holder was inserted but no variable is holding that value?

try customize this instead:

int i = st.executeUpdate("insert into account_details (name,ac_holder,dob,address,email,type) values ('"+named+"','ac holder?','"+dobd+"','"+addressd+"','"+emaild+"','"+toa+"')");

Open in new window

Author

Commented:
now it says
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'ac_holder' in 'field list'
Ryan ChongSoftware Team Lead

Commented:
now it says
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'ac_holder' in 'field list'
do you have a field called as "ac_holder" in your target table?
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Ryan ChongSoftware Team Lead

Commented:
is your target table's structure changed?

for a quick try:

int i = st.executeUpdate("insert into account_details (name,dob,address,email,type) values ('"+named+"','"+dobd+"','"+addressd+"','"+emaild+"','"+toa+"')");

Open in new window

Top Expert 2016
Commented:
Please issue the query

desc account_details;

Open in new window


with your mysql client and post the results. You should be using PreparedStatement btw

Author

Commented:
You should be using PreparedStatement btw

i will upgrade to it.
do you have a field called as "ac_holder" in your target table?
i removed that and it works now

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial