0% found this document useful (0 votes)
12 views2 pages

Exp 6 BVP Java

The document describes a Java program that inserts data into a MySQL database table using JSP. The program connects to the database, executes two INSERT statements to add records, and then retrieves and displays the inserted data in an HTML table.

Uploaded by

Nanu Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Exp 6 BVP Java

The document describes a Java program that inserts data into a MySQL database table using JSP. The program connects to the database, executes two INSERT statements to add records, and then retrieves and displays the inserted data in an HTML table.

Uploaded by

Nanu Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment 6

Aim: Write a Java program to insert data into a table using JSP.
Code:
index.jsp
<%@ page import="java.sql.*" %>
<% Class.forName("com.mysql.jdbc.Driver"); %>
<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:mysql://localhost:3306/mydbms", "root", "root");
Statement statement = connection.createStatement();
String command = "INSERT INTO register(id, name) VALUES(1,'Vikas')";
statement.executeUpdate(command);
command = "INSERT INTO register(id, name) VALUES (2,'Akshay')";
statement.executeUpdate(command);
ResultSet resultset =
statement.executeQuery("select * from register");
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>
Output:

You might also like