resultset problem

resultset problem

hi
I have one problem with resultset?
ResultSet rs=st.execute("select subjname,staffname from staffdetails");
while(rs.next())
{
st.executeUpdate("update CSEFIRSTYEARTIMETABLE set p2='"+rs.getString(1)+"',p3='"+rs.getString(1)+"',p4='"+rs.getString(1)+"' where dayperiod='2'");

}

the above update query is executed once not repeatedly error is
java.sql.SQLException: Operation not allowed after ResultSet closed
how to repeat the update query upto the wile condition is true?

pls send me answer?
View Answers

June 22, 2010 at 12:02 PM

Hi Friend,

We are providing you a sample code. It will be helpful for you.

import java.sql.*;
class Select{
public static void main(String[] args){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/register";, "root", "root");
Statement st=connection.createStatement();
Statement st1=connection.createStatement();
ResultSet rs=st.executeQuery("select * from data");
int i=1;
while(rs.next()){
System.out.println(rs.getString(2)+" "+rs.getString(3));
st1.executeUpdate("update person set name='"+rs.getString(2)+"',address='"+rs.getString(3)+"' where id='"+i+"'");
i++;
}
}
catch(Exception e){}
}
}

Thanks









Related Tutorials/Questions & Answers:
resultset problem - JSP-Servlet
resultset problem  hi I have one problem with resultset? ResultSet rs=st.execute("select subjname,staffname from staffdetails"); while... is java.sql.SQLException: Operation not allowed after ResultSet closed how
ResultSet
ResultSet   What is a ResultSet
Advertisements
ResultSet
ResultSet  What is a ResultSet
Problem displaying resultset in jsp(no frameworks used) - JSP-Servlet
Problem displaying resultset in jsp(no frameworks used)  Problem... if the resultset return 25 rows, these 25 records are to be displayed in my jsp. My problem... resultset values to a bean 2)the respective bean instances are added
ResultSet
ResultSet  I want to retrieve data of unknown datatype from database.how to do it using resultset or Resultsetmetadata.Can you please tell me what... = con.createStatement(); ResultSet rs = st.executeQuery
multiple resultset in one resultset
multiple resultset in one resultset  how to retrive multiple resultsets in one resultset in java.? plz help
resultset metadta
resultset metadta  import java.sql.Connection; import... Employee Details Using resultset metadata: "); Connection con = null...(); ResultSet rs = st.executeQuery("SELECT * FROM employee
The cursor in scrollable resultset
The cursor in scrollable resultset   How to move the cursor in scrollable resultset
Update a resultset programmatically
Update a resultset programmatically  How to update a resultset programmatically
Resultset with one to many relationship
Resultset with one to many relationship   Suppose there are 5 tables... populate my bean classes from resultset without using hibernate, so... solution to this problem
Resultset - JSP-Servlet
Resultset  I am writing while(rs.next){} but if resultset is null then it cannot enter in while block. I want,if resultset is null then it will enter into the while block.  Hi friend, A ResultSet object
SQL exception, Exhausted ResultSet
SQL exception, Exhausted ResultSet  javax.servlet.ServletException: java.sql.SQLException: Exhausted Resultset iam getting this error messege whenever i run my code. what would be the possible reasons
JTable populate with resultset.
JTable populate with resultset.  How to diplay data of resultset...) JTable(Vector data, Vector columneNames) Here is a JTable populate with resultset...(); ResultSet resultSet = statement.executeQuery(sql
Resultset Issue in SQL
Resultset Issue in SQL  when i call rs.next() in my code it is returning false, though im having valid query to execute and fetch a row from database.how can i resolve this issue. My code is: SELECT JOBDESCRIPTION,CATEGORY
JSP - Resultset - JSP-Servlet
JSP - Resultset  hello sir, how can i count record in jsp. i use resultset in my jsp so in my login form how can i check the username and password is correct or not...?? please reply it's urgent.. thanks
large resultset values - SQL
large resultset values  i have one query which will bring more than one lakh records from database(total records are abt 3 crores). While getting the details i'm getting error like
receive a ResultSet from a stored procedure
receive a ResultSet from a stored procedure  How do I receive a ResultSet from a stored procedure
ResultSet In Java
ResultSet In Java In this section we will learn about the ResultSet in Java... that are mostly used in to get the value. ResultSet contains the data of a table after executing the SQL queries. Object of ResultSet also maintains the current position
ResultSet object initialization - Java Beginners
ResultSet object initialization  How to initialize resultset object  Hi friend, public interface ResultSet A ResultSet object maintains a cursor pointing to its current row of data. A default ResultSet object
JDBC ResultSet last() Example
JDBC ResultSet last() Example: The ResultSet last() are use to moves the cursor to the last row in the ResultSet object. It return true if the cursor pointed last row in the ResultSet and return false if the ResultSet object does
JDBC ResultSet first() Example
JDBC ResultSet first() Example: The ResultSet first() are use to moves the cursor to the first row in the ResultSet object. It return true if the cursor pointed first row in the ResultSet and return false if the ResultSet object does
Printing Values of Resultset to Html Table
Printing Values of Resultset to Html Table  I have a resultset and I need to collect the resultset values into the arraylist into a table... in advance   JSP Display values of ResultSet to HTML table: <%@page
Getting ResultSet size - JSP-Servlet
Getting ResultSet size  Hello friends, what is the result getFetchSize() of resultset. I got error with this method. While rs contains... the driver. It has absolutely no effect on the number of rows in a ResultSet. The driver
Closing Statement and ResultSet Objects - Development process
Closing Statement and ResultSet Objects  I Friend. i am getting the closing the objects problem. i am using the business logic in jsp now.it is having the two or more statements objects and results set objects ,how
Spring JdbcTemplate and ResultSet is too slow..
Spring JdbcTemplate and ResultSet is too slow..  Hi.. I am using spring jdbctemplate to fetch the records from oracle database. But it is taking too long time to execute a simple select query. The query which is having 400
Moving Cursor within ResultSet
; } Moving Cursor Within ResultSet There are many methods are given to move... = null; // Statement reference variable for query // Execution ResultSet resultSet = null; // ResultSet reference variable for saving query // result
JDBC Updateable ResultSet Example
; } Updateable ResultSet Example You can update the database table using result set. To update the table using result set you need to set the ResultSet... illustrate how to update table through resultset. UpdateableResultSet.javaADS
ResultSet Object data to Ms-Word Doc
ResultSet Object data to Ms-Word Doc   help me , i don't know how to write data from oracle database into MSWord document using servlet or jsp
JDBC ResultSet Example
; } JDBC ResultSet Example JDBC ResultSet is an interface of java.sql package... is obtained by executing the execute method of statement. A ResultSet object points...;The default ResultSet object is not updateable therefore the cursor moves only forward
problem in onlinetest...
problem in onlinetest...  hi, my code getting the problem is ,when user leave a question then the server puts error... pls help me
JDBC ResultSet Example
JDBC ResultSet Example: In this example, we are discuss about ResultSet class...) database query results. Through this example you can see how to use ResultSet... statement object and store the result in the resultset object 
solve this problem
in table please tell me the solution for thid problem import java.io.*; import...; ResultSet rs; try{ Class.forName("org.gjt.mm.mysql.Driver...://localhost/test?user=root&password=root"; Connection conn; ResultSet rs; try
JDBC ResultSet beforeFirst() Example
JDBC ResultSet beforeFirst() Example: This ResultSet method set cursor... the cursor is before the first row in this ResultSet object. Syntax: ResultSet rs.... In this example, the beforeFirst() point the 0 position in the resultset object
uploading problem
(); ResultSet rs=st.executeQuery("select count(*) from...(); } } } } %> my problem...: firstly.... then problem solved... bt real problem is when i upload files fusing mozilla
Servlet problem
problem from last three month and now i hope rose india developers... connectivity code it works but problem is with servlet page. My servlet code... = con.createStatement(); ResultSet rs = null; String sql
JDBC ResultSet afterLast() Example
JDBC ResultSet afterLast() Example: This ResultSet method set cursor...() moves the cursor to the end of this ResultSet object, just after the last row...: ResultSet rs; void rs.afterLast(); Now we will create example using this method
JDBC ResultSet Delete Row Example
JDBC ResultSet Delete Row Example: Learn how to delete row using ResultSet. We are also used ResultSet object with update capability for delete rows from... executeQuery() method on the created statement object to return ResultSet
Find Default ResultSet Type Example
Find Default ResultSet Type Example: We are discuss about to find out Default ResultSet type. There are many operations depends on the ResultSet support Type so you can find out the default ResultSet type using this example. We
JDBC ResultSet next() Example
JDBC ResultSet next() Example: In this example, we are discuss about resultset... is positioned after the last row. Syntax: ResultSet rs; Boolean rs.next...: package ResultSet; import java.sql.Connection; import 
java.sql.SQLException: Operation not allowed after ResultSet closed
java.sql.SQLException: Operation not allowed after ResultSet closed  package processing; import java.io.; import java.math.BigDecimal; import...(); ResultSet rs = st.executeQuery("Select * from asteriskcdrdb.sp1 where
problem in validation
problem in validation  sir/madam, i m using struts-1.3.10. i m getting a problem my properties file is not found.... while i hav configuired it in struts-config.xml file, likeADS_TO_REPLACE_1 thanks n regards himanshu
javascript problem
javascript problem  hi guys My problem is that I am using radio button for yes or no but i want to do that if I press yes button then enter... enter please help me this problem
jsp problem
jsp problem  problem:::::::: On JSP form ,when i insert data in text field........at that time action is perform and data is retriev from data base..."); Statement st=con.createStatement(); ResultSet rs=st.executeQuery
problem on strings
problem on strings  in string1 "123456 ABC DEF...",IN string2 "raveen". iwant to add string2 after 123456 in the first string based on index number.i need logic for this with out using StringBuffer concept. Thanks in advanace
Problem with loginbean.jsp
Problem with loginbean.jsp  http://www.roseindia.net/jsp/loginbean.shtml - I am getting an error in loginbean.jsp.There is some error regarding .What is hello in this? Also in this example how
problem of confirmation
problem of confirmation  sir, I tried ur code but when i click on cancel it still submits I dont need to pass id as record is already diaplayed...(); ResultSet rs2
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
Problem with cookies
Problem with cookies  Hello All, i need jsp code for RememberMe module of login. i am facing problem with cookies. so please if any one could guide me please help and provide mme the exact code.   Please visit
problem with package
problem with package  Dear sir, i have created one java file with package com.net; and i compiled the program.it showing the .class file in " net" folder.The problem is i want to use that .class file in some other

Ads