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



Home Answers Viewqa Development-process JSP Mysql Insert Example
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


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


Advertisement
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 Tutorials/Questions & Answers:
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
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
Advertisements
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
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
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 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 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
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 images into a Mysql database
insert images into a Mysql database  How can I insert images into a Mysql database
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
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
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
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 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
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...(connectionURL,"root","root"); String queryString = "INSERT INTO stu_info(Name,City
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
insert query in jsp
insert query in jsp  give me insert code in jsp at run time
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
Unable to Insert Arabic words in mysql table
Unable to Insert Arabic words in mysql table  I have I java program that I want to insert arabic letters in mysql. Do you have any idea about the configuration of mysql that accepts arabic charcters.   in jsp use
SQL Bulk Insert Example
SQL Bulk Insert Example       SQL Bulk Insert Example is used to insert a bulk record... to create SQL Bulk Insert .To grasp this example we create a table 'Stu
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
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
SQL Bulk Insert Example
SQL Bulk Insert Example       SQL Bulk Insert Example is used to insert a bulk record to the table... Bulk Insert .To grasp this example we create a table 'Stu_Table'. 
insert image - JSP-Servlet
insert image  hi friends i am mahesh i am trying to insert image into oracle database using JSP but i am not geting so please friends send me the code for inserting image into database using JSP   Hi Friend, Try
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<
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
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 data in mysql database through jsp using prepared statement
Insert data in mysql database through jsp using prepared statement...; This is detailed jsp code that how to insert data into database by using prepared statement... 'student' in mysql and table named "stu_info" in same database by sql
 

 

 

DMCA.com