<%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.util.StringTokenizer" %> <%@ page import="java.lang.*" %> <% " name="description">

Ajax using jsp

Ajax using jsp

<%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.util.StringTokenizer" %> <%@ page import="java.lang.*" %> <% String sn=request.getParameter("pname1"); int quan=Integer.parseInt(request.getParameter("quan")); float rate=Float.parseFloat(request.getParameter("rate")); String pdate=request.getParameter("pdate"); out.println(sn); out.println(quan); out.println(rate); out.println(pdate); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:diagnostic"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select quan from stockdet where pname='"+sn+"'"); int a=0; float b=0; while(rs.next()) { a=rs.getInt(1); } out.println(a); int b1=a+quan; out.println(b1); st.executeUpdate("update stockdetails set quan='"+b1+"',rate='"+rate+"',pdate='"+pdate+"' where pname='"+sn+"'"); out.println("Executed Succesfully"); //response.sendRedirect("index1.html"); } catch (Exception e) { out.println(e); } %>

Is there Any error...........In first Page I use ajax for displaying the data from database and edit that data...that edit data is used in the above code........in the above code iam getting all the data that present in previous page....while updating it is not updated and also in resultset am getting quantity but it is nt getting..........please solve this....................

View Answers

May 12, 2012 at 1:19 PM

The given code displays all the database data into html table.And there is a button at every row to allow the user to edit that particular row. The button will call the function and display the editing row in another page to update that row. The user will then easily update the record.

1)application.jsp:

<%@ page import="java.sql.*" %>
<html>
<head>
<script language="javascript">
function editRecord(id){
    var f=document.form;
    f.method="post";
    f.action='edit.jsp?id='+id;
    f.submit();
}

</script>
</head>
<body>

<br><br>
<form method="post" name="form">
<table border="1">
<tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String userName ="root";
String password="root";

int sumcount=0;
Statement st;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db,userName,password);
String query = "select * from employee";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>
<%
while(rs.next()){
%>
<tr><td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><input type="button" name="edit" value="Edit" style="background-color:green;font-weight:bold;color:white;" onclick="editRecord(<%=rs.getString(1)%>);" ></td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>

May 12, 2012 at 1:20 PM

continue..

2)edit.jsp:

<%@page language="java"%>
<%@page import="java.sql.*"%>
<form method="post" action="update.jsp">
<table border="1">
<tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
String id=request.getParameter("id");
int no=Integer.parseInt(id);
int sumcount=0;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
String query = "select * from employee where id='"+no+"'";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next()){
%>
<tr>
<td><input type="text" name="name" value="<%=rs.getString("name")%>"></td>
<td><input type="text" name="address" value="<%=rs.getString("address")%>"></td>
<td><input type="text" name="contact" value="<%=rs.getInt("contactNo")%>"></td>
<td><input type="text" name="email" value="<%=rs.getString("email")%>"></td>
<td><input type="hidden" name="id" value="<%=rs.getString(1)%>"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
</tr>
<%
}
}
catch(Exception e){}
%>
</table>
</form>

3)update.jsp:

<%@page import="java.sql.*"%>
<%
String ide=request.getParameter("id");
int num=Integer.parseInt(ide);
String name=request.getParameter("name");
String address=request.getParameter("address");
int contact=Integer.parseInt(request.getParameter("contact"));
String email=request.getParameter("email");
try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
Statement st=null;
st=conn.createStatement();
st.executeUpdate("update employee set name='"+name+"',address='"+address+"',contactNo="+contact+",email='"+email+"' where id='"+num+"'");
response.sendRedirect("/examples/jsp/application.jsp");
}
catch(Exception e){
System.out.println(e);
}
%>









