ARTICLE

Insert Data Into Table Through JSP

Posted by Vikas Mishra Articles | JSP January 10, 2012
In this article, I am going to develop an application that shows how to insert data into a table through JSP.
Reader Level:
 

This is another very important application in the series of database applications using JSP. In this article, I am going to develop an application that shows how to insert data into a table through JSP. In this application we are filling the data through JSP coding.

Step 1: Create a new database

In the first step we click on the blank database option and click on the create.

make a new database.jpg

Step 2: Design the database

In this step we select a field name and data type for the those fields. In this application we select five fields (id, name).

design.jpg

Step 3: Make DSN

In this step we make a DSN using the following process.

First we select the control panel option from start.

select the control panel.jpg

Then click on the administrative tools

click on administration tools.jpg

Select Data Sources option

select data source option.jpg

Then select Microsoft Access Driver(*.mdb,*.accdb), and click on the finish button.

create new data source.jpg

Then select database from the computer and give it a specific name; now the DSN is created.

select database.jpg

Step 4: Create a New Project

In this step we select New Project option from the file menu.

create new project.jpg

Step 5: Choose Project

In this step we select web application from Java web option and then click on the next button.

select new web application.jpg

Step 6: Name and Location

In this step we given it a specific name and set a specific location and click on the next button.

name.jpg
 

Step 7: Server and Setting

We select a specific server for this application and click on the next button.

server and setting.jpg

Step 8: Select Framework

There is no need to select any framework for this application; just click on the finish button.

selectframework.jpg

Step 9: Create jsp file

We create one jsp file for this application.

create new jsp file.jpg

Insert.jsp

<%@ page import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>
<HTML>
     <HEAD>
     <TITLE>
Inserted data in a Table</TITLE>
     </HEAD>
     <BODY BGCOLOR="cyan">
     <H1>Inserted data in a Table</H1>
     <%
         Connection connection =DriverManager.getConnection("jdbc:odbc:employee");
         Statement statement = connection.createStatement();
         String command = "INSERT INTO Employee(ID, Name) VALUES(1,'Vikas')";
         statement.executeUpdate(command);
         command = "INSERT INTO Employee(ID, Name) VALUES (2,'Akshay')";
         statement.executeUpdate(command);
         ResultSet resultset =
         statement.executeQuery("select * from Employee");
         while(resultset.next()){
      %>
        <TABLE BORDER="1">
          <TR>
              <TH>ID</TH>
              <TH>Name</TH>
         </TR>
          <TR>
              <TD> <%= resultset.getString(1) %> </TD>
              <TD> <%= resultset.getString(2) %> </TD>
          </TR>
       </TABLE>
       <%
        }
       %>
      </BODY>
</HTML>


Step 10:
Compile and Run the application

Now we compile the application and then run it on the server and find the following output.

Output

Insert.jsp

output.jpg

Resources related to these article:

Login to add your contents and source code to this article
post comment
     

plz upload edit or update database in jsp..plz its urgent

Posted by neil rathod Apr 30, 2013

quite helpful..thanks

Posted by vishal koradiya Mar 04, 2013
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.