Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training Big Data and Hadoop Training Java Training  
 

how to use update

Ads

 
 

Share on Google+Share on Google+

Ragini Shukla
how to use update
3 Answer(s)      8 years ago
Posted in : Java Beginners
Ads
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:

<[email protected] language="java"%>
<[email protected] 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:

<[email protected] 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

Ads









Related Tutorials/Questions & Answers:
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
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
Advertisements
how to update
how to update   conditional update
how to update image in php
how to update image in php  how to update image in php
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... { fr.close(); sc.close(); } }} now i want to update the quantity
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 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
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 use Servlet and Ajax?
How to use Servlet and Ajax?  How to use Servlet and Ajax
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 use calender in php
how to use calender in php  how to put calender in php
How to use AT Commands with J2ME?
How to use AT Commands with J2ME?  How to use AT Commands with J2ME? Thank you for your answer
how to use mouse pressed
how to use mouse pressed   to action mouse clicked
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
how to use button in array
how to use button in array  plz tell me how to code for button in array
How to Use Collections
How to Use Collections  how to use ArrayList and HashMaps in case of user defined class  Hi Friend, Please visit the following links: http://www.roseindia.net/java/jdk6/ http://www.roseindia.net/javacodeexamples
how to use setAttribute
how to use setAttribute  how to get following codes using setAttributes in java??? Employee xlink:type="extended" xlink:show="new" xlink:actuate="onRequest
How to use dojoscript with jsf?
How to use dojoscript with jsf?  Hi all , am new to jsf. can anyone help me out in using dojo script frame work with jsf. how to integrate dojo into jsf. Thanks in advance
how to use JOptionPane.YES_NO_OPTION
how to use JOptionPane.YES_NO_OPTION  As i said earliar i am making... logging out finally.. i also thinking how to use the input (yes or no ) given... dialog should appear which ask for yes or no . PROBLEM is i dont know how
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 an editable combobox
how to use an editable combobox   Hello Everyone!!!!!!!! I have a jcombo box with certain values and i want to use it as an editable that means when user will type something in combobox, according to that text only matching item