java - Inserting Into MySQL database by click of a button in JSP -


following code insert data mysql database.

but code not inserting data database clicking send button.

    <%     class.forname("com.mysql.jdbc.driver");     conn = drivermanager.getconnection(conn_string, username, password);      if(request.getparameter("send")!=null){         string scom=request.getparameter("scompany");         string porderno=request.getparameter("pono");         string bdate=request.getparameter("date");         string drug1=request.getparameter("d1");         string qty1=request.getparameter("q1");           //getting todaydate         date date = new date();         timestamp timestamp = new timestamp(date.gettime());          string sql = "insert purchaseorderinfo set supplier ='"+scom+"', pono='"+porderno+"', expecteddate='"+bdate+"', podate='"+timestamp+"' ";         pst=conn.preparestatement(sql);           if((scom!=null && scom.length()>0)             && (porderno!=null && porderno.length()>0)             && (bdate!=null && bdate.length()>0)             && (drug1!=null && drug1.length()>0)             && (qty1!=null && qty1.length()>0)){              pst.execute();           %>           <script language="javascript">                 alert("send sucess");           </script>           <%             }     } %> 

this send button;

<div class="col-md-8">     <form action="adminpg-purchaseorder.jsp" method="post" id="login-form" role="form" style="display: block">         <div class="form-group">             <div class="row">                 <div class="col-sm-6 col-sm-offset-3">                     <input type="submit" name="send" id="submit" tabindex="1" class="form-control btn btn-login" value="send">                 </div>             </div>         </div>         </form> </div> 

how fix code inserting data database?

your insert query wrong. similar update query. change

string sql = "insert purchaseorderinfo set supplier ='"+scom+"', pono='"+porderno+"', expecteddate='"+bdate+"', podate='"+timestamp+"' "; 

to

string sql = "insert purchaseorderinfo(supplier,pono,expecteddate,podate)       values('"+scom+"', '"+porderno+"', '"+bdate+"', '"+timestamp+"' "; 

Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -