Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Ajax data insertion and fetch 1

Have Programming Question? Ask it here!
 
 
 


Bipin Kumar Aryan
data insertion and fetch 1
0 Answer(s)      a year and 2 months ago
Posted in : Ajax


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Location</title>
    </head>
    <body>
        <h1>Fill Up Your Details</h1>

    <center>  <form action="hit" method="POST">
            <fieldset>

                <b> iGnite Id:</b><input type="text" name="id" placeholder="Ignite Id"><br><br>
                <b>Your Name:</b><input type="text" name="name" placeholder="Name"><br><br>
               <b> Home Town:</b><input type="text" name="home" placeholder="Home"><br><br>
                <b>Location:</b><input type="text" name="location" placeholder="Location"><br><br>
                <b>Gender</b><input type="radio" name="sex" value="male">Male
                            <input type="radio" name="sex" value="female">Female<br><br>

                <b>Choice</b><input type="checkbox" name="choice" value="Kolkata">Kolkata
                            <input type="checkbox" name="choice" value="Chennai">Chennai
                            <input type="checkbox" name="choice" value="Mumbai">Mumbai
                            <input type="checkbox" name="choice" value="Delhi">Delhi<br>
                            <input type="submit" name="submit" value="Submit">

            </fieldset>
            <center><a href="view.jsp"><h1>VIEW</h1></a></center>



        </form></center>
    </body>
</html>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
    <center> <h1>View Your Location</h1>
        <form action="view" method="POST">
            <b> Enter Your Ignite Id:</b><input type="text" name="id" placeholder="IgniteId"><br><br>
            <input type="submit" value="SUBMIT" name="submit"><br><br><br>
            <table border="2">

                <th>Name</th>
                <th>home</th>
                <th>Location</th>
                <%
                    try {

                        ResultSet rs = (ResultSet) request.getAttribute("data");
                        while (rs.next()) {
                %>                                              
                <tr>
                    <td><input type="text" value="<%=rs.getString("name")%>"</td>
                    <td><input type="text" value="<%=rs.getString("home")%>"</td>
                    <td><input type="text" value="<%=rs.getString("location")%>"</td>
                </tr>
                <%                        }
                    } catch (Exception e) {
                    }
                %>

            </table>

        </form> </center> </body>
</html>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
insert int data base
@@@@@@@@@
import com.mysql.jdbc.PreparedStatement;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author ignite178
 */
public class hit extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /*
             * TODO output your page here. You may use following sample code.
             */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet hit</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet hit at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out=response.getWriter();
        String Id=request.getParameter("id");
        String Name=request.getParameter("name");
        String Home=request.getParameter("home");
        String Location=request.getParameter("location");
        String Gender=request.getParameter("sex");
        String Choice=request.getParameter("choice");

        try{
         Class.forName("com.mysql.jdbc.Driver");
         Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/location", "root", "root");
        String sql="INSERT INTO posting (ignite_id,name,home,location,gender,choice) VALUES('"+Id+"','"+Name+"','"+Home+"','"+Location+"','"+Gender+"','"+Choice+"')";
      PreparedStatement ps=(PreparedStatement) con.prepareStatement(sql);
        ps.executeUpdate();
        ps.close();
        con.close();



        }
        catch(Exception e)
        {
            out.print(e.toString());
        }
        finally{
            out.print("Submit Successfully");
        out.close();

        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@222
how to fetch
@@@@@@@@@@@@@@@
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author ignite178
 */
public class view extends HttpServlet {
    private ServletResponse response;

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /*
             * TODO output your page here. You may use following sample code.
             */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet hit</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet hit at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
//        try {
//            try {
//                Class.forName("com.mysql.jdbc.Driver").newInstance();
//            } catch (InstantiationException ex) {
//                Logger.getLogger(view.class.getName()).log(Level.SEVERE, null, ex);
//            } catch (IllegalAccessException ex) {
//                Logger.getLogger(view.class.getName()).log(Level.SEVERE, null, ex);
//            }
//        } catch (ClassNotFoundException ex) {
//            Logger.getLogger(view.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        Connection con = null;
//        try {
//            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/location", "root", "root");
//        } catch (SQLException ex) {
//            Logger.getLogger(view.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        String id=request.getParameter("id");
//        String query = "select * from posting where ignite_id='"+id+"'";
//        Statement s = null;
//        try {
//            s = con.createStatement();
//        } catch (SQLException ex) {
//            Logger.getLogger(view.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        ResultSet rs = null;
//        try {
//            rs = s.executeQuery(query);
//        } catch (SQLException ex) {
//            Logger.getLogger(view.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        request.setAttribute("data", rs);
//        RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
//        rd.forward(request, response);
//    }
    }
    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        String Id = request.getParameter("id");

        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/location", "root", "root");
            String id=request.getParameter("id");
        String query = "select * from posting where ignite_id='"+id+"'";
        Statement s = null;
            s = (Statement) con.createStatement();
            ResultSet rs = null;
             rs = s.executeQuery(query);
              request.setAttribute("data", rs);
        RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
        rd.forward(request, response);              

      } catch (Exception e) {
            out.print(e.toString());
        } finally {

            out.close();

        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}

