I can't insert data into database

Reply

Join Date: Jun 2009
Posts: 2
Reputation: vandana88 is an unknown quantity at this point 
Solved Threads: 0
vandana88 vandana88 is offline Offline
Newbie Poster

I can't insert data into database

 
0
  #1
Jun 7th, 2009
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?


  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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,118
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 471
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: I can't insert data into database

 
0
  #2
Jun 7th, 2009
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
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 2
Reputation: vandana88 is an unknown quantity at this point 
Solved Threads: 0
vandana88 vandana88 is offline Offline
Newbie Poster

Re: I can't insert data into database

 
0
  #3
Jun 9th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,176
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: I can't insert data into database

 
0
  #4
Jun 10th, 2009
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.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 22
Reputation: CoSIS1 is an unknown quantity at this point 
Solved Threads: 1
CoSIS1 CoSIS1 is offline Offline
Newbie Poster

Re: I can't insert data into database

 
0
  #5
Jun 29th, 2009
double check on database schema and tables and columns

are they exactly what you have in the code?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 1
Reputation: irfannagaria is an unknown quantity at this point 
Solved Threads: 0
irfannagaria irfannagaria is offline Offline
Newbie Poster

Re: I can't insert data into database

 
0
  #6
Jul 2nd, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC