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 html coding,
<html>
<form method="post" action="http://localhost:8080/examples/jsp/1/insert.jsp">
<table>
<tr><td>DEPARTMENT_NAME</td><td><input type="text" name="DEPARTMENT_NAME"></td></tr>
<tr><td>DEPARTMENT_ID</td><td><input type="text" name="DEPARTMENT_ID"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>
// when i give departmentname and departmentid and click submit i want to save this data in my oracle database.. in oracle i created a table "department" and having this departmentname and departmentid colums, and also let me know how to mention my oracle server in coding..
thank you!!
Ragulan.M
View Answers
August 29, 2012 at 3:37 PM
Here is a jsp code that insert the form values to MySQL database.
1)register.jsp:
<html>
<form method="post" action="insert.jsp">
<table>
<tr><td>First Name:</td><td><input type="text" name="fname"></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="lname"></td></tr>
<tr><td>Email:</td><td><input type="text" name="email"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td>Confirm Password:</td><td><input type="password" name="cpass"></td></tr>
<tr><td>Date Of Birth</td><td><input type="text" name="dob"></td></tr>
<tr><td>Age:</td><td><input type="text" name="age"></td></tr>
<tr><td>Gender</td><td><input type="text" name="gender"></td></tr>
<tr><td>Address:</td><td><input type="text" name="address"></td></tr>
<tr><td>Country</td><td><input type="text" name="country"></td></tr>
<tr><td>State:</td><td><input type="text" name="state"></td></tr>
<tr><td>City</td><td><input type="text" name="city"></td></tr>
<tr><td>Telephone No:</td><td><input type="text" name="tno"></td></tr>
<tr><td>Mobile:</td><td><input type="text" name="mobile"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>
2)insert.jsp:
<%@page import="java.sql.*,java.util.*"%>
<%
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String email=request.getParameter("email");
String pass=request.getParameter("pass");
String cpass=request.getParameter("cpass");
String dob=request.getParameter("dob");
int age=Integer.parseInt(request.getParameter("age"));
String gender=request.getParameter("gender");
String address=request.getParameter("address");
String country=request.getParameter("country");
String state=request.getParameter("state");
String city=request.getParameter("city");
int telephone=Integer.parseInt(request.getParameter("tno"));
int mobile=Integer.parseInt(request.getParameter("mobile"));
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into student(firstname,lastname,email,pass,confirm_pass,dob,age,gender,address,country,state,city,telephone,mobile) values('"+fname+"','"+lname+"','"+email+"','"+pass+"','"+cpass+"','"+dob+"',"+age+",'"+gender+"','"+address+"','"+country+"','"+state+"','"+city+"',"+telephone+","+mobile+")");
out.println("Data is successfully inserted!");
}
catch(Exception e){
System.out.print(e);
e.printStackTrace();
}
%>
August 30, 2012 at 10:13 AM
thank you for the reply!!
how to mention the
"Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root");"
for oracle.. i am confused here..
November 11, 2012 at 5:48 PM
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "username", "password");"
Ads
Related Tutorials/Questions & Answers:
how to insert data into database using jsp & retrive
how to
insert data into
database using
jsp & retrive Hello,
I have created 1 html page which contain username, password & submit button. in my oracle10G
database already contain table name admin which has name, password
Advertisements
how to insert data in database using html+jsp
how to
insert data in
database using html+jsp anyone know
what... and
database name. Here machine name id localhost and
database name... = null;
// declare a resultset that uses as a table for output
data from
insert data into database
insert data into database hi,thanks for reply
just i am doing student information project,frontend is
jsp-servlet and backend is msaccess2007. i... the
data into the
jsp page that
data stored into the database.Here the error
database is connected but not insert the data
database is connected but not
insert the data hi,
i am getting connected to database.Retrive the
data also but cannot
insert the
data into
database...=con.prepareStatement("
insert into studentmaster(slno) values('"+batch+"')");
i
unable to insert data into database
unable to
insert data into
database hello.i have a problem in inserting
data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting
data into
database based
unable to insert data into database
unable to
insert data into
database hello.i have a problem in inserting
data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting
data into
database based
unable to insert data into database
unable to
insert data into
database hello.i have a problem in inserting
data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting
data into
database based
unable to insert data into database
unable to
insert data into
database hello.i have a problem in inserting
data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting
data into
database based
insert data into database
insert data into database type Exception report
message...)Go to the start->Control Panel->Administrative Tools->
data sources.
2... selecting the driver, click finish button.
4)Then give
Data Source Name
Insert data in Excel File from Database using JSP
developed a application to
insert data in excel file from
database in
JSP. We... the
data from
database, create an excel file and
data
insert into newly...
Insert data in Excel File from Database using
JSP 
insert data in the database using checkbox
insert data in the
database using checkbox i am fetching
data from the
database using servlet on the
jsp page and there is checkbox corresponding... should i
insert only checked
data into
database on submission.
We
Question about "Insert text file data into Database"
Question about "
Insert text file
data into
Database" Hey
I was reading the tutorial "
Insert text file
data into
Database", (awesome btw), and noticed that both a FileInputStream, a DataInputStream and a BufferedReader
search in Two Tables to Find data and view by jsp
search in Two
Tables to Find
data and view by jsp hi i want search in Two
Tables to Find
data and view by
jsp
<%@page import...; Have a look at the following link:
JSP search using two
tables
 
how to insert checkbox value into database using jsp
how to
insert checkbox value into
database using jsp How to
insert check box value to the oracle
database using
jsp?
I want to create hotel's...;
Here is a simple
jsp code that
insert the selected checkbox values
how to insert checkbox value into database using jsp
how to
insert checkbox value into
database using jsp How to
insert check box value to the oracle
database using
jsp?
I want to create hotel's package. where the admin will select the activities to
insert in the PACKAGE table. I