java - How can I access SQLyog community through netbeans and insert a query in it? my code is Here below -


i have added apache tomcat in libraries , connect correct want insert data in sqlylog through html page. what's wrong in code have doubts insert query , file.

 public class myservlet extends httpservlet {  class dbconn {      connection c1 = null;     statement st = null;     resultset rs = null;     private final string ac;     private final string aaa;      dbconn() {         try {             class.forname("com.mysql.jdbc.driver");             c1 = drivermanager.getconnection("jdbc:mysql://localhost:3306/teacher", "root", "abcde");          } catch (exception cnfe) {             system.out.println("couldn't find driver!");             system.out.println("couldn't connect: print out stack trace , exit.");             system.out.println("we got exception while creating statement:" + "that means we're no longer connected.");         }         try {             st = (statement) c1.createstatement();             system.out.println("statement created successfully");         } catch (sqlexception se) {             system.out.println("we got exception while creating statement:" + "that means we're no longer connected.");          }         if (c1 != null) {             system.out.println("hooray! connected database!");         } else {             system.out.println("we should never here.");         }         string query = "insert teacher1 (id,name) "                  + "values (" + 1 + ", '" + aaa + "')";       // insert query     } }  protected void processrequest(httpservletrequest request,         httpservletresponse response)         throws servletexception, ioexception {     response.setcontenttype("text/html;charset=utf-8");     printwriter out = response.getwriter();     try {          out.println("<html>");         out.println("<head>");         out.println("<title>servlet myservlet</title>");          out.println("</head>");         out.println("<body >");          out.println("<h1>servlet myservlet @ " + request.getcontextpath() + "</h1>");         string name = request.getparameter("firstname");         out.println("<h2>" + name + "</h2>");         out.println("</body>");         out.println("</html>");     } {         out.close();     } }  protected void doget(httpservletrequest request, httpservletresponse response)         throws servletexception, ioexception {     processrequest(request, response); }  protected void dopost(httpservletrequest request, httpservletresponse response)         throws servletexception, ioexception {     processrequest(request, response); }      public string getservletinfo() {     return "short description"; } 

index.jsp

   <!doctype html>    <html>     <head>       <meta http-equiv="content-type" content="text/html; charset=utf-8">     <title>jsp page</title>     </head>      <body>     <h1>hello world!</h1>      <form action="myservlet"  method="get"    >          first name:<br>          <input type="text" name="firstname"/>          <br>          last name:         <br>          <input type="text" name="lastname" />          <br><br>          <input type="submit" value="submit"/>        </form>       </body>       </html> 

i have added apache tomcat in libraries , connect correct want insert data in sqlylog through html page. what's wrong in code have doubts insert query , file.

myservlet.java

import java.beans.statement; import java.io.ioexception; import java.io.printwriter; import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse;  public class myservlet extends httpservlet {      class dbconn {          connection c1 = null;         statement st = null;         resultset rs = null;         private final string ac;         private final string aaa;          dbconn() {             try {                 class.forname("com.mysql.jdbc.driver");                 c1 = drivermanager.getconnection("jdbc:mysql://localhost:3306/teacher", "root", "abcde");              } catch (exception cnfe) {                 system.out.println("couldn't find driver!");                 system.out.println("couldn't connect: print out stack trace , exit.");                 system.out.println("we got exception while creating statement:" + "that means we're no longer connected.");             }             try {                 st = (statement) c1.createstatement();                 system.out.println("statement created successfully");             } catch (sqlexception se) {                 system.out.println("we got exception while creating statement:" + "that means we're no longer connected.");              }             if (c1 != null) {                 system.out.println("hooray! connected database!");             } else {                 system.out.println("we should never here.");             }             string query = "insert teacher1 (id,name) "                     + "values (" + 1 + ", '" + aaa + "')";       // insert query         }     }      protected void processrequest(httpservletrequest request,             httpservletresponse response)             throws servletexception, ioexception {         response.setcontenttype("text/html;charset=utf-8");         printwriter out = response.getwriter();         try {              out.println("<html>");             out.println("<head>");             out.println("<title>servlet myservlet</title>");             out.println("</head>");             out.println("<body >");              out.println("<h1>servlet myservlet @ " + request.getcontextpath() + "</h1>");             string name = request.getparameter("firstname");             out.println("<h2>" + name + "</h2>");             out.println("</body>");             out.println("</html>");         } {             out.close();         }     }      protected void doget(httpservletrequest request, httpservletresponse response)             throws servletexception, ioexception {         processrequest(request, response);     }      protected void dopost(httpservletrequest request, httpservletresponse response)             throws servletexception, ioexception {         processrequest(request, response);     }      public string getservletinfo() {         return "short description";     } } 

index.jsp

<!doctype html> <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">         <title>jsp page</title>     </head>     <body>         <h1>hello world!</h1>          <form action="myservlet"  method="get"    >              first name:<br>              <input type="text" name="firstname"/>              <br>              last name:             <br>              <input type="text" name="lastname" />              <br><br>              <input type="submit" value="submit"/>          </form>     </body> </html> 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -