943,621 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 2409
  • JSP RSS
Jun 7th, 2009
0

I can't insert data into database

Expand Post »
Hi I have a difficulty in insertion data. I don't get any error message but it doesn't insert data to database. My code is below. Where am I wrong?


JSP Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <HR noshade size="5" width="50%" align="center">
  7. <title>ZONE</title>
  8. </head>
  9. <body bgcolor="Silver">
  10.  
  11. <%@ page language="java" import = "java.sql.*,java.util.*,java.text.*,java.io.*" %>
  12. <CENTER>
  13. <h4><font size="4" face="Verdana">ZONE MASTER</font> </h4>
  14. <BR></BR>
  15. <h4><font size="2" face="Verdana">ZONE CODE <input type="text" name="ZONE_CODE" value="" width="06" /> </h4></font>
  16. <h4><font size="2" face="Verdana">ZONE NAME <input type="text" name="ZONE_NAME" value="" width="06" /> </h4></font>
  17. </CENTER>
  18.  
  19.  
  20. <%
  21.  
  22. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  23. Connection con = DriverManager.getConnection("jdbc:odbc:oraclexe","hr","hr");
  24.  
  25. String zone_code=request.getParameter("ZONE_CODE");
  26. String zone_name=request.getParameter("ZONE_NAME");
  27.  
  28. if(request.getParameter("INSERT") != null) {
  29. try{
  30. String ins= "insert into ni_zone_master (zone_code,zone_name ) values ('"+zone_code+"', '"+zone_name+"')";
  31.  
  32. PreparedStatement st1 = con.prepareStatement(ins);
  33. st1.executeUpdate();
  34.  
  35. con.close();
  36. }
  37. catch(SQLException sqle)
  38. {
  39. out.println("ERROR IN PAGE"+sqle);
  40. }
  41. }
  42. if(request.getParameter("UPDATE") != null) {
  43. try{
  44. String ins= "UPDATE ni_zone_master SET zone_code = '"+zone_code+"', zone_name = '"+zone_name+"' WHERE zone_code = '"+zone_code+"' AND zone_name = '"+zone_name+"' ";
  45.  
  46. PreparedStatement st1 = con.prepareStatement(ins);
  47. st1.executeUpdate();
  48.  
  49.  
  50. con.close();
  51. }
  52. catch(SQLException sqle)
  53. {
  54. out.println("ERROR IN PAGE"+sqle);
  55. }
  56. }
  57. if(request.getParameter("DELETE") != null)
  58. try{
  59. String ins = "DELETE FROM ni_zone_master WHERE zone_code = '"+zone_code+"' AND zone_name = '"+zone_name+"'";
  60.  
  61. PreparedStatement st1 = con.prepareStatement(ins);
  62. st1.executeUpdate();
  63. con.close();
  64. }
  65. catch(SQLException sqle)
  66. {
  67. out.println("ERROR IN PAGE"+sqle);
  68. }
  69.  
  70. %>
  71.  
  72. <CENTER>
  73. <form name="INSERT" method="POST">
  74. <input type="submit" value="ADD" name="ADD" onclick="InsertZoneInfo()"/></form>
  75. <form name="CHANGE" method="POST">
  76. <input type="submit" value="UPDATE" name="UPDATE" onclick="UpdateZoneInfo()"/></form>
  77. <form name="DELETE" method="POST">
  78. <input type="submit" value="DELETE" name="DELETE" onclick="DeleteZoneInfo()"/></form>
  79. </CENTER>
  80. </body>
  81. <HR noshade size="5" width="50%" align="center">
  82. </html>
Last edited by Tekmaven; Jun 7th, 2009 at 10:03 pm. Reason: Code Tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vandana88 is offline Offline
2 posts
since Jun 2009
Jun 7th, 2009
-1

Re: I can't insert data into database

You posted in wrong section, check out our Web Development for JSP section (I already made request for post to be moved)
Also in mean time you can have look at this post JSP database connectivity according to Model View Controller (MVC) Model 2
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is online now Online
6,654 posts
since Dec 2004
Jun 9th, 2009
0

Re: I can't insert data into database

i'm so sorry as i was very new to this community and now what should i do shall i remove this thread and paste it somewhere else?
and plz do solve my problem. Is my code correct or i should do any modifications?It's very urgent......thanks in advance
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vandana88 is offline Offline
2 posts
since Jun 2009
Jun 10th, 2009
0

Re: I can't insert data into database

Well syntactically your JSP page is correct, although the approach of firing queries directly from inside the JSP page (that too using SQL Statements constructed on the fly) is not only bad but dangerous.

Also you need some brushing up on your concepts of HTML and Javascript. The <input> tags need to be nested inside a corresponding <form> tag, if you want the data from the <input> tag to be posted to the JSP page mentioned in the "action" attribute of <form> tag.
Also I do not see any Javascript functions by the name of InsertZoneInfo(),UpdateZoneInfo() or DeleteZoneInfo()

If you are using Firefox you could go to Tools ->Error Console to see the various Javascript errors or alternatively you could install the Firebug extension for more comprehensive debugging info.
Anyways the situation as I see demands that you learn not only about JSP and MVC[1,2,3] but also about HTML and JavaScript right now.
Last edited by stephen84s; Jun 10th, 2009 at 3:30 am.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Jun 29th, 2009
0

Re: I can't insert data into database

double check on database schema and tables and columns

are they exactly what you have in the code?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
CoSIS1 is offline Offline
22 posts
since Jun 2009
Jul 2nd, 2009
0

Re: I can't insert data into database

You can make two changes:
1: from oracle database homepage login as administrator then unlock the hr (may be it work)
2: try this url: to Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
hope this will works.........

bye
Last edited by peter_budo; Jul 2nd, 2009 at 9:17 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
irfannagaria is offline Offline
1 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Error: Requested resource not available for Servlet
Next Thread in JSP Forum Timeline: oracle session in jsp pages





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC