473,513 Members | 4,753 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with result set

4 New Member
Can anybody help me with this? I have bean which connects to a db and runs a queary, i am then trying to go through the result set and add each item returned to a array list, at the moment i can add items to a array list by hard coding them in but am having trouble doing it with a loop:
Expand|Select|Wrap|Line Numbers
  1. public List getVideo(String p1, String p2) {
  2.     ArrayList videos = new ArrayList();
  3.     videoBean v1 = new videoBean();
  4.     v1.setArtist("some artist"); // hard code the stuff here
  5. v1.setTitle("the title");
  6.     videos.add(v1);
  7.  
  8.     return videos;
  9.     }
Using this i method i can hard code data in and return it to where it was called but i want to do this in the while loop of:
Expand|Select|Wrap|Line Numbers
  1.             String selectSQL = "Select artist_name, title" + 
  2.             "from VideoTable" + "where category = " + CatPassed +" and price <= " + PricePassed +";";
  3.             Statement stmt0 = conn.createStatement();
  4.             ResultSet rs0 = stmt0.executeQuery(selectSQL); 
  5.  
  6. //List VideoList = new ArrayList(); // use this instead i think // works if i put it as list not array list
  7.             while(rs0.next()) {
  8.                 videoBean collection = new videoBean();
  9.                 collection.setArtist(rs0.getString("artist_name"));
  10.                 collection.setTitle(rs0.getString("title"));
  11.         System.out.println(collection.getArtist()); // testing in terminal  
  12.             }
  13.             stmt0.close();
Can anybody help me?
Apr 13 '07 #1
3 1500
r035198x
13,262 MVP
Can anybody help me with this? I have bean which connects to a db and runs a queary, i am then trying to go through the result set and add each item returned to a array list, at the moment i can add items to a array list by hard coding them in but am having trouble doing it with a loop:
Expand|Select|Wrap|Line Numbers
  1. public List getVideo(String p1, String p2) {
  2. ArrayList videos = new ArrayList();
  3. videoBean v1 = new videoBean();
  4. v1.setArtist("some artist"); // hard code the stuff here
  5. v1.setTitle("the title");
  6. videos.add(v1);
  7.  
  8. return videos;
  9.     }
Using this i method i can hard code data in and return it to where it was called but i want to do this in the while loop of:
Expand|Select|Wrap|Line Numbers
  1. String selectSQL = "Select artist_name, title" + 
  2. "from VideoTable" + "where category = " + CatPassed +" and price <= " + PricePassed +";";
  3. Statement stmt0 = conn.createStatement();
  4. ResultSet rs0 = stmt0.executeQuery(selectSQL); 
  5.  
  6. //List VideoList = new ArrayList(); // use this instead i think // works if i put it as list not array list
  7. while(rs0.next()) {
  8. videoBean collection = new videoBean();
  9. collection.setArtist(rs0.getString("artist_name"));
  10. collection.setTitle(rs0.getString("title"));
  11.         System.out.println(collection.getArtist()); // testing in terminal 
  12. }
  13. stmt0.close();
Can anybody help me?
I don't see how you are using the videoBean here.
Do you want to add videoBean objects to the arraylist? You can do so with
Expand|Select|Wrap|Line Numbers
  1.  ArrayList collection = new ArrayList(); 
  2. while(rs0.next()) {
  3.       videoBean video = new videoBean();
  4.       video.setArtist(rs0.getString("artist_name"));
  5.       video.setTitle(rs0.getString("title"));
  6.       collection.add(video);
  7. }   
  8.  
Apr 14 '07 #2
peterkay
4 New Member
Thanks i tried that but i just get a empty list returned, in the getvideo method what should i have in it now then?

Expand|Select|Wrap|Line Numbers
  1. public List getVideo(String p1, String p2) {
  2. ArrayList videos = new ArrayList();
  3. videoBean v1 = new videoBean();
  4. v1.setArtist("some artist"); // hard code the stuff here
  5. v1.setTitle("the title");
  6. videos.add(v1);
  7.  
  8. return videos;
  9.     }
I don't need any of the set bits in there but if i have a new array list i'm guessing thats why i get nothing returned.
Apr 14 '07 #3
r035198x
13,262 MVP
Thanks i tried that but i just get a empty list returned, in the getvideo method what should i have in it now then?

Expand|Select|Wrap|Line Numbers
  1. public List getVideo(String p1, String p2) {
  2. ArrayList videos = new ArrayList();
  3. videoBean v1 = new videoBean();
  4. v1.setArtist("some artist"); // hard code the stuff here
  5. v1.setTitle("the title");
  6. videos.add(v1);
  7.  
  8. return videos;
  9.     }
I don't need any of the set bits in there but if i have a new array list i'm guessing thats why i get nothing returned.
Have you stored anything in the database?
Apr 16 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
1848
by: Kurt A. Kaylor | last post by:
Hey, I am trying to get some code I have written to work. Runs well until I make a request. The I get some problems with PHP related to an SQL statement. Here are the errors :Warning:...
6
4305
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
5
2103
by: Jeff Greenberg | last post by:
Not an experienced c++ programmer here and I've gotten myself a bit stuck. I'm trying to implement a class lib and I've run into a sticky problem that I can't solve. I'd appreciate any help that I...
1
574
by: wukexin | last post by:
I write my own class Cfile, I want to know what about implement ctime().Who help me? My use function ctime, I sign it with $$$. my class Cfile: #------------------------ file.h...
2
4446
by: rufpirat | last post by:
Hello I'm in the middle of trying to build an "AD phone book", and this being my first try at asp.net, I have a few questions that I hope some of you might be able to help with: 1. Is it...
23
2758
by: casper christensen | last post by:
Hi I run a directory, where programs are listed based on the number of clicks they have recieved. The program with most clicks are placed on top and so on. Now I would like people to be apple to...
0
5520
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
2967
by: cherub | last post by:
I am not a programmer but i am trying to run the following script i thought i figured out with a book, but i am getting an error. Here is what i need it to do: From Outlook 03 Custom Contact Form...
3
2079
by: Dan | last post by:
I've been using optparse for a while, and I have an option with a number of sub-actions I want to describe in the help section: parser.add_option("-a", "--action", help=\ """Current supported...
16
2746
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.