Program 2
<%--
Document : productsearch
Created on : Jan 12, 2024, 6:46:55 PM
Author : admin
--%>
<%@page import="java.util.List"%>
<%@page import="beans.Mobile"%>
<%@page import="org.hibernate.Query"%>
<%@page import="org.hibernate.Session"%>
<%@page import="org.hibernate.SessionFactory"%>
<%@page import="org.hibernate.cfg.Configuration"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<center>
<font color="red" size="5">Product Search Page</font>
<form>
<textarea rows=2 cols="150" name="txtproduct"></textarea>
<br>
<input type="submit" value="Search">
</form>
<%
String pname=null;
pname=request.getParameter("txtproduct");
if(pname!=null)
{
Configuration cfg=new Configuration();
cfg.configure("resources/hibernate.cfg.xml");
SessionFactory sf=cfg.buildSessionFactory();
Session session1=sf.openSession();
Query q;
String hql;
hql="from Mobile where mbname like '" +pname + "%'";
q=session1.createQuery(hql);
List<Mobile>mylist=q.list();
if(mylist.size()==0)
out.println("<font color=blue size=6>Record not found</font>");
else
{
out.println("<table border=1>");
out.println("<tr><th>ID</th><th>Mobile Name</th><th>Price</th><th>Type</th></tr>");
for(Mobile M1:mylist)
{
out.println("<tr>");
out.println("<td>"+M1.getMbid()+"</td>");
out.println("<td>"+M1.getMbname()+"</td>");
out.println("<td>"+M1.getPrice()+"</td>");
out.println("<td>"+M1.getType()+"</td>");
out.println("</tr>");
}
out.println("</table>");
}
}
%>
</center>
</body>
</html>Program 3
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package beans;
public class Mobile
{
private int mbid;
private String mbname;
private String price;
private String type;
public Mobile() {
}
public int getMbid() {
return mbid;
}
public void setMbid(int mbid) {
this.mbid = mbid;
}
public String getMbname() {
return mbname;
}
public void setMbname(String mbname) {
this.mbname = mbname;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}Program 4
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="beans.Mobile" table="mobile" schema="dataflair">
<id name="mbid" column="mbid"></id>
<property name="mbname" column="mbname"></property>
<property name="price" column="price"></property>
<property name="type" column="type"></property>
</class>
</hibernate-mapping>Program 5
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/dataflair</property>
<property name="connection.username">root</property>
<property name="connection.password">root@data</property>
<property name="connection.pool_size">10</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<mapping resource="resources/mobile.hbm.xml"/>
</session-factory>
</hibernate-configuration>