Solved

ResultSet persistence

Posted on 2002-03-29
4
450 Views
Last Modified: 2010-05-18
I need some way to maintain data from a ResultSet after closing the connection.  In other words, I want something that can get the data from the database, close the connection, then return the results.  If it helps, I'm using an Oracle 8 database.  Any suggestions?

//psuedocode
private ResultSet mymethod(String sql)
{
  Connection conn = getConnection();
  Statement stmt = conn.getStatement();
  ResultSet rs = stmt.execute(sql);
  conn.close();
  return rs;
}
0
Comment
Question by:rwinkler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 100 total points
ID: 6905456
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6905463
0
 

Expert Comment

by:rashidkamranbs
ID: 6905502
See the RsultSet object must be associated with a valid statement and of course connection object.. by closing connection mean you closed the resultset object..

Just Change Ur Function A little and using ResultSetMetaData before closing your connection put all the data in an sutiable Collection or Map object and return that ArrayList or whatever Collection object you choose .. this way ya would be having Results of Query but ofcourse.. not in the form of ResultSet but another COllection object

0
 
LVL 1

Author Comment

by:rwinkler
ID: 6905508
EXACTLY what I was looking for!  Thanks!

For archival purposes:

CachedRowSet crs = new CachedRowSet();

Listing 1: Explicit CachedRowSet initialization

<jsp:useBean id="Contacts"
             class="sun.jdbc.rowset.CachedRowSet"
             scope="session">
<%
  // load database driver
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  // initialize our CachedRowSet bean
  Contacts.setUsername("dbuser"); // example userid
  Contacts.setPassword("dbpassword"); // example password
  Contacts.setUrl("jdbc:odbc:ContactDB"); // example DSN
  Contacts.setCommand("SELECT name, telephone from Contacts");
  Contacts.execute();
%>
</jsp:useBean>


OR

<%
  // initialize our CachedRowSet bean using dataSourceName
  // property
  Contacts.setDataSourceName("Databases/ContactsDB/Datasource");
  Contacts.setCommand("SELECT name, telephone from Contacts");
  Contacts.execute();
%>

OR

<%
  // get connection from pool
  InitialContext ctx = new InitialContext();
  javax.sql.DataSource ds =
    (javax.sql.DataSource)ctx.lookup
    ("Databases/ContactsDB/DataSource");
  java.sql.Connection con = ds.getConnection();
  Contacts.setCommand("SELECT name, telephone from Contacts");
  // supply the connection to the RowSet
  Contacts.execute(con);
%>
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb on wildfly 5 64
web project error add remove 1 85
batch vs regular insert in spring DAO 2 52
Coding for the first time 9 103
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question