473,499 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hi, i am using ajax to update a database table. it is like, one can change the value

2 New Member
in a text box and click on update button. once the button is click a function with parameter as the changed value. it is sent to a jsp file for updation.
when i try to run this code, it shows number format exception-input string undefined.
Oct 9 '09 #1
3 3819
Dormilich
8,658 Recognized Expert Moderator Expert
well, then you probably didn’t pass the value correctly somewhere.
Oct 9 '09 #2
techno
2 New Member
but i could not find the error. been trying for long..
here s d code

Expand|Select|Wrap|Line Numbers
  1. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <title>Untitled Document</title>
  7. <% 
  8.                              //          String id1=(String)session.getAttribute("user");
  9.                              //          out.println("welcome  "+id1+",ur shopping cart contains");
  10.                                       %>
  11.  
  12. <%!
  13. String p,pn,c,q;
  14. %>
  15. <SCRIPT language="javascript">
  16. var xmlHttp,url;
  17.  
  18.  
  19.  
  20. function change1(p,val)            //to check product availability and if available update the product table
  21. {
  22.  // var d=window.document.getElementById("quantity");
  23.  //  var n=d.options[d.selectedIndex].value;
  24.     xmlHttp=GetXmlHttpObject();
  25.     if (xmlHttp==null)
  26.       {
  27.           alert ("Your browser does not support AJAX!");
  28.           return;
  29.       } 
  30.                  url="https://localhost:8443/change.jsp";
  31.  
  32.               //   url=url+"?pwd="+n1+"&repwd="+n2;
  33.  
  34.  
  35.                url=url+"?prod="+p+"&q="+val;
  36.                 xmlHttp.onreadystatechange=stateChanged;
  37.       xmlHttp.open("GET",url,true);
  38.       xmlHttp.send(null);
  39.    } 
  40.  
  41.  
  42. function stateChanged() 
  43.                   { 
  44.  
  45.        if(xmlHttp.readyState==4)
  46.           {
  47.                                 document.getElementById("dataTable").innerHTML=xmlHttp.responseText;    
  48.         }
  49.                 }
  50.  
  51.  
  52. function GetXmlHttpObject()
  53. {
  54.     if (window.XMLHttpRequest)
  55.     {
  56.     // code for IE7+, Firefox, Chrome, Opera, Safari
  57.      return new XMLHttpRequest();
  58.   }
  59.   if (window.ActiveXObject)
  60.   {
  61.     // code for IE6, IE5
  62.     return new ActiveXObject("Microsoft.XMLHTTP");
  63.   }
  64. return null;
  65. }
  66.  
  67. </SCRIPT>
  68. </head>
  69. <body>
  70.  
  71. <%
  72. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
  73. Connection con=DriverManager.getConnection("jdbc:odbc:ds");     
  74.  
  75. Statement st = con.createStatement();
  76.  
  77. String q="SELECT * FROM \"ADMINISTRATOR\".USERID";
  78. ResultSet rs=st.executeQuery(q);
  79. %>
  80.  
  81. <form name="formId" action="tot1.jsp"  method="post">
  82. <table id="dataTable" border=2 bgcolor="#FFFFFF" cellpadding="5" cellspacing="2">
  83.  
  84. <tr>
  85. <TH>CHOOSE</TH>
  86. <th>PRODUCT ID</th>
  87. <th>PRODUCT NAME</th>
  88. <TH>COST</TH>
  89. <TH>QUANTITY</TH>
  90. </tr>
  91. <%
  92. while(rs.next())
  93. {
  94.  
  95. p=rs.getString("PID");
  96. pn=rs.getString("PNAME");
  97. c=rs.getString("COST");
  98.  
  99. %>
  100.  
  101. <tr>
  102. <td><input type="checkbox" name="uid" id="uid"  value="<%= p%>" /></td>
  103. <td ><%=p%> </td>            
  104. <td ><%=pn%> </td>
  105. <td ><%=c%> </td>
  106.  
  107. <td><input type="text" name="quantity" id="quantity" value="1" /></td>
  108.  
  109. </td>
  110. </tr>
  111.  
  112. <%
  113. }
  114. %>
  115.  
  116. <tr> 
  117. <td><input type="button" name="update" value="Update cart" onClick="change1(document.formId.uid.value,document.formId.quantity.value)"
  118. </td>
  119. <td><input type="button" name="add" value="Add more" onClick="window.location='http://localhost:8443/index2.jsp' "  />  
  120. </td>
  121. <td><input type="submit" name="submit" value="Checkout"  />
  122. </td>
  123. </tr>
  124. </table>
  125. </form>
  126.  
  127. <%
  128. st.close();
  129. con.close();
  130. %>
  131. </body>
  132. </html>



