how to store data in database using mysql jsp


<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<body>
<%@ include file="admin_header.jsp" %>
<br><br><br><br>
<br><br>
<div class="col-md-2">


<a href="addvendor.jsp" class="btn btn-lg btn btn-primary">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;View Vendor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
</div>
<div class="col-md-9">

<button type="button" disabled class="btn btn-primary btn-block">Vendor details</button>
<form action="vendorInsert.jsp" method="get">
  <fieldset class="form-group">
    <label for="exampleInputEmail1">Name:</label>
    <input type="text" class="form-control" name="fname" placeholder="Enter email">
   
  </fieldset>
  <fieldset class="form-group">
    <label for="exampleInputPassword1">Email</label>
    <input type="email" class="form-control" name="eml" placeholder="email enter">
  </fieldset>
  <fieldset class="form-group">
    <label for="exampleSelect1">Currency</label>
    <select class="form-control" name="select1">
      <option>Us-Dollar</option>
      <option>Indian Rs</option>
        </select>
  </fieldset>
  <fieldset class="form-group">
    <label for="exampleInputEmail1">Contact Person:</label>
    <input type="text" class="form-control" name="cp" placeholder="Enter email">
   
  </fieldset>
  <hr>
 
  <button type="button" disabled class="btn btn-primary btn-block">Address</button>
 
  <fieldset class="form-group">
    <label for="exampleTextarea">Address:</label>
    <textarea class="form-control" name="ta" rows="3"></textarea>
  </fieldset>
 
  <fieldset class="form-group">
    <label for="exampleInputEmail1">city:</label>
    <input type="text" class="form-control" name="city" placeholder="Enter email">
   
  </fieldset>
 
  <fieldset class="form-group">
    <label for="exampleInputEmail1">State:</label>
    <input type="text" class="form-control" name="state" placeholder="Enter email">
   
  </fieldset>
 
  <fieldset class="form-group">
    <label for="exampleInputEmail1">country:</label>
    <input type="text" class="form-control" name="country" placeholder="Enter email">
   
  </fieldset>
 
  <button type="button" disabled class="btn btn-primary btn-block">Contact Info</button>
 <fieldset class="form-group">
    <label for="exampleInputEmail1">Mobile No:</label>
    <input type="number" class="form-control" name="number" placeholder="Enter email">
   
  </fieldset>
  <fieldset class="form-group">
    <label for="exampleInputEmail1">Fax:</label>
    <input type="text" class="form-control" name="fax" placeholder="Enter email">
   
  </fieldset>
  <fieldset class="form-group">
    <label for="exampleInputEmail1">web url:</label>
    <input type="text" class="form-control" name="url" placeholder="Enter email">
   
  </fieldset>


  <button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</body>



addvendor.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
   
<%@page import="java.util.Calendar"  %>
<%@page import="java.util.Date" %>
<%@page import="java.text.DateFormat"%>
<%@page import="java.util.Formatter"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String a3=request.getParameter("fname");
String a4=request.getParameter("eml");
String a5=request.getParameter("select1");
String a6=request.getParameter("cp");
String a7=request.getParameter("ta");
String a8=request.getParameter("city");
String a9=request.getParameter("state");
String a10=request.getParameter("country");
String a11=request.getParameter("number");
String a12=request.getParameter("fax");
String a13=request.getParameter("url");



try {
 Class.forName("com.mysql.jdbc.Driver");
 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/contract","root","root");

/* Passing argument through the question mark */
 PreparedStatement ps=conn.prepareStatement("insert into vendor values(?,?,?,?,?,?,?,?,?,?,?)") ;

 ps.setString(1,a3);
 ps.setString(2,a4);
 ps.setString(3,a5);
 ps.setString(4,a6);
 ps.setString(5,a7);
 ps.setString(6,a8);
 ps.setString(7,a9);
 ps.setString(8,a10);
 ps.setString(9,a11);
 ps.setString(10,a12);
 ps.setString(11,a13);
 

 int i=ps.executeUpdate(); /*Set the Update query command */
 if(i!=0)
 {
 response.sendRedirect("home.jsp");
 }
 else
 {
 response.sendRedirect("msg=Insertion Failed!! Please try again!!! ");
 }
 conn.close();
 } catch(Exception ex)
{
 out.println(ex);
}
%>


</body>
</html>

Post a Comment

0 Comments

Recent in Recipes

3/Food/post-list