how to use update

how to use update

View Answers

August 24, 2009 at 5:23 PM

Hi Friend,

We have taken four fields of database table exam(student_id,student_name,subject,marks).Similarly you can modify all the fields.Here we are providing you a code that will modify these four fields.

1)a.jsp:

<%@ page import="java.sql.*" %>
<html>
<head>
<script language="javascript">
function editRecord(id){
window.open('http://localhost:8080/examples/jsp/aa.jsp?id='+id,'mywindow','width=500, height=350,toolbar=no,resizable=yes,menubar=yes');

}
</script>
</head>
<body>

<br><br>
<table border="1">
<tr><th>Student Id</th><th>Student Name</th><th>Subject</th><th>Marks</th><th></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 exam";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>

<%
while(rs.next()){
%>
<tr><td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><a href="#" onclick="editRecord(<%=rs.getString(1)%>);" >Edit</a></td>
</tr>
<%
}
%>
<%
}
catch (Exception e) {
e.printStackTrace();
}
%>

</table>
</form>
</body>
</html>

August 24, 2009 at 5:24 PM

continue...........
2) aa.jsp:

<%@page language="java"%>
<%@page import="java.sql.*"%>
<form method="post" action="aaa.jsp">
<table border="1">
<tr><th>Student ID</th><th>Student Name</th><th>Subject</th><th>Marks</th></tr>
<%
String id=request.getParameter("id");
int no=Integer.parseInt(id);

Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";;
String dbName = "test";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";

int sumcount=0;
Statement st;

try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
String query = "select * from exam where student_id='"+no+"'";
st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next()){
%>

<tr>
<td><input type="text" name="id" value="<%=rs.getString(1)%>"></td>
<td><input type="text" name="name" value="<%=rs.getString(2)%>"></td>
<td><input type="text" name="sub" value="<%=rs.getString(3)%>"></td>
<td><input type="text" name="mar" value="<%=rs.getString(4)%>"></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>
</form>

August 24, 2009 at 5:26 PM

continue.........

3)aaa.jsp:

<%@page import="java.sql.*"%>
<% String no=request.getParameter("id");
String name=request.getParameter("name");
String sub=request.getParameter("sub");
String mar=request.getParameter("mar");
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 exam set student_id='"+no+"', student_name='"+name+"',subject='"+sub+"',marks='"+mar+"' where student_id='"+no+"'");
out.println("Data is updated successfully");
}
catch(Exception e){}
%>

Hope that the above code will be helpful for you.
Thanks









