Home Answers Viewqa Development-process JSP Mysql Insert Example

 
 


uma
JSP Mysql Insert Example
1 Answer(s)      5 years and 3 months ago
Posted in : Development process

I need a JSP and MYsql code to insert into the database.

View Answers

April 15, 2008 at 8:06 PM



InsertInto-Database.jsp


<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<html>

<head>
<title>Insert into database</title>
</head>

<body>

<table border="1" width="50%">
<tr>
<td width="100%">
<form method="POST" action="InsertDatabaseAction.jsp">

<h2 align="center">Insert Into Database</h2>
<table border="1" width="100%">
<tr>
<td width="50%"><b>First Name:</b></td>
<td width="50%"><input type="text" name="firstname" value=""/> </td>
</tr>
<tr>
<td width="50%"><b>Last Name:</b></td>
<td width="50%"><input type="text" name="lastname" size="21"></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>

</form>
</td>
</tr>
</table>
</body>
</html>

InsertDatabaseAction.jsp

<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<%

Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
java.util.Date date;
String s=null;
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
Statement st = con.createStatement();
String username=request.getParameter("firstname");
String lastname=request.getParameter("lastname");

int val = st.executeUpdate("insert stu_detail values(id,'"+username+"','"+lastname+"')");

con.close();
out.println("successfully insert data into database!");
out.println("</br>");
out.println("<br/><a href=useredit-page.jsp><b>Edit and Delete</b></a>");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}

%>

useredit-page.jsp

<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>
<html>
<head>
<title>Retrive value from database</title>
</head>
<body>
<table border="0" width="75%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<h2><font color="#FF0033">Retrive data from database</font></h2>
<form method="POST" >
<table border="1" width="100%" cellspacing="0" cellpadding="0" bgcolor="#CCFFCC">
<tr>
<td width="50%"><b>User ID:</b></td>
<td width="50%"><b>First Name</b></td>
<td width="50%"><b>Last Name</b></td>
<td width="50%"><b>Edit</b></td>
<td width="50%"><b>Delete</b></td>
<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
Statement st = con.createStatement();
String query = "SELECT * FROM stu_detail";
ResultSet rs = st.executeQuery(query);
while (rs.next()) {
%>

<tr>
<td width="50%" valign="right"><%=rs.getInt("id")%><br/></td>

<td width="50%"><%=rs.getString("firstname")%><br/></td>
<td width="50%"><%=rs.getString("lastname")%><br/></td>

<td width="50%"><a href="edit.jsp?id=<%=rs.getInt("id")%>"><img src="edit.jpg" border="0"></a></td>
<td width="50%"><a href="RecordDelete.jsp?id=<%=rs.getInt("id")%>"><img src="delete.jpg" border="0"></a></td>
</tr>

<%}

out.println("<br/><a href=insertInto-database.jsp><b>Insert Data page</b></a>");
rs.close();
con.close();

}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

edit.jsp

<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<html>

<head>
<title>Insert into database</title>
</head>

<body>

<%
String strId =request.getParameter("id");
int id = Integer.parseInt(strId);
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
Statement st = con.createStatement();
String query = "SELECT firstname,lastname FROM stu_detail where id="+id;
ResultSet rs = st.executeQuery(query);
while (rs.next()) {
%>


<table border="1" width="50%">
<tr>
<td width="100%">
<form method="POST" action="RecordUpdateAction.jsp">
<input type="hidden" name="id" value="<%=request.getParameter("id")%>">
<h2 align="center">Insert Into Database</h2>
<table border="1" width="100%">

<tr>
<td width="50%"><b>First Name:</b></td>
<td width="50%"><input type="text" name="firstname" value="<%=rs.getString("firstname")%>"/> </td>
</tr>
<tr>
<td width="50%"><b>Last Name:</b></td>
<td width="50%"><input type="text" name="lastname" value="<%=rs.getString("lastname")%>" size="21"></td>
</tr>
</table>
<p><input type="submit" value="Update" name="submit">
<input type="reset" value="Reset" name="reset"></p>

</form>
</td>
</tr>
</table>


<%}

rs.close();
con.close();

}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>
</body>

</html>

RecordUpdateAction.jsp

<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<%
String strId =request.getParameter("id");
int id = Integer.parseInt(strId);
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
Statement st = con.createStatement();
String username=request.getParameter("firstname");
String jobposition=request.getParameter("lastname");
int in = st.executeUpdate("UPDATE stu_detail SET firstname ='"+username+"', lastname ='"+jobposition+"' where id ="+id);
con.close();
out.println("successfully updated");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>
--------------------------------------------------------------

RecordDelete.jsp


<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<%
String strId =request.getParameter("id");
int id = Integer.parseInt(strId);
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
Statement st = con.createStatement();
String username=request.getParameter("firstname");
String jobposition=request.getParameter("lastname");
int in = st.executeUpdate("DELETE FROM stu_detail where id ="+id);
con.close();
out.println("successfully updated");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>