here s the jsp file to which the parameter is sent

Expand|Select|Wrap|Line Numbers
  1. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  3. <%@ page import="java.io.*" %>
  4. <%@ page import="java.lang.*" %> 
  5.  
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  9. <title>Untitled Document</title>
  10. </head>
  11. <%!
  12. String p,pn,c,sql,s1;
  13. String update,update1;
  14. int quantity;
  15. %>
  16.  
  17. <body>
  18.  
  19. <%
  20. String code=new String(request.getParameter("prod"));
  21. String q=new String(request.getParameter("q"));
  22.  
  23.  
  24. int ID=Integer.parseInt(code);
  25. int qu=Integer.parseInt(q);
  26.  
  27. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  28.  
  29. Connection con =DriverManager.getConnection("jdbc:odbc:ds"); 
  30. Connection con1 =DriverManager.getConnection("jdbc:odbc:ds"); 
  31. Connection con2 =DriverManager.getConnection("jdbc:odbc:ds"); 
  32. Connection con3 =DriverManager.getConnection("jdbc:odbc:ds"); 
  33.  
  34.  
  35. Statement stmt=con.createStatement();
  36. Statement stmt1=con1.createStatement();
  37. Statement stmt2=con2.createStatement();
  38. Statement stmt3=con3.createStatement();
  39.  
  40.  
  41.  s1="SELECT * FROM ADMINISTRATOR.PRODUCT WHERE PID="+ID;
  42. ResultSet rs=stmt1.executeQuery(s1);
  43.  
  44. while(rs.next())
  45. {
  46.  p=rs.getString("quantity");
  47.  quantity=Integer.parseInt(p);
  48.  
  49. if(qu<quantity)
  50. {
  51.   quantity=quantity-qu;
  52.  
  53.  
  54.  sql = "UPDATE ADMINISTRATOR.USERID SET QUANTITY="+qu+"  WHERE PID= "+ID;
  55. stmt.executeUpdate(sql);
  56.  
  57. update="UPDATE ADMINISTRATOR.PRODUCT SET QUANTITY="+quantity+" WHERE PID="+ID;
  58. stmt1.executeUpdate(update);
  59.  
  60. update1="UPDATE ADMINISTRATOR.PROD SET QUANTITY="+quantity+" WHERE PID="+ID;
  61. stmt2.executeUpdate(update1);
  62.  
  63. }
  64.  
  65. else if(qu>quantity)
  66. {
  67. // response.sendRedirect("https://localhost:8443/index1.jsp");
  68. out.print(" REQUIRED QUANTITY NOT AVAILABLE");
  69. }
  70. }
  71. stmt.close();
  72. stmt1.close();
  73. stmt2.close();
  74. stmt3.close();
  75.  
  76. con.close();
  77. con1.close();
  78. con2.close();
  79. con3.close();
  80.  
  81. %>
  82. </body>
  83. </html>
Oct 14 '09 #3
acoder
16,027 Recognized Expert Moderator MVP
When passing any URL parameters, encode them using encodeURIComponent().
Oct 24 '09 #4

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

Similar topics

5
2011
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
6
17133
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
5
2416
by: ggk517 | last post by:
We are trying to develop an Engineering application using PHP, Javascript with Informix as the back-end. Is it possible to retrieve data using Javascript but by accessing the Database. Say...
7
6959
by: Serge Rielau | last post by:
Hi all, Following Ian's passionate postings on problems with ALTOBJ and the alter table wizard in the control center I'll try to explain how to use ALTOBJ with this thread. I'm not going to get...
3
6561
by: =?Utf-8?B?RGVlcGE=?= | last post by:
Hi All, I have a webform in asp.net framework 1.1 where the dropdownlist is populated with list of locations from the database. The depending on the list selected, the user will be able to see...
2
3121
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
17
2908
by: Shalini Bhalla | last post by:
i have 2 tables bank master and branch details having bankcode as a common feild . i have designed a form in which i am filtering branches according to a particular bank code using ajax ,...
7
2008
by: JDOMPer | last post by:
Don’t misunderstand me – I use AJAX, but I think there is a far simpler, elegant alternative that just uses Javascript, the DOM and Php ( hence - JDOMP) for data transfers, and is cross-browser...
1
4579
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in...
5
4433
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
0
7131
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
7007
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
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
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...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.