• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to print table: "Syntax error: Encountered "\'" at line 1, column 36"

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<%@page import="java.sql.*"%>
<%@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>
<%
Connection connection = null;
String DBUrl="jdbc:derby://localhost:1527/CRM";
try
{
String Cid, strSQL, CNAME, CITY, STATE, EMAIL, mySTATE;
mySTATE=request.getParameter("STATE");
connection = DriverManager.getConnection(DBUrl);
Statement SQLStatement = connection.createStatement();
String stateCheckbox1 = request.getParameter("CA");
String stateCheckbox2 = request.getParameter("OR");
String stateCheckbox3 = request.getParameter("WA");
if (stateCheckbox1 != null)
{mySTATE="CA";}
else if (stateCheckbox2 != null)
{mySTATE="OR";}
else
{mySTATE="WA";}
strSQL="select * from CUSTOMER where STATE='" +mySTATE+ "CA";
ResultSet rs = SQLStatement.executeQuery(strSQL);
out.println("<table border='1' width='400' cellspacing=1>");
out.println(" <thead><tr>");
out.println("<th>CID</th> <th>CNAME</th> <th>CITY</th> <th>Rating</th>");
out.println("</tr></thead>");
while (rs.next())
{
Cid=rs.getString("CID");
CNAME=rs.getString("CNAME");
CITY=rs.getString("CITY");
STATE=rs.getString("STATE");
EMAIL=rs.getString("EMAIL");
out.println("<tr>");
out.println("<td width='25%'>" + Cid + "</td>");
out.println("<td width='25%'>" + CNAME + "</td>");
out.println("<td width='25%'>" + CITY + "</td>");
out.println("<td width='25%'>" + STATE + "</td>");
out.println("<td width='25%'>" + EMAIL + "</td>");
out.println("</tr>");
}
rs.close();
}
catch(SQLException e)
{
out.println(e.getMessage());
}
out.println("</table>");
%>
</body>
</html>
 
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.) Do not write database connection code in JSPs. Use a normal Java class (DAO) that you call from a servlet.
2.) Always close resultselts, statements and connections in a finally block.
3.) Use a PreparedStatement for passing parameters to your query. That will prevent SQL injection and fix the SQL syntax error you are getting.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
E. is not steering you wrong -- you should not be putting any Java code in a JSP. That is a bad bad practice from long long ago. Modern JSP pages (that is, anything written in the past 12 years) should be free of Java code.
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic