jsp error

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

LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
now it says
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'ac_holder' in 'field list'
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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?
0
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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

0
CEHJCommented:
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
0
gudii9Author 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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.