473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Hibernate insert problem

can someone tell me what is wrong with this code.
it prints "Data Inserted Successfully" but does not insert the values to database

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <%!
  4. int empno;double salary;String name; Session session1 = null;
  5. %>
  6. <body>
  7. <%
  8. String num1=request.getParameter("t1");
  9. if(num1 != null)
  10. {
  11. empno=Integer.parseInt(num1);
  12. name=request.getParameter("t2");
  13. String sal=request.getParameter("t3");
  14. salary=Integer.parseInt(sal);
  15. try
  16. {
  17. Configuration cf=new Configuration();
  18. cf.configure();
  19. SessionFactory sessionFactory = cf.buildSessionFactory();
  20. session1 =sessionFactory.openSession();
  21. Transaction tr = session1.beginTransaction();
  22. Emp e=new Emp(empno,name,salary);
  23. tr.commit();
  24. session1.save(e);
  25.  
  26. session1.close();
  27. out.println("<h1>Data Inserted Successfully</h1>");
  28. }
  29. catch(Exception e)
  30. {
  31. System.out.println("e="+e.getMessage());
  32. }
  33. }
  34. %>
  35.  
  36. <form>
  37.   <table width="352" border="1">
  38.     <tr>
  39.       <th>Emp Number</th>
  40.       <td><input name="t1" type="text"></td>
  41.     </tr>
  42.     <tr>
  43.       <th> Name </th>
  44.       <td><input name="t2" type="text"></td>
  45.     </tr>
  46.     <tr>
  47.       <th>Salary </th>
  48.       <td><input name="t3" type="text"></td>
  49.     </tr>
  50.     <tr>
  51.       <th colspan="2"><input type="submit"value="Submit" >
  52.       </th>
  53.     </tr>
  54.   </table>
  55. </form>
  56. </body>
  57. </html>
  58.  
Mar 1 '13 #1
1 1507
r035198x
13,262 8TB
1.) Don't mix java with HTML. Use plain java classes for the hibernate parts.
2.) You are committing the transaction before saving the data.
Mar 6 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Caversham | last post by:
I am trying to insert data into the fields id and term of the table key. id is an auto-incrementing field. Each of the following forms fails:- INSERT INTO key (id, term) VALUES (0, 'dog') ...
1
by: Adrian | last post by:
Both servers running SQL 2000 I have set up on our local SQL server (using Enterprise Manager) a linked server running on our ISP. Just did new linked server and added remote password and login....
5
by: kieran | last post by:
INSERT INTO Comments_tbl (FullName_tsf, Email_tsf, NTuser_tsf, name_tsf, type_tsf, comments_tsf) VALUES ('Test Tester' , 'tester@test.com', 'ttest', 'test', 'help', 'need better help') I am...
2
by: Steve Kuekes | last post by:
I have two sql servers, I have defined each one as a linked server to the other. I can mostly access the servers from one another, but I get the following error on a sql insert. Insert...
5
by: Raed Sawalha | last post by:
dear : i have the following problem: string sAttachmentBody; int nCount = 0; int nMaxLineLength = 77; //sAttachmentBody.Length may reaches (560960 chars)
2
by: simon | last post by:
I have couple asp.net controls on the page, including compare and range validators. When user click the insert button, the data are inserted into the database. It works on my computer and on...
2
by: Steven Blair | last post by:
When I hit a button inside my FormView which has Insert as its Command Name, my Insert statement is executed with the correct parameters (the events Inserting & Inserted are fired). But I need...
0
by: paulhux174 | last post by:
Hi, I've a dataGrid set up (the standard msdn example) with a SqlDataAdapter, and DataSet. The problem is that after inserting a new row using the LinkButton1_Click() (code below) then edit...
5
by: Brad Baker | last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL database. At the top of the page I have the following code: <%@ Page Language="C#" Debug="true" %> <%@ import...
15
by: abracad_1999 | last post by:
I am trying to populate a table with the following insert query run through phpmyadmin. When I attempt to run it phpmyadmin just freezes. After a while "Fatal error: Maximum execution time of 300...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.