| | |
I can't insert data into database
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2009
Posts: 2
Reputation:
Solved Threads: 0
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)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <HR noshade size="5" width="50%" align="center"> <title>ZONE</title> </head> <body bgcolor="Silver"> <%@ page language="java" import = "java.sql.*,java.util.*,java.text.*,java.io.*" %> <CENTER> <h4><font size="4" face="Verdana">ZONE MASTER</font> </h4> <BR></BR> <h4><font size="2" face="Verdana">ZONE CODE <input type="text" name="ZONE_CODE" value="" width="06" /> </h4></font> <h4><font size="2" face="Verdana">ZONE NAME <input type="text" name="ZONE_NAME" value="" width="06" /> </h4></font> </CENTER> <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:oraclexe","hr","hr"); String zone_code=request.getParameter("ZONE_CODE"); String zone_name=request.getParameter("ZONE_NAME"); if(request.getParameter("INSERT") != null) { try{ String ins= "insert into ni_zone_master (zone_code,zone_name ) values ('"+zone_code+"', '"+zone_name+"')"; PreparedStatement st1 = con.prepareStatement(ins); st1.executeUpdate(); con.close(); } catch(SQLException sqle) { out.println("ERROR IN PAGE"+sqle); } } if(request.getParameter("UPDATE") != null) { try{ 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+"' "; PreparedStatement st1 = con.prepareStatement(ins); st1.executeUpdate(); con.close(); } catch(SQLException sqle) { out.println("ERROR IN PAGE"+sqle); } } if(request.getParameter("DELETE") != null) try{ String ins = "DELETE FROM ni_zone_master WHERE zone_code = '"+zone_code+"' AND zone_name = '"+zone_name+"'"; PreparedStatement st1 = con.prepareStatement(ins); st1.executeUpdate(); con.close(); } catch(SQLException sqle) { out.println("ERROR IN PAGE"+sqle); } %> <CENTER> <form name="INSERT" method="POST"> <input type="submit" value="ADD" name="ADD" onclick="InsertZoneInfo()"/></form> <form name="CHANGE" method="POST"> <input type="submit" value="UPDATE" name="UPDATE" onclick="UpdateZoneInfo()"/></form> <form name="DELETE" method="POST"> <input type="submit" value="DELETE" name="DELETE" onclick="DeleteZoneInfo()"/></form> </CENTER> </body> <HR noshade size="5" width="50%" align="center"> </html>
Last edited by Tekmaven; Jun 7th, 2009 at 10:03 pm. Reason: Code Tags
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
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
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.
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 ?"
"How to ask questions the smart way ?"
•
•
Join Date: Jun 2009
Posts: 1
Reputation:
Solved Threads: 0
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
hope this will works.........
bye
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.
![]() |
Similar Threads
- How to insert data into database? (JSP)
- insert and update data in two different database (JSP)
- source code to insert data into database using javabean (Java)
- inser data into database (JSP)
- how to insert data into the database in vb.net using textfields. (VB.NET)
- How to insert data into a db (Java)
- Please help(Problem in insertion data to database) (JSP)
- Insert Data in to Db from the Dynamic Rows (HTML and CSS)
- Unable to insert data into database. (MySQL)
Other Threads in the JSP Forum
- Previous Thread: Error: Requested resource not available for Servlet
- Next Thread: oracle session in jsp pages
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish imagetodatabse imageupload internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial video web






