aspose file tools*
The moose likes JDBC and the fly likes How to extract and print the contents of arraylist of java bean objects? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to extract and print the contents of arraylist of java bean objects?" Watch "How to extract and print the contents of arraylist of java bean objects?" New topic
Author

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

Shree Chinnu
Greenhorn

Joined: Jan 16, 2010
Posts: 7
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.

vicky ma
Ranch Hand

Joined: May 13, 2009
Posts: 38
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 )>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5827
    
    7

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.


JBoss In Action
Shree Chinnu
Greenhorn

Joined: Jan 16, 2010
Posts: 7
This is a web service. I have to send the array of java beans to the client and print the results.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to extract and print the contents of arraylist of java bean objects?