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



Home Answers Viewqa Development-process JSP Mysql Insert Example

Have Programming Question? Ask it here!
 
 
 


uma
JSP Mysql Insert Example
1 Answer(s)      6 years and 4 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
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
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 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
insert query in jsp
insert query in jsp  give me insert code in jsp at run time
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
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
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
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'. 
JSP &MYSQL
JSP &MYSQL  Develop a web page for the telephone directory using jsp and mysql
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
how to insert the selected item of combobox in mysql - XML
how to insert the selected item of combobox in mysql  hi, i have to insert the selected item from combobox into MYSQL database.pls provide... of combobox in mxml.how to insert selecteditem in database. pls suggest me i have
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
connection of jsp with mysql - JSP-Servlet
Example of connection between JSP and MYSQL  Need an example of connection between JSP and MYSQL
JSP with Mysql
JSP with Mysql  Hi sir, I trying to several time but i am not get an answer. My questions are 1. How to inserting same field data to different mysql table using jsp. That is creating a form with 5 fields,data's are same
jsp mysql
........... like that all requests nd comments should be display through jsp and mysql...jsp mysql  actually i want a page that has two frames nd in 1 frame i'l add a textarea to post some help nd nw when he clicks on post button it has
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
insert data into mysql databse using swing
insert data into mysql databse using swing   Blockquote hi, here is my code, i want code for store data into mysql database when click on submit button from access data from this form, please provide code, import java.awt.
jsp_mysql
jsp_mysql  hi,, plz help me by providing the code for displaying SELECTED columns from mysql table which are given dynamically through checkboxes...; <html> <head><title>Read from mySQL Database</title>
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
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
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
how to insert values from jsp into ms access
how to insert values from jsp into ms access   how to insert values using jsp into ms access database
problem in insert query - JSP-Servlet
problem in insert query  Hi! I am using this statement for data insertion into table but data is not moving only null passed and stored:- String insertQuery= "insert into volunteer_profiles ( name, gender ) values ( 'name
Connect JSP with mysql
Connect JSP with mysql   ... you how to connect to MySQL database from your JSP code. First, you need... database in my sql command prompt) 2. Connect JSP with mysql
Query to insert values in the empty fields in the last row of a table in Mysql database?
Query to insert values in the empty fields in the last row of a table in Mysql database?  I have some fields filled and some fields empty in the last row of my MYSQL database. Now I want to fill up those empty fields in the last
jsp/mysql connection
jsp/mysql connection  I am puttng the following files in the lib folder of jdk to connect jsp and mysql and in the lib folder of tomacat and in the lib folder of project of netbeans but I am unable to to connect jsp and mysql
jsp/mysql connection
jsp/mysql connection  I am puttng the following files in the lib folder of jdk to connect jsp and mysql and in the lib folder of tomacat and in the lib folder of project of netbeans but I am unable to to connect jsp and mysql
How to connect mysql with jsp
How to connect mysql with jsp  how to connect jsp with mysql while using apache tomcat
Advertisements
 

 

 

DMCA.com