java - In my jsp page I am trying to insert values to database but I dont see any error, page refreshes and the data is not inserted -


here code. <%--      document   : index     created on : jan 16, 2016, 2:49:24 pm     author     : manoj --%> <%@page import="java.sql.*"%> <% class.forname("org.apache.derby.jdbc.clientdriver"); %> <%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html> <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">         <title>inserting data</title>     </head>     <body>         <h1>inserting data</h1>         <%!             public class contact {                 string url = "jdbc:derby://localhost:1527/contact";                 string username = "nbuser";                 string password = "nbuser";                  connection conn = null;                 preparedstatement pst = null;                 statement stm = null;                 resultset rst = null;              public contact(){                 try{                     conn = drivermanager.getconnection(url, username, password);                     pst = conn.preparestatement(                     "insert contactinfo (name, address, mobile)"+" values (?, ?, ?)");                     }                 catch(sqlexception e)                 {                     e.printstacktrace();                 }             }             public int setcontact(string name, string address, string mobile)             {                  int result =0;                  try{                     pst.setstring(1, name);                     pst.setstring(2, address);                     pst.setstring(3, mobile);                      result = pst.executeupdate();                  }                  catch(sqlexception e)                  {                     e.printstacktrace();                  }                  return result;             }             }             %>             <%                int result = 0;                if(request.getparameter("submit") != null){                string name = new string();                string address = new string();                string mobile = new string();                 if (request.getparameter("name")!= null)                {                    name = request.getparameter("name");                }                  if (request.getparameter("address")!= null)                {                    address = request.getparameter("address");                }                    if (request.getparameter("mobile")!= null)                {                    mobile = request.getparameter("mobile");                }                 contact contact = new contact();                result = contact.setcontact(name, address, mobile);                 }             %>         <form name="myform" action="index.jsp" method="post">             <table border="0">                <tbody>                     <tr>                         <td>name</td>                         <td><input type="text" name="name" value="" size="30" /></td>                     </tr>                     <tr>                         <td>address</td>                         <td><input type="text" name="address" value="" size="50" /></td>                     </tr>                         <tr>                         <td>mobile</td>                         <td><input type="text" name="mobile" value="" size="10" /></td>                     </tr>                 </tbody>             </table>             <input type="reset" value="clear" name="clear" />             <input type="submit" value="submit" name="submit" />         </form>     </body> </html> 

kindly me. first time writing jsp code. database using apache derby within neatbeans 8.1. tried alternatives not find solution. when manually insert row database inserting values.

you can try debug code , check whether if(request.getparameter("submit") != null) returning true or false.

as doubt because have used

<input type="submit" value="submit" name="submit" />

where value capital s


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -