Hibernate Application 1 [Link] <html> <head> <script> function subm() { [Link]="[Link] [Link](); } function listme() { [Link]="[Link] f1.
submit(); } </script> </head> <body> <form name=f1> <h2>Enter Product Details here</h2> <br> <hr> <br> <table> <tr><td>Pno<td><input type=text name="pno"></tr> <tr><td>Product Name<td><input type=text name="pname"> <tr><td><input type=button value="List Products" onclick="listme()"><td><input type=button value="Insert" onclick="subm()"></tr> </table> </form> </body> </html> 2. [Link] [Link] [Link] [Link].driver_class [Link] [Link] jdbc:odbc:Mydsn [Link] sa [Link] hibernate.show_sql true
3. [Link]
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "[Link] <hibernate-mapping> <class name="Product" table="product"> <id name="pno" type="string"
>
<column name="pno" sql-type="text" not-null="true"/> <generator class="assigned"/> </id> <property name="pname"/> </class> </hibernate-mapping>
4. Product pojo import [Link].*; import [Link].*; public class Product { String pno; String pname; public Product() { } public Product(String pno,String pname) { [Link] = pname; [Link] = pno; } public void setPno(String id) { pno = id; } public String getPno(){ return pno; } public void setPname(String pn) {
pname = pn; } public String getPname() { return pname; } } 5. servlet1 import [Link].*; import [Link].*; import [Link].*; import [Link].*; import [Link].*; public class prodlist extends GenericServlet { static SessionFactory sessionFactory; public void service(ServletRequest req,ServletResponse res) throws ServletException,IOException { PrintWriter out=[Link](); try { Configuration cfg = new Configuration(); [Link]([Link]); sessionFactory = [Link](); } catch (Exception e) { [Link](e); } try { Session session = [Link](); [Link]("<html>"); [Link]("<table border='1'>"); [Link]("<tr><td>Pno</td><td>Product Name</td></tr>"); List cds = [Link]("from Product"); Iterator iter = [Link](); while ([Link]()) { Product cd = (Product)[Link](); [Link]("<tr><td>"); [Link]([Link]());
[Link]("</td><td>"); [Link]([Link]()); [Link]("</td><td>"); [Link]("</td></tr>"); [Link](); [Link](); } } catch (Exception e) {[Link](e);}
} } 6. servlet 2 import [Link].*; import [Link].*; import [Link].*; import [Link].*; import [Link].*; public class prodserv extends GenericServlet { static SessionFactory sessionFactory; public void service(ServletRequest req,ServletResponse res) throws ServletException,IOException { PrintWriter out=[Link](); String no=[Link]("pno"); String pn=[Link]("pname"); try { Configuration cfg = new Configuration(); [Link]([Link]); sessionFactory = [Link](); } catch (Exception e) { [Link](e); } try { Product pd = new Product(no,pn); Session session = [Link]();
Transaction t = [Link](); [Link](pd); // [Link](); [Link](); [Link](); [Link]("<h2>Record inserted..."); [Link](); } catch (Exception e) {[Link](e);} } }