Related Pages:
JSP Radio Button MySQL insert - JSP-Servlet
JSP Radio Button MySQL insert  Hi, I have an HTML form which has a couple of radio buttons for example (gender: male/female) and some check boxes... with the code to store radio button data and checkbox data to MySQL table. For example
Mysql Insert
Mysql Insert       Mysql Insert is used to insert the records or rows to the table. Understand with Example The Tutorial illustrate an example from 'Mysql Insert'.To grasp
insert name city image in database using mysql and jsp
insert name city image in database using mysql and jsp  how to insert name ,city and image in database in mysql and jsp   Here is an example in jsp that insert name, city and image to database. <%@ page import
jsp and mysql
jsp and mysql  i have a form which contains dropdown list. i have to take the values to another jsp page and perform the calculation on the database... as it is and the new function value in the new jsp page.. im in the middle of the project
Insert Blob(Image) in Mysql table using JSP
Insert Blob(Image) in Mysql table using JSP In this Section, we will insert blob data(image) in Mysql database table using JSP code. A Blob stores a binary... Blob(Image) in Mysql table using JSP Download Source Code
insert excel sheet into mysql as a table
insert excel sheet into mysql as a table  sir, i want to import an excel sheet into mysql5.0 database as in the table format using tomcat 6.0 by jsp
Mysql Multiple Date Insert
illustrate an example from 'Mysql Multiple Column Insert'.To understand... Mysql Multiple Date Insert       Mysql Multiple Column Insert is used to add or insert
Mysql Multiple Date Insert
illustrate an example from 'Mysql Multiple Column Insert'. To understand an example... Mysql Multiple Date Insert       Mysql Multiple Column Insert is used to add or insert
MySQL PHP Insert
. Understand with Example The Tutorial illustrate an example on MySQL PHP Insert... MySQL PHP Insert       Mysql PHP Insert is used to execute the Mysql function ( ) insert
insert name city and upload image in database using mysql and jsp
insert name city and upload image in database using mysql and jsp   insert name city and upload image in database using mysql and jsp
Uploading Excel sheet record in JSP to insert data in MySql
Uploading Excel sheet record in JSP to insert data in MySql  Need Help how to upload Excel (.xls) file and insert data in Mysql using JSP it wil be wonder for me if any help me
Mysql Trigger After Insert
The Tutorial illustrate an example from Mysql Trigger After Insert. To understand... Mysql Trigger After Insert       Mysql Trigger After Insert fired the trigger after you
MySQL allowMultiQueries JSP Example
MySQL allowMultiQueries JSP Example In this section we will discuss about how.... This example explains you all the steps for allowing multiple queries using MySQL... will insert some value into it. Then we will create a JSP page where we will write
insert values - JSP-Servlet
insert values  How to insert values in the oracle database using JSP... page<html><head><title>Insert value in database</title><...;100%"> <h1><center>Insert value in Database<
JSP-Mysql - JSP-Servlet
JSP-Mysql  Hello friends, Anyone send me the way how to store image in mysql database from a jsp page.  Hi friend, Code to insert image in mysql Using Jsp : For more information on JSP
To insert attachment file in database in JSP.
To insert attachment file in database in JSP.  I am doing project in JSP. How to insert attachment file in mysql database? Please suggest some solution. Your inputs is valuable to me.   Hi Friend, Visit Here Thanks
Insert a row in 'Mysql' table using JSP Code
Insert a row in 'Mysql' table using JSP Code In this section, we will discuss about how to insert data in Mysql database using JSP code. Query...; Mysql database Table. Code to insert row in Mysql table : databaseinsertion.jsp
Insert and Retrieve Image - JSP-Servlet
Insert and Retrieve Image  Hello, I need source code using java servlet or jsp and html form and brief explanations on how to insert and retrieve image from Microsoft sql database 2000 not Mysql please as sent to me earlier
fetch and insert multiple rows into mysql database using jsp servlet
fetch and insert multiple rows into mysql database using jsp servlet  ... jsp form and want inserting it into my mysql database table. but i am having a problem to insert multiple rows into database using a single insert query
insert data
insert data  i've got a problem to insert my data to database.i can... =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","...("insert into images values(?,?,?,?,?)"); st.setString(2
insert images into a Mysql database
insert images into a Mysql database  How can I insert images into a Mysql database
jsp, mysql - Java Beginners
jsp, mysql  i want to store / insert the selected value in the combo box (jsp), into the mysql. how to do it?... pls help me in urgent
insert query in mysql
insert query in mysql  insert query in mysql not working   [INSERT INTO Birthdays(firstname, lastname, birthday, group) VALUES('Sam','Smith','June','Junior
help in insert code - JSP-Servlet
help in insert code  I have some doubt in following code. I want to insert value using prepared statement.we r accessing connection from other... = response.getWriter(); Connection con = null; String url = "jdbc:mysql
To insert attachment file in database in JSP.
To insert attachment file in database in JSP.  I am doing project in JSP. How to insert attachment file in mysql database? Please suggest some... connectionURL = "jdbc:mysql://localhost:3306/test"; ResultSet rs = null
connection of jsp with mysql - JSP-Servlet
Example of connection between JSP and MYSQL  Need an example of connection between JSP and MYSQL
JDBC: Insert Records Example
JDBC: Insert Records Example In this section, you will learn how to insert...){ System.out.println("Insert Records Example..."); Connection con = null...(); } } } Output  : Insert Records Example... Record inserted successfully
Servlet Example To Insert Mysql Clob Data
Servlet Example To Insert Mysql Clob Data    This example shows how to insert CLOB data in the database. In our... how to insert data of CLOB type in mysql database through the servlet program
To Upload and insert the file into Database with Current Date and Time In JSP
To Upload and insert the file  into Database with Current Date and Time In JSP       In this tutorial, you will learn how to upload a file through JSP and insert
mysql jsp - Java Beginners
mysql jsp  how to insert values to mysql? i want to insert values from a combo box to mysql... how to perform that. pls help me in urgent.  Hi friend, Plz give full source code where you having the problem
Struts insert & retrieve
Struts insert & retrieve  Give a struts prg to insert and retrieve data from mysql db using the struts tags(no jsp scriplets and expressions) following mvc arch. i.e. model containing db connectivity, form containing get &
mysql with jsp - Java Beginners
mysql with jsp  i wanted to insert a combo box value to mysql table usgin jsp. how to perform that. can anybody help me in urgent.  Hi... For more information on JSP visit to : http
Java Multiple Insert Query
example that demonstrates how to execute the multiple sql insert query in JSP...Java Multiple Insert Query In this example we will discuss about how to execute multiple insert query in Java. This example explains you about how
Insert current date into MYSQL database
Insert current date into MYSQL database In this tutorial, you will learn how to insert current date into database. In most of the applications, there is a need to insert date or time to database. Mysql provides several datatypes
To Upload and insert the CSV file into Database
to upload a CSV file through JSP and insert it into the database. For this, we have created two jsp pages page.jsp and upload_page.jsp. The page.jsp is created... To Upload and insert the CSV file into Database
JDBC Insert Statement Example
.style1 { text-align: center; } JDBC Insert Statement Example JDBC Insert statement allow you to insert record into the table of the database... the database and insert record to the database. At first create table named student
PHP SQL Insert
an example from PHP SQL Insert . To understand the example, firstly we need... PHP SQL Insert       PHP SQL Insert is used to insert the record from HTML page to Mysql 
MVC Example
MVC Example  I WANT MVC EXAMPLE PROGRAM using Jsp Servlets and Jdbc with mysql of Insert,update,delete,search. please give the answer in MVC rule
HOW WRITE GREEK CHARACTERS INTO MYSQL BY JSP ?
HOW WRITE GREEK CHARACTERS INTO MYSQL BY JSP ?  HALLOW TO ALL ! I'M USING MYSQL5.5 , TOMCAT7 & JSP. IN MY BROWSER I'M SEEING GREEK CHARS BECAUSE...:mysql://localhost:3306/XXXXX?user=userName&password=usersPassword&
Using javabeans to connect mySQL database on a jsp page - JSP-Interview Questions
Using javabeans to connect mySQL database on a jsp page  Hi, Am doing my project and I don't know how to connect a jsp page to a mySQl database...; Connecting a JSP page to MYSQL Database using JavaBean File Name: beancode.java
Insert Operation - WebSevices
Insert Operation  Send the code for Insert Contact in pop up window... insert my contact details(Name,email and etc).So,send the code and solution... pop up window having a form if record insert successfully prints a message
MySQL Generate AlphaNumberic Id In JSP
MySQL Generate AlphaNumberic Id In JSP In this section we will discus about how to generate id in specific format in MySQL and JSP. This example explains... into JSP page. This example explains you all the steps for creating the alpha
Ant Script to Insert Data in Mysql Table
Ant Script to Insert Data in Mysql Table       This example illustrates how to insert data...;value="jdbc:mysql://192.168.10.211/test"/>   <
Image in mysql
Image in mysql  Hi. How to insert and retrieve images in mysql db using JSP or JAVA Servlet? Thanks in advance
insert code jsp to access
insert code jsp to access   insert code jsp to access
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it
Insert data in mysql database through jsp using Prepared Statement ---- Please..."); String connectionURL ="jdbc:mysql://localhost:3306/studentdb"; Connection...,"root","root"); String queryString = "INSERT INTO stu_info(Name,City,Phone
mysql - JSP-Servlet
mysql  code to add photo in mysql database ... i want page from which i can upload photo which will store in mysql database and display in one page in jsp...  Hi Friend, Try the following code: 1)page.jsp
PHP SQL Query Insert
PHP SQL Query Insert       This example illustrates how to execute insert query in php...). Now, queries can be executed using mysql_query() method to insert values
what is the jsp coding to insert a data in database tables
what is the jsp coding to insert a data in database tables  Dear Sir, I Want to know the coding for insert the data from jsp to oracle database.. my... that insert the form values to MySQL database. 1)register.jsp: <html> <form
Insert Image in DB through Servlet - JSP-Servlet
Insert Image in DB through Servlet  Dear Sir, My previous Query... pre = conn.prepareStatement("insert into MyPictures values...(e.getMessage()); } } } Whether Any entry will be made in web.xml when Insert Image