如何在html表中显示来自mysql的数据?使用netbean Java

时间:2016-07-19 20:10:02

标签: java mysql jsp servlets netbeans

我在这里错了c12。 RS = C12。 ST。 executeUpdate(SQL);我不知道怎样才能摆脱这个错误我的所有代码都在这里请执行它并讲述我的错。我想用html表格显示mysql表

myservlet5.java

       public class myservlet5 extends HttpServlet {
       private Object executeUpdate;

        private static class executeUpdate {

        public executeUpdate() {
        }
         }
         private Object rs;
          private Object st;
           protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
      response.setContentType("text/html;charset=UTF-8");
              PrintWriter out = response.getWriter();
               String name=request.getParameter("t1");
                String abc=request.getParameter("t2");

                aaaa c1=new aaaa();

                try{

                 String Sql="insert into teacher1(id,name) values('"+name+"','"+abc+"')";

                 c1.st.executeUpdate(Sql);   
                 }
               catch(SQLException ex)
                  {

               out.println(ex);

               }
               aaaa c12=new aaaa();
            try{

            String Sql="Select * from teacher1";

。 c12.rs = c12.st.executeUpdate(SQL);

            out.println("<table border=1>");
            while(c12.rs.next()){

           String name1=c12.rs.getString("id");

          String abc1=c12.rs.getString("name");

           out.println("<tr>");
           out.println("<td>"+name1+"</td>");
           out.println("<td>"+abc1+"</td>");
           out.println("</tr>");  
            }
           out.println("</table>");
            }
            catch(SQLException ex)
            try {
              out.println("<html>");
              out.println("<head>");
              out.println("<title>Servlet myservlet5</title>");            
              out.println("</head>");
              out.println("<body>");
         out.println("<h1>Servlet myservlet5 at " + request.getContextPath() + "</h1>");

                 out.println("</body>");
               out.println("</html>");
             } 

             finally {            
            out.close();
           }
         }

的index.jsp

         <html>
         <head>
         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

         </head>
         <body>
         <form action="myservlet5"  method="GET"    >

        First name:<br> 
        <input type="text" name="t1"/> 
        <br> 
        Last name:
        <br> 
        <input type="text" name="t2" /> 
        <br>  <br> 
        <input type="submit" value="Submit"/> 
        </form>
        </body>
        </html>

错误

    HTTP Status 500 -

    type Exception report

    message

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

    exception

    java.lang.RuntimeException: Uncompilable source code - illegal start of expression 
    myservlet5.processRequest(myservlet5.java:67)
    myservlet5.doGet(myservlet5.java:131)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.

     Apache Tomcat/5.5.2

0 个答案:

没有答案