Related Tutorials/Questions & Answers:
using jsp's....and ajax - Ajax
using jsp's....and ajax  Hi, i need code using ajax .....in a text box when i enter an alphabet i should get list of words starts with the alphabet given in the text box
Ajax using jsp
Ajax using jsp  <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import...); } %> Is there Any error...........In first Page I use ajax for displaying
Advertisements
ajax using jsp
ajax using jsp  <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.util.StringTokenizer" %> <%@ page import="java.lang.*" %> <
datagid with paging using jsp - Ajax
datagid with paging using jsp  datagrid with paging using ajax and jsp  Hi friend, For read more information : http://www.roseindia.net/jsp/data-grid.shtml Thanks
application using AJAX and JQuery and also use JSP
application using AJAX and JQuery and also use JSP   i need create an application using AJAX and JQuery and also use JSP
Ajax with java(using Dojo) - JSP-Servlet
Ajax with java (using Dojo)  Hi, In In place Edit Box,when I click "save" button how can I save the data in server side i.e JSP or how can I call.... Is there a possibility for tutorial on Scriptaculous. us,for Java programmers
Create Listbox in JSP using AJAX control
Create Listbox in JSP using AJAX control  Hi everyone!!! I want... listbox to select single elemnt using AJAX control . But i don't know anything about AJAX. In that listbox,listbox items are dictly fetched from databases
Popup Window using Ajax In JSP
Popup Window using Ajax In JSP  ... Window application using Ajax in JSP. For this, we will create the following...("Insert")) { %> <jsp:forward page="InsertData.jsp" />
access image from ajax store in mysql using jsp
access image from ajax store in mysql using jsp  access image from ajax store in mysql using jsp (code to access image captured by camera and store in mysql
jsp and ajax
jsp and ajax  how to enable or disable textbox using radio buttons by using jsp and ajax
jsp & ajax
jsp & ajax  how to enable or disable textbox using radio buttons by using jsp and ajax? plz help me.... i m new in jsp & ajax
how to get popup fro servelt to jsp by using ajax........
how to get popup fro servelt to jsp by using ajax........  how to get popup fro servelt to jsp by using ajax........ I went popup in jsp page when my form submit successfully.....through servlet can any buddy give r explian how
How to get data from DB in to Text box by using Jsp & Ajax
How to get data from DB in to Text box by using Jsp & Ajax   I want to get the data from database in to text box in a jsp page by using Ajax. If I enter the letter A in the textbox it should show only those values which starts
ajax jsp - Ajax
ajax jsp  multiple combo with ajax using jsp?  Hi friend, I am sending you a link. This link will help you. Please visit for more information. http://www.roseindia.net/jsp/comboSelect.shtml Thanks
how to generate reports from oracle database using jsp and ajax code
how to generate reports from oracle database using jsp and ajax code  Hai masters i am new to this Java world. my team leader ask me to generate sales report data from oracle database to jsp page please any one know how to do
jsp - Ajax
jsp  I'm very new in using the jsp and ajax, i have some JSP pages and i need to add some ajax features in my jsp page, for the example i need.... How can I implement this and then add this to my jsp page? please
Using Ajax
Using Ajax  Hi, How I can use Ajax in web programming? Tell me any example which using Ajax to call server side script? Thanks   Hi, Here are examples: PHP Ajax and Database First Ajax Example Getting Started
using ajax and jsp (struts) to login and remain on same page.
using ajax and jsp (struts) to login and remain on same page.  I am a fresher... I can forward my login page to success page using struts, but I.../struts/struts2/struts2ajax/ajax-login-form.shtml
Ajax with jsp - Ajax
Ajax with jsp  multiple combo boxes with ajax in jsp?  Hi friend, I am sending you a link. I hope that, this link will help you. Please visit for more information. http://www.roseindia.net/jsp
refreshing a jsp without flickering effect for every 5 seconds using ajax
refreshing a jsp without flickering effect for every 5 seconds using ajax  I want to refresh a jsp without flickering for every 5 seconds using ajax.This jsp is responsible to get the new records from the database and display
JSP and AJAX very urgent - Ajax
JSP and AJAX very urgent  Hi Team, This is Ragavendran.R.. I have a very basic doubt in AJAX. While Using AJAX, of course, there will be tag involved in JSP page. But in my current project, I am using too many tags
ajax code with jsp - Ajax
ajax code with jsp  hi , Sorry for insufficient data.i m making some correction on question. I have to perform some calculation on my jsp page. i want to do it automatically (using ajax in jsp). problem is - i hv two
show folder on server by clicking a row in table using jsp and ajax
show folder on server by clicking a row in table using jsp and ajax  Hi, i want a jsp page which has one dropdown and one textfield. when i click on serach button after selecting the dropdown and a value in textfield it should
show folder on server by clicking a row in table using jsp and ajax
show folder on server by clicking a row in table using jsp and ajax  Hi, i want a jsp page which has one dropdown and one textfield. when i click on serach button after selecting the dropdown and a value in textfield it should
displaying List of records from database in a jsp using ajax
displaying List of records from database in a jsp using ajax  Sir, I...;%@page import="com.tbss.RtChannels"%><%@ taglib uri="http://java.sun.com/jsp... the records using jstl tag libraries. But it is not working. I think
how to get popup fro servelt to jsp by using ajax........
how to get popup fro servelt to jsp by using ajax........  how to get popup fro servelt to jsp by using ajax. I went popup in jsp page when my... 3.servlet page here is jsp page :Salu2.jsp file <%@ page language="java
Combo Box Using Ajax In JSP
Combo Box Using Ajax In JSP       In this section, we develop an  application to Select the Data from database using Ajax in combo box. We created two file
ajax and jsp code - Ajax
ajax and jsp code  can u please give me the code for retriving the data from database using ajax our requriment is if i select country name in listbox display the corresponding all the states. using jsp and ajax   
Problem dispalying Country, City, State in JSP using Ajax in Struts Framework - JSP-Servlet
Problem dispalying Country, City, State in JSP using Ajax in Struts Framework  Hi, In my JSP page, I have used one div that adds some rows... showing data from database using ajax, jquery.. but it is not working.. It is because
Values from servlet into dropdownlist in jsp page using ajax
Values from servlet into dropdownlist in jsp page using ajax  1) jsp file <%@page import="java.sql.Statement"%> <%@page import... servlet into dropdownlist of jsp page...kindly check the code attached and tell me
Jsp and ajax
Jsp and ajax  Hi I am using jsp and ajax.I am retrieving...; function ajax(str){ var xmlHttp; var i; var config=document.getElementById..."; url=url+"?q="+config+"&q1="+config1; xmlHttp.open("POST",url,true
Jsp and ajax
Jsp and ajax  Hi I am using jsp and ajax.I am retrieving...; function ajax(str){ var xmlHttp; var i; var config=document.getElementById..."; url=url+"?q="+config+"&q1="+config1; xmlHttp.open("POST",url,true
Jsp and ajax
Jsp and ajax  Hi I am using jsp and ajax.I am retrieving...; function ajax(str){ var xmlHttp; var i; var config=document.getElementById..."; url=url+"?q="+config+"&q1="+config1; xmlHttp.open("POST",url,true
Jsp and ajax
Jsp and ajax  Hi I am using jsp and ajax.I am retrieving...; function ajax(str){ var xmlHttp; var i; var config=document.getElementById..."; url=url+"?q="+config+"&q1="+config1; xmlHttp.open("POST",url,true
How to use ajax in jsp?
How to use ajax in jsp?  Hi, How i can access the server-side data in JSP using the Ajax? Thanks   Hi, You can use the Ajax code to access the server side data from JSP page. Check the tutorial Combo Box Using Ajax
jsp and ajax - JSP-Servlet
jsp and ajax  i had some problem i want to display the current... to be automatically updated for every second for that i want to make an ajax call.../jsp/fileupload.shtml Thanks
ajax in jsp
ajax in jsp  i m not able to compare string with the responseText value, though the value in the responsetext is of string type. my code: login.jsp <html> <head> <meta http-equiv
ajax in jsp
ajax in jsp  i m not able to compare string with the responseText value, though the value in the responsetext is of string type. login.jsp: print("<html> <head> <meta http-equiv="Content-Type" content="text
JSP and AJAX- very urgent - Ajax
JSP and AJAX- very urgent  Respected Sir/Madam, I am... (Using AJAX. for ur reference, I have included the coding below: Login.html... not support AJAX!"); return; } var url="check.jsp"; url=url+"?id="+alpha
jsp+ajax validation
60% in the drop down list .how to validate student from using ajax and jsp...jsp+ajax validation  hi, I have created the jsp form (course... have created student jsp form where it should display register number
displaying List of records from database in a jsp using ajax, onclick it should display the results ?? its urgent can u help me
displaying List of records from database in a jsp using ajax, onclick it should display the results ?? its urgent can u help me   displaying List of records from database in a jsp using ajax, onclick it should display the results
how to fetch the record using AJAX? - Ajax
how to fetch the record using AJAX?  Can anyone tell me how to fetch the records from database using Ajax
code for jsp - Ajax
country.By using jsp and Ajax.    Hello Friend I send the code you...code for jsp  please give code for using jsp page and Ajax.Retrive... getDetail(source,div){ getData(source,div); } An Ajax Demo
Auto Search box using ajax
Auto Search box using ajax   Hi , i want to implement auto search box functionality like google and linkedin using ajax,jsp,servlet, javascript etc.when the value appears on the textbox then we should also be able to select
Ajac code with jsp - Ajax
Ajac code with jsp  hi , i am beginner for ajax.I have to perform some calculation on my jsp page. i want to do it automatically that is possible using ajax. problem is - i hv two text box. 1st take
ajax in java - JSP-Servlet
ajax in java  The below code is for a php page but I want this in JSP page. function postRequest(strURL){ var xmlHttp...: "login.php"   Hi friend, Do some changes to convert in JSP
Selection With Ajax and JSP
Selection With Ajax and JSP  I am working at a jsp page using ajax for country , state, city selection. so if he select country it will populate... the city. I am doing it through two jsp pages only. Country1.jsp : <%@ page
ajax code for jsp
ajax code for jsp  How to write ajax code to retrieve information on to particular part of webpage when we select option from drop down box
Hiding form values using ajax
Hiding form values using ajax  i am trying to show and hide form values with ajax but it's not working,but in javascript it is working.Can anyone will help me to the work in ajax please. Thanks in advance
DropDown and text boxes with AJAX, JSP - Ajax
present. we are already using jsp's and java technology. can we integrate ajax in jsp's to achieve the same? if so could you please guide me to achive the same...DropDown and text boxes with AJAX, JSP  Hi, we are using one drop

Ads