Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

MS Access Database, Tomcat Server, JSP Form and Insert jsp

Avatar of MarcosInfo
MarcosInfo asked on
JSP
2 Comments1 Solution878 ViewsLast Modified:
I have been working for a while on this. And cannot get all to work. I have tomcat runnning well, it sees MS Access,

Upon Submit of Form I want to insert the data to Access on my local host pc,  No luck so far CAN ANYONE SPOT inmy CODE where I may have issues..?  AND can anyone simplify the insertion? I got help from a friend but really am lost on all the stuff....HELP!

<%@ page language="java" import="java.sql.*"%>

<%
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);

    String url = "jdbc:odbc:Northwind";
    String username = "";
    String password = "";


Connection con=null;
ResultSet rst=null;
Statement stmt=null;


%>

<% //VERIFY SUBMIT IS PRESSED BEFORE INSERTING DATA

if("pressed".equals(request.getParameter("id"))){

      //MAKE CONX
      //GET READY TO ENTER TO DATABASE
      int i=1;
      con = DriverManager.getConnection(url, username, password);
      stmt=con.createStatement();
      String x_Name = request.getParameter("Name");
      String x_Gender = request.getParameter("Gender");
      String x_DOB = request.getParameter("DOB");
      String x_Address1= request.getParameter("Address1");
      String x_Address2= request.getParameter("Address2");
      String x_City= request.getParameter("City");
      String x_State= request.getParameter("State");
      String x_Zip= request.getParameter("Zip");
      String x_Phone= request.getParameter("Phone");
      String x_Comments1= request.getParameter("Comments1");
      String x_Comments2= request.getParameter("Comments2");
      String x_Comments3= request.getParameter("Comments3");
      String x_Comments4= request.getParameter("Comments4");
      String x_Date = request.getParameter("Date");
      String x_Email = request.getParameter("Email");
      String sql = "insert into jsp_table ";
        sql +=
"(NAME,GENDER,DOB,ADDRESS1,ADDRESS1,CITY,STATE,ZIP,PHONE,COMMENTS1,COMMENTS2,COMMENTS3,COMMENTS4,DATE,EMAIL)
";
      sql += " values ('";
        sql +=  x_Name ;
        sql +=  "','";
        sql += x_Gender;
        sql += "','";
        sql += x_DOB;
        sql += "','" ;
        sql += x_Address1 ;
        sql += "','" ;
        sql += x_Address2;
        sql += "','" ;
        sql += x_City ;
        sql += "','" ;
        sql += x_State ;
        sql += "'," ;
        sql += x_Zip ;
        sql += ",'" ;
        sql += x_Phone;
        sql += "','" ;
        sql += x_Comments1;
        sql += "','";
        sql += x_Comments2 ;
        sql += "','" ;
        sql += x_Comments3 ;
        sql += "','" ;
        sql += x_Comments4 ;
        sql += "','" ;
        sql += x_Date ;
        sql += "','" ;
        sql += x_Email;
        sql += "')";
      //out.println(sql);

      int val = stmt.executeUpdate(sql);

      //if the insert was successfull, display all the values in the database
ordered decending by the insert date
      if(val==1) {
            out.println("<p>The following values have been entered in the
database<br>");
            String sql2=("select * from JSP_TABLE");
            rst=stmt.executeQuery(sql2);

            while(rst.next()){
                  out.println(rst.getString(1));
                  out.println(" ");
                  out.println(rst.getString(2));
                  out.println(" ");
                  out.println(rst.getString(3));
                  out.println(" ");
                  out.println(rst.getString(4));
                  out.println(" ");
                  out.println(rst.getString(5));
                  out.println(" ");
                  out.println(rst.getString(6));
                  out.println(" ");
                  out.println(rst.getString(7));
                  out.println(" ");
                  out.println(rst.getString(8));
                  out.println(" ");
                  out.println(rst.getString(9));
                  out.println(" ");
                  out.println(rst.getString(10));
                  out.println(" ");
                  out.println(rst.getString(11));
                  out.println(" ");
                  out.println(rst.getString(12));
                  out.println(" ");
                  out.println(rst.getString(13));
                  out.println(" ");
                  out.println(rst.getString(14));
                  out.println(" ");
                  out.println(rst.getString(15));
                  out.println("<br>");


            }//end while
            out.println("<a href=\"InsertForm.jsp\">THANKS BACK TO ENTRY PAGE</a>");
            out.println("</p>");



      }else{
            out.println("<p>There is a problem, your data was not saved</p>");

      }

//Close all open connections when done.
rst.close();
stmt.close();
con.close();


//}else{
      //do nothing

//}


%>


ERROR WHEN RUN:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 19 in the jsp file: /insertdata.jsp
Generated servlet error:
String literal is not properly closed by a double-quote

An error occurred at line: 19 in the jsp file: /insertdata.jsp
Generated servlet error:
String literal is not properly closed by a double-quote

Generated servlet error:
Syntax error, insert "}" to complete ClassBody


      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 19 in the jsp file: /insertdata.jsp
Generated servlet error:
String literal is not properly closed by a double-quote

An error occurred at line: 19 in the jsp file: /insertdata.jsp
Generated servlet error:
String literal is not properly closed by a double-quote

Generated servlet error:
Syntax error, insert "}" to complete ClassBody


      org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
      org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

ASKER CERTIFIED SOLUTION
Avatar of mhunts
mhunts

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answers