Update data into the database Using Hibernate and Servlet by
R4R Team
Here we will discuss how to update data into the database table without go in the database. Yes it can be possible when we work with the hibernate. For this we will take as we discussed in the last example how to fetch data form the database table data into the jsp page.
Here in the Hibernate we can update the data which we inserted into the database. It can be done through the some basic step as we discussed in our last session of the project example of the hibernate. So now here we will create as we done before and we will show the code to implement only here.
<title>Hibernate Application Using Servlet</title>
</head>
<body>
<pre>
<form action="MyServlet" method="post">
First Name <input type="text" name="fist_name"/>
Last Name <input type="text" name="last_name"/>
Salary <input type="text" name="sal"/>
<input type="submit" value="Submit"/>
</form>
</pre>
</body>
</html>
Step 3. create a table in the database. Remember which database you selected on the time of the project taking all table will be created into the same database. Now we here we will use the hibernate_pro database.
1. create table InsertData001
(
id int not null auto_increment primary key,
fname varchar(50),
lname varchar(50),
sal int(50));
Step 3. Take a package type the name of the package r4r.
Step 4. create a Hibernate reverse engineering file as we discussed in our last example.
hibernate.reveng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-catalog="hibernate_pro"/>
<table-filter match-name="InsertData001"/>
</hibernate-reverse-engineering>
Step 5. create a POJO class it is also we discussed in out last session.(Note that POJO class must be creted into the package)
InsertData001.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!