We help IT Professionals succeed at work.

jsp error

gudii9
gudii9 asked
on
333 Views
Last Modified: 2017-03-09
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

CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
now it says
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'ac_holder' in 'field list'
CERTIFIED EXPERT

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?
CERTIFIED EXPERT

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

CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

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