Heading

Wednesday, March 5, 2014

Web Application in Java with JDBC, Servlets, JSp and MYSQL DataBase-9

User Home Tabs:

Production Registration :  This jsp file helps us to get the values from Add_Product .jsp and helps us to store in the DB.

<%--
    Document   : Product_Register
    Created on : Feb 25, 2014, 12:48:48 PM
    Author     : SDSTAFF
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%
           HttpSession hs=request.getSession(false);
           if(hs==null)
           {
               RequestDispatcher rd=request.getRequestDispatcher("Login_Page.jsp");
               rd.forward(request, response);
               return;
           }
          
          
        %>
<%
Connection con = null;
Statement st = null;
ResultSet rs = null;

String a = request.getParameter("productid");
String f = request.getParameter("productname");
String g = request.getParameter("productcost");

try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","password");
st=con.createStatement();
st.executeUpdate("insert into product values('"+a+"','"+f+"','"+g+"')");
response.sendRedirect("Add_Product.jsp?Message=success");

%>

<%
}
catch(Exception ex)
{
    out.println(ex);
}
%>

No comments:

Post a Comment