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


Home Answers Viewqa Ajax ajax using jsp

 
 


srujana
ajax using jsp
2 Answer(s)      a year and a month ago
Posted in : Ajax

<%@ 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); } %>

View Answers

May 12, 2012 at 1:21 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:23 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 Pages:
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
Ajax  how to impliment ajax in registration table using jsp-servlet
Ajax
Ajax  how to include ajax in jsp page?   Hi, Please read Ajax First Example - Print Date and Time example. Instead of using PHP you can write your code in JSP. Thanks
ajax
me reg this. thanks KK   Combobox box using Ajax in JSP   i...ajax  HI, In my application using ajax if i type a managername in the textbox it should display all the employees under the that manager
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
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
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
ajax
ajax  I am facing following problem, I am using ajax to get...(top,left and right) using table in jsp. On the left part i am displaying some... part. Here am using tag to display the output.Whenever user clicks on the link
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.*" %> <
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
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
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
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   
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
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
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...;select name="comboBoxMenu" id="${j}" onchange="ajax(this.value);"> <
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...;select name="comboBoxMenu" id="${j}" onchange="ajax(this.value);"> <
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...;select name="comboBoxMenu" id="${j}" onchange="ajax(this.value);"> <
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...;select name="comboBoxMenu" id="${j}" onchange="ajax(this.value);"> <
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
Ajax Learner - Ajax
these days. Here are the benefits of using Ajax: * Ajax can be used...Ajax Learner  Hi, This is Ziaul,I am working as Java/j2ee Developer from last one year. i have to use Ajax for my current project.pls guide me how
Ajax Learner - Ajax
these days. Here are the benefits of using Ajax: * Ajax can be used.../ajax/ http://www.roseindia.net/jsp/comboSelect.shtml Thanks...Ajax Learner  Hi, This is Ziaul,I am working as Java/j2ee Developer
Table refresh with ajax - Ajax
Table refresh with ajax  I am using jsp/html in my code. Is it compulsory that i have to use a servlet to implement table refresh using ajax? Or jsp also would work? Rajatha
https call in AJAX - Ajax
/jsp/popup-window-using-ajax-in-jsp.shtml Hope that it will be helpful for you...https call in AJAX  Hi, I am trying to call a https URL in my AJAX script which is in my JSP. But it is not getting the reponse from the url i
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
Ajax user interface - Ajax
these all has to be do using JSP,AJAX,JDBC what exactly i needed...Ajax user interface  hello could anyone help my requirement is to design the database interaction using AJAX my requirement is a table
Ajax in struts application - Ajax
Ajax in struts application  I have a running application using struts and now i want to implement Ajax(for populating some search box) in it.The problem is that my jsp page is able to send the request to my Struts Action process
Ajax with BIRT - Ajax
is my code.. JSP and Servlet using AJAX function getXMLObject...Ajax with BIRT  Hai i am currently working on BIRT in a company... to call my BIRT report from my jsp on a button Click. I have tried some code. But I am
ajax example
in jsp page?   Hi, Please read Ajax First Example - Print Date and Time example. Instead of using PHP you can write your code in JSP... form in Ajax using jQuery framework. Thanks  DOJO
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
ajax code - Ajax
ajax code  hello sir, how can i insert a text field dynamically by using ajax   Hi Friend, Try the following code: 1)ajax.jsp...= document.getElementById("name").value; window.open("http://localhost:8080/examples/jsp
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
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
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
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...;jsp:forward page="InsertData.jsp" /> <% } else
Ajax
Ajax  send the example to fetch the data from the server by using ajax in java. for ex:-if there are states which is used to display in frontend we use ajax. send it to me
Ajax not working in jsp
Ajax not working in jsp  I'm using Netbean, Ajax validation in the following code is not working the code succesfully run for first UID validation...; frmMain.elements[i].valid; } } return blnValid; } //if Ajax
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
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
ajax  how to connect ajax with mysql without using php,asp or any other scripting language. please answer soon
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
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
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
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
Ajax  I want message print on jsp page that come from servlet through ajax.please help me out
Ajax
Ajax  I want message print on jsp page that come from servlet through ajax.please help me out
filter and display html table data using ajax - Ajax
filter and display html table data using ajax  Hi i am stuck up at a situation where i have a jsp page from where the control goes to the .js file calling the ajax function called retrieveURL.from here goes
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