Home Answers Viewqa Java-Beginners how to use update

 
 


Ragini Shukla
how to use update
3 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners

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 Pages:
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
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
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
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
how to update   conditional update
update a JTable - Java Beginners
update a JTable   how to update a JTable with Mysql data through user interface   Hi friend, Please implement like the follows code... is the working table model I use: class ResultSetTableModel extends
how to update image in php
how to update image in php  how to update image in php
JDBC: Update Records Example
JDBC: Update Records Example In this section, you will learn how to update records of the table using JDBC API. Update Records : Update record is most... for such situation you can use update statement to update particular value of record
update query
update query  using oops concept in php.. How to update the data from databse ? with program example
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
Update Record using Prepared Statement
JDBC: Update Record using Prepared Statement In this section, you will learn how to update row using Prepared Statements. Update Record  ... performance. So if you want to update many rows, you can use Prepared
Hibernate update Method
a simple example which will demonstrate you how an update method is used...Hibernate update Method In this tutorial you will learn about the update method in Hibernate Hibernate's update method saves the modified value
Statement Batch Update
Statement Batch Update       In this section we are going to learn about the batch update and how to use it. Here, we are providing an example with code to execute
JDBC: Batch Update Example
JDBC: Batch Update Example In this tutorial, you will learn how to do batch update of records using JDBC API. Batch Update : When you want to update... cause communication overhead. So to reduce time and cost, we use batch update
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
update database
update database  hi.. i want to know how the valuesof database can be updated in the jsf-jpa framework when the drop down button is clicked the data... that can be done there then by pressing the update buutton the value can be updated
Update value
Update value  How to update value of database using hibernate ?   Hi Samar, With the help of this code, you will see how can update database using hibernate. package net.roseindia.DAO; import
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... { fr.close(); sc.close(); } }} now i want to update the quantity
data update
://www.roseindia.net/jsp/crud-application.shtml Here, you will see that how you can edit/update data and saved them into that table again
Syntax error in my UPDATE..please advise
; stmt.executeUpdate(sql); Please advise how should I change my SQL to use Heidi MySQL...Syntax error in my UPDATE..please advise  Hi experts, I tested my... for the right syntax to use near 'where ID = 2' at line 1
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 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
Update a resultset programmatically
Update a resultset programmatically  How to update a resultset programmatically
PreparedStatement using batch update - Java Beginners
PreparedStatement using batch update  How to execute different preparedStatement object using batch update(Java) Pls explain with the code... + db, user, pass); pst = con.prepareStatement("update data set address
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 Profile
. In this section at first we see how the update form is developed after this we will discuss how to develop an action.   Developing an update form  ... Update Profile      
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 use mysql event scheduler in hibernate
how to use mysql event scheduler in hibernate  Hi all, I am creating...("); it gives native batch update Exception How can resolve this problem can... that when i update something it has to reflect in database after specific interval
JSP Servlet update patient data - JSP-Servlet
JSP Servlet update patient data  Hi Friend, I'm attaching my... patient_id='"+id+"' and dov='"+date+"'; if i use any other statement obviously... in the edit process using the one while (rs.next()){ loop. Can you show me how
update two frames at once
update two frames at once  How do I update two frames at once
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
frame update another frame.
frame update another frame.   How do I make a link or form in one frame update another frame
session update in php
session update in php  How to session update in php?   $this->session->set_userdata('name', $fullname
how to update table using inner joins
how to update table using inner joins  how to update table using inner joins
How to use spring validator with multiaction controller?
How to use spring validator with multiaction controller?  Hi, I am trying to use spring validator with multiaction controller. The configuration...- /**/configurationList.do=list /**/configurationUpdate.do=update
Foreign key update table
Foreign key update table  How to update table that has the foreign key in SQL..?   ALTER TABLE YourTable ADD CONSTRAINT FK_YourForeignKey... (YourPrimaryKeyColumn) ON UPDATE CASCADE
textfields and update - SQL
textfields and update  how can i retrieve a table from a database and put in on the textfields using jdbc?and at the same time update the items on the database
using case in update statement
using case in update statement  i want to use case in update clause... syntax is not working for update stmt.my problem is update emp set case deptno... working but for first condition only update emp set deptno=(case when 10 then 20
update statement in mysql
and use the update query to update the record. To update record, we write query ?UPDATE student SET fieldName=??? WHERE fieldName=?? . You can SET value...update statement in mysql  Update statement to update the existing
like query and then update or replace
like query and then update or replace   In postgres i use like query to find the a specific word in a column for example in a column i have text... to replace or update "wmost" to "westernmost" in that text. is there a way to do
textfields and update - SQL
textfields and update  how can i put retrieved table from a database to the textfields using jdbc?and at the same time update the items... basis u want to update database? can u clarify? Thanks Rajaniakant 
Auto field update
Auto field update  In my application I have a field called status which is having the 4 values like new,submitted,approved, rejected. How to set those filed in Database(MySQL), and how to auto update that field status in other
update a JTable - Java Beginners
update a JTable   i have tried your advice as how to update a JTable with mysql data through user interface but it is resulting some errors here is the code /* import java.sql.*; import javax.swing.*; import java.awt.
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
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
PHP MySQL Update
PHP MySQL Update       In SQL, Update is another statement which is used to update any record of a table. This command is useful when we need to update any existing value, which could
Difference between and merge and update in hibernate
Difference between and merge and update in hibernate  What is difference between and merge and update in hibernate?   Use update() if you are sure that the session does not contain an already persistent instance
update date from stored procedure
update date from stored procedure  how to works on insert,update data from stored procedure.   Insert data using stored procedure
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.*"%>

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.