• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to extract and print the contents of arraylist of java bean objects?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.util.ArrayList;
//import java.util.Iterator;

public class ClassDetails {
public ArrayList<MYBean> getDetails(String aa){

Connection conn = null;
ResultSet rst =null;
PreparedStatement preparedStatement = null;
ArrayList<MYBean> MYList = new ArrayList<MYBean>();
try {
final String CONNECTION_STRING = "";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

conn = DriverManager.getConnection(CONNECTION_STRING);
String strQuery = "SELECT * FROM XXX where xxx.yy = " +aa;
preparedStatement = conn.prepareStatement(strQuery);
rst = preparedStatement.executeQuery();

while (rst.next()) {
MYBean MyDetails = new MYBean();
MYList .add(MyDetails);
}
conn.close();
rst.close();
preparedStatement.close();
}
catch (ClassNotFoundException cnfex) {
cnfex.printStackTrace();
} catch (SQLException sqlex) {
sqlex.printStackTrace();
} catch (Exception excp) {
excp.printStackTrace();
}
return MYList ;
}
}


MYBean has about 6 fielda along with getter and setter methods.

MYlist is an array list of Mybean that has to be returned to another program.
How can I print the results that is returned by this program in another java program.
In other words how can i print the contents of this arraylist.

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
write it to some file using IO streams and second program can read the same
<Crude method but if you dont want to change system architecture its best way to do .>
Hope some1 will come up with better solution <may be using some design patterns (i haven't learned them yet )>
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

A title such as "please help urgent" is not helpful. What would happen if all posts had such a title?

Please go back and change your post to add a more meaningful subject by clicking the button on your post.

Also, please read this for more information on why using "urgent" will actually hurt your chances of getting quick answers.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

MYlist is an array list of Mybean that has to be returned to another program.


Could you describe the architecture of your app a little bit, that would help us answer this question. If I were doing this I would use either the messaging API or the web services API. But then I work primarily with Java EE apps.
 
Shree Chinnu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a web service. I have to send the array of java beans to the client and print the results.
 
today's feeble attempt to support the empire
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic