Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners how to use update
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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



Advertisement
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 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 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?  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 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 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 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 table using inner joins
how to update table using inner joins  how to update table using inner joins
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
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 Servlet and Ajax?
How to use Servlet and Ajax?  How to use Servlet and Ajax
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 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 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 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 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.*"%>
how to use mouse pressed
how to use mouse pressed   to action mouse clicked
how to use button in array
how to use button in array  plz tell me how to code for button in array
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
Advertisements
 

 

 

DMCA.com