Advertisement
View Answers

Related Tutorials/Questions & Answers:
data insertion and fetch 1
data insertion and fetch 1  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <... rs = (ResultSet) request.getAttribute("data"); while...; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ insert int data base @@@@@@@@@ import
how to fetch data from servlet ????
how to fetch data from servlet ????  how to fetch data from servlet
Advertisements
fetch data from database in javascript
fetch data from database in javascript   How to fetch data from database in JavaScript when it is a leap year
data insertion from xml file to database table
data insertion from xml file to database table  Hi all, I have data in the XML file. I need to insert it into table in the database using servlet. so please reply me . ThankYou
Insertion of multiple row data for billing purpose.
Insertion of multiple row data for billing purpose.  Hi , I have a hrml page . with 4 input text field as a 4 column and 4-5 rows... the input field data of all row through JSP. any good suggestion please help
to fetch data from ms word and storing into database
to fetch data from ms word and storing into database  i want to know how to fetch datafields from ms word and storing into database??? please answer soon .its urgent
Fetch the data from mysql and display it on php form
Fetch the data from mysql and display it on php form  when i press on login button, after succesful login the related data of that person should be display in other textbox
fetch data from ms acces - Swing AWT
fetch data from ms acces  How do i fetch back AUTO generated key from MS ACCESS table after inserting data through the java panel.... Please Help...(); ResultSet rs=st.executeQuery("select * from data "); while(rs.next
Fetch the data using jsp standard action
Fetch the data using jsp standard action  I want the code of fetch the data from the database & show in a jsp page using jsp:usebean in MVC model... that retrieves the data from the database through java bean and display it in jsp page
Data fetch from multiple SQL tables - Hibernate
Data fetch from multiple SQL tables   I am in the process of writing my first hibernate application. I have a sql query that fetches data from multiple tables using left and right outer joins. I need to convert this JDBC data
Select tag to fetch data from oracle database
Select tag to fetch data from oracle database  I created a select box having more than one menus in the select box such as regnno, address and name of a student and when regnno is selected from the drop down list by a user
Struts2 and Hibernate Fetch Data Base Value
Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am... me what should i do for fetch the database value and shown on jsp page... "success"; } > > public String fetch() { > > apllist=dao.fetch1
Struts2 and Hibernate Fetch Data Base Value
Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am... me what should i do for fetch the database value and shown on jsp page... "success"; } > > public String fetch() { > > apllist=dao.fetch1
how to fetch data fron facebbok using spring batch and hibernate ?
how to fetch data fron facebbok using spring batch and hibernate ?  how to fetch data from facebbok using spring batch and hibernate ? Means i have... details of data to local database and fetch all details if data
Solving task 1 by 1 from bundle of task data
set.what should i do so that the solve code solve data 1 by 1?do i need to use...Solving task 1 by 1 from bundle of task data  Hello and namaste guys, i really need help here.i use ResultSet to query data from database. as we know
how to make drop down list in JSF & fetch data Item from database
how to make drop down list in JSF & fetch data Item from database  how to make drop down list in JSF & fetch data Item from database
insertion sort
insertion sort  how many arrays needed for insertion sort and why
insertion sort
insertion sort  write a program in java using insertion sort
insertion sort
insertion sort  write a program in java using insertion sort
insertion sort
insertion sort  write a program in java using insertion sort
insertion sort
insertion sort  write a program in java using insertion sort
Insertion Sort Java
Insertion Sort in Java is an algorithm that is used to sort integer values. It can be implemented very easily and is efficient for small data sets. However, Insertion Sort in Java is less efficient when it comes to larger data sets
PDO Fetch Execute
PDO Fetch Mode: We have studied before in the earlier tutorials that how to connect with a database and how to fetch data from the tables, in many times we... a technique called FETCH, which is used with the PDOStatement object. PDO
Insertion into database
Insertion into database  Hi, I need code for inserting the multiple select box values into database.Please do send me the code. Thanks for ur immediate replies its helping a lot
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access  import javax.swing.*; import java.awt....,"connected to database"); stat=con.createStatement(); String ss="select name from data
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access  import javax.swing.*; import java.awt....,"connected to database"); stat=con.createStatement(); String ss="select name from data
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access  import javax.swing.*; import java.awt....,"connected to database"); stat=con.createStatement(); String ss="select name from data
PDO Fetch Into
PDO Fetch Into: Like in the previous tutorial, we will deal with OOP concept in this tutorial. In PHP PDO::FETCH_INTO is a constant which allows us to fetch the data from an existing database into an instance or object of a class
hibernate insertion problem - Hibernate
hibernate insertion problem  Hi , Thanks for the material .Its very gud . when i run FirstExample.java i get the message insertion has been done int the table contact . but whne i look into database data is not inserted
PDO Fetch Object
PDO Fetch Object: This is another way to access the data of a table...;query($sql); $obj=$stmt->fetch(PDO::FETCH_OBJ); echo $obj->name."...;fetch(PDO::FETCH_OBJ); print_r($obj); var_dump($obj); $dbh=null; } catch
How To Fetch Data From Database Into JTextArea
How To Fetch Data From Database Into JTextArea In this section we will read... given which will demonstrate you about how to fetch data and displayed... When you will execute this example you will get the output as follows : 1. Data
PDO Fetch Num
PDO Fetch Num: We've discussed in the previous tutorial about PDO::FETCH... index of the result unlike the PDO::FETCH_ASSOC which returns the name...;query($sql); $result=$stmt->fetch(PDO::FETCH_NUM); echo "<table
Insertion Sort Applet
Insertion Sort Applet  I need Insertion Sort Applet code was design by Dr. Daniel Liang Please
insertion sort applet code
insertion sort applet code  i need Insertion Sort Applet Program
Insertion Sort Applet
Insertion Sort Applet  Please All , I need Insertion sort applet program
Insertion Sort - Java Beginners
Insertion Sort  Hello rose india java experts.If you don't mind.Can you help me.What is the code for Insertion Sort and Selection Sort that displays....   Hi Friend, Try the following code: 1)InsertionSort.java
PDO Fetch Both
;fetch(PDO::FETCH_BOTH); echo "<table border=1>"; foreach...PDO Fetch Both: In the previous two examples we have seen the two methods... type), PDO provides the solution as PDO::FETCH_BOTH produces, with the help
Insertion Sort Problem
Insertion Sort Problem  So I have this in a class file. It is supposed to be an insertion sorter: int min, index=0, temp; for(int i=0;i<sorted.length;i++){ min=sorted[i]; for(int j=i+1;j<
Insertion Sort In Java
Insertion Sort In Java     ... In this example we are going to sort integer values of an array using insertion sort. Insertion sorting algorithm is similar to bubble sort. But insertion sort
Insertion Sort Timer
Insertion Sort Timer  Welcome all I wanna program in java find the timer of insertion sort and find time complexity for random value thanks all
arraylist not able to store large amount of data( over 1 lakh records) - Java Interview Questions
arraylist not able to store large amount of data( over 1 lakh records)  A result set containing over 1 lakhs of records is used to set data... function that iterator is used to iterate and data from above arraylist is used
File insertion into oracle database
File insertion into oracle database  How to Read and Insert a file (any format) into a Oracle database
PDO Fetch Lazy
PDO Fetch Lazy: PDO::FETCH_LAZY is the combination of PDO::FETCH_OBJ and PDO::FETCH_BOTH. It displays the query which has been made along with the object... student"; $stmt=$dbh->query($sql); $obj=$stmt->fetch(PDO::FETCH_LAZY); print
php mysql fetch array example
php mysql fetch array example  How to fetch data from mysql and store it into an array in PHP? Please post an example. Thanks in Advance
fetch url in php - PHP
fetch url in php  How to Fetch URL in PHP
Java insertion sort question
Java insertion sort question  I've got another program that I need help with. I am trying to write a Java method that accepts an array of strings, and sorts the strings using the insertion sort algorithm. Then I need to write
PDO Fetch Class
PDO Fetch Class: Using PDO::FETCH_CLASS we can map the fields of a table as properties (fields/variables) of a class. With the help of this method we can...;fetchALL(PDO::FETCH_CLASS,'employee'); foreach($obj as $emp){ echo $emp
insertion in SQL - SQL
insertion in SQL  Hi! Everybody... i have a problem with sql insertion. When i am inserting values through command i.e. insert into employee values(,,,,); here i want to insert ' in employee name column of database
insertion in SQL - SQL
insertion in SQL  Query is "insert into employee values('"+eno+"','"+ename+"');" in the ename place we will get employee names such as John's... in the database because of single code in the name. dbase is MS-SQL emp.name data type
mysql_fetch_object and mysql_fetch_array.
mysql_fetch_object and mysql_fetch_array.  What is the difference between mysqlfetchobject and mysqlfetcharray?   Hi friends, MySQL fetch object will collect first single matching record where mysqlfetcharray
Advertisements
 

 

 

DMCA.com