Related Tutorials/Questions & Answers:
how to update
how to update   conditional update
how to use update - Java Beginners
how to use update  Hi all, your all code is perfect thanks. I have one table emp ID,emp name,view,modify and delete. emp_ide_name have taken from database but view modify and delete is link if user click modify data
Advertisements
how to update image in php
how to update image in php  how to update image in php
How to use update and reset method of CRC32
How to use update and reset method of CRC32.In this tutorial, we will discuss about the update() and reset() method of CRC32 class. The CRC32 class... in  java.util.zip package .  In this example, you will see how
How to update table in Hibernate
How to update table in Hibernate  Hi, I have a table in database that has two fields in it. Student Name and ID, can anyone explain me how to update these tables in Hibernate. Thanks.   Update table query in Hibernate
how to update the value of jslider
how to update the value of jslider  hello, I want to make a audio player but the jslider is not updating help me
how to update the value of jslider
how to update the value of jslider  hello, I want to make a audio player but the jslider is not updating help me
how to update the value of jslider
how to update the value of jslider  hello, I want to make a audio player but the jslider is not updating help me
how to update the value of jslider
how to update the value of jslider  hello, I want to make a audio player but the jslider is not updating help me
how to update the value of jslider
how to update the value of jslider  hello, I want to make a audio player but the jslider is not updating help me
how to update the text file?
how to update the text file?  if my text file contains a string and integer in each line say,: aaa 200 bbb 500 ccc 400 i need a java code to update the integer value if my input String matches with the string in file. please
How to update clob??
How to update clob??  I have a table "articles" which contains the columns -articletitle,details,author,serial.The details column is the only column which is Clob and the serial is int.The rest are varchar2.I want to update all
how to update the text file?
how to update the text file?  my textfile with name list.txt: Rice 25.0 500 Wheat 80.0 150 Jowar 50.0... i want to update the quantity in my text file, if the item i entered matches
how to update specific row in on update key in the Navicat for mysql trigger
how to update specific row in on update key in the Navicat for mysql trigger   Blockquote insert into two(name, date) select name, curdate() from one on duplicate key update name=values(name
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
how to update checkbox list in database
how to update checkbox list in database  Issues: i am using different checkboxs for getting role then all role list store in one string array i want to update one by one but it's not updating by using below code .it's not adding
how to update table using inner joins
how to update table using inner joins  how to update table using inner joins
How to update mysql from 5.1 to 5.5
How to update mysql from 5.1 to 5.5  How to update mysql from 5.1 to 5.5
How to update a file
How to update a file All the file operations have to be performed using java.io.* package. You have already learnt various file operations. In this section, you will learn how to update the text file.  Description of code: We
How to recover from google panda update?
How to recover from google panda update?  Hi, After rolling out of the Google Panda 4.0 update my website is hit and the traffic is now more than 60... Panda update ASAP. Can anyone guide me "How to recover from google panda update
update
update  Predict and justify the output of the following code snippet written by the developer to update the Status table: String str = "UPDATE m...://localhost:3306/roseindia", "root", "root"); String str = "UPDATE Status SET
how do i update my database with the help of update syntax in html <text/javascript>? How to write 'where' statement in this?
how do i update my database with the help of update syntax in html ? How to write 'where' statement in this?  var sqlmek="update into Student_info... ActiveXObject("ADODB.Recordset"); alert('How are you!!'); cn.Open(strConn
How to survive google panda 4.0 update
How to survive google panda 4.0 update  Hi, Recently Google Panda 4.0 is released and many website is impacted. So, How to survive the Google Panda 4.0 update? Thanks   In this update of the Google Panda 4.0 many
how to add a update button in the following jsp
how to add a update button in the following jsp  Once the excel from the following jsp is loaded to the broswer, how to add a button in the jsp to allow the user to update the excel? thanks, <%@page import="java.io.*"%>
Mysql Update command
Mysql Update       Mysql Update Mysql Update is used to modify the table... Update SQL Update is used to modify the existing structure of table
how to update xml from java - XML
how to update xml from java  hi, Im new to xml parsing and dont know much about. I need to modify the attribute val of a tag in a complex xml file by using java code tell me the procedure. Thanks in advance.   hi
how to display(update) current date and month in select box on selecting the year.
how to display(update) current date and month in select box on selecting the year.  how to display(update) current date and month in select box on selecting the year
how update JTable after adding a row into database
how update JTable after adding a row into database  J have two... in JTable, and it's OK, but after adding a row into database table does't update. How update JTable after adding a row into database? package djile pak.java
How to update record to database? I have trouble with the following code
How to update record to database? I have trouble with the following code  I have written the update statement but it still not work to update...']; $sql="UPDATE customer SET deliveryAdd= $deliveryAdd WHERE custEmail=$emailAddress
Maven dependency for cn.bingoogolapple - bga-update version 1.0.1 is released. Learn to use bga-update version 1.0.1 in Maven based Java projects
version of  cn.bingoogolapple - bga-update library is 1.0.1. Developer can use this version ( cn.bingoogolapple - bga-update version 1.0.1...-update released The developers of   cn.bingoogolapple - bga-update
Maven dependency for cn.bingoogolapple - bga-update version 1.0.0 is released. Learn to use bga-update version 1.0.0 in Maven based Java projects
version of  cn.bingoogolapple - bga-update library is 1.0.0. Developer can use this version ( cn.bingoogolapple - bga-update version 1.0.0...-update released The developers of   cn.bingoogolapple - bga-update
how to make JTable to add delete and update sql database table
how to make JTable to add delete and update sql database table  Hello all I want to know how to make JTable to act actively to add delete and update database table. i am struck ed here from long time please help me
update query
update query  using oops concept in php.. How to update the data from databse ? with program example
How to update,Delete database values from jtable cells ..
How to update,Delete database values from jtable cells ..  Hello Sir, I am working on a project in which i have to fetch the values from database to jtable .Now as per my requirement i need to update and delete
How to update,Delete database values from jtable cells ..
How to update,Delete database values from jtable cells ..  Hello Sir, I am working on a project in which i have to fetch the values from database to jtable .Now as per my requirement i need to update and delete the database
How to update,Delete database values from jtable cells ..
How to update,Delete database values from jtable cells ..  hello Sir, I am currently working on a project where i have to fetch the data... to update the cell values from there only means that whatever values i ma entering
Update SQL Query Example
;In this video I will teach you how to use the update query to update the data...Update SQL Query Example  Hi, I am beginner in SQL (MySQL) and trying to learn Update SQL Query with Example code. Can anyone explain me the SQL
how to update values of a html form into an excel table using java servlets?
how to update values of a html form into an excel table using java servlets?  i have written a java servlet program, which has a html form to be filled. after filling the form the servlet generates a receipt and the values should
How to insert and update all column values of database from jtable.
How to insert and update all column values of database from jtable.  ... ,update,delete database values from jtable only so i added three buttons add,update,delete .. mydatabase contains five columns id,name,address,contact,email
The UPDATE Statement
The UPDATE Statement       The UPDATE statement is used to modify the data in the database table through a specified criteria. In the given syntax of update statement the keyword SET
How to overcome Google Penguin Update?
Learn how to overcome Google Penguin Update by making necessary changes in your website. To overcome Google Penguin update is a popular search word... at this emerging term and how far it is important for web practices. In the last decade
How to update table column from the values of Arraylist in java
How to update table column from the values of Arraylist in java  Hii Sir, I have an arraylist containing these values [2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 3, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 1, 1
How to insert and update all column values of database from jtable.
How to insert and update all column values of database from jtable.  ... ,update,delete database values from jtable only so i added three buttons add,update... added successfully..everytime... and update button is not working atall
How to insert and update all column values of database from jtable.
How to insert and update all column values of database from jtable.  ... ,update,delete database values from jtable only so i added three buttons add,update... added successfully..everytime... and update button is not working atall
update profile
update profile  coding for update profile
how to update combobx's selected value to database with respect toselected multiple checkboxes
how to update combobx's selected value to database with respect toselected multiple checkboxes   suppose this if form1.jsp in which i am going...="update PROFILE set Route_Id='"+txt[t]+"' where Proid='"+lang[j
Update a resultset programmatically
Update a resultset programmatically  How to update a resultset programmatically
How to delete and update from Jtable cell in swing app
How to delete and update from Jtable cell in swing app  Hii Sir, I am developing a swing app for adding,updating and deleting from jtable... will use // I'm overriding the getColumnClass static DefaultTableModel
Google Penguin Algorithm update issues and How to Recover
major Google Penguin update, which hit the ranking and search visibility of websites... update and why did it affect your website? Matt Cutts on May 22 2013 announced that a new Penguin 2.0 update has been released, which will be the update
want to ask how to update data for runtime selected multiple checkboxes
want to ask how to update data for runtime selected multiple checkboxes ... and entered the values in the textbox then it should get update in the database.I have succesfully updated when I am clickinga single checkbox but I want to update

Ads