• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get data from a database  RSS feed

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a bad hair day or something, if some one can give me some clue,

I have servlet that is initiated at start up

I query the database and get a record set let say 500 rows 30 columns ID, Name, Number etc...

1. how do I get the column name let say getColumnName("ID"), getColumnName("Name"), etc.. I iterating through the record set..


2. I want to eventually write these to a file pipe delimeted to ftp to another app.
a. - Would it be OK to write directly print.out(getColumnName("ID"), getColumnName("Name"), etc.. )?
b. - Or should I look at storing the records in a vector and then writing the data?

3. Later on I get a response from the app I sent the file to to tell me if the records were successful or fail and then I update the status of the record in the database.

If some one can give me an idea what the best apprach to this is I will love you forever.

Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should work according to the Model-View-Controller design pattern. In short, the MVC contains :
- model : the JavaBeans correspond to the concepts of the user of the web application, like Client, Product, Order, Delivery, Invoice
- view : the Java Server Pages take care of the presentation layer
- controller :the servlet(s) take(s) care of the application flow.

And besides these kinds of objects, you have the DAO's or Data Access Objects. These are the objects who make connection with the database and put the resultset in a JavaBean. I'll give an example :

public ArrayList findMeterrondes()
throws SQLException
StringBuffer zoekString = new StringBuffer();
zoekString.append("select * from mlzro");
Connection con = getConnection();
PreparedStatement ps = con.prepareStatement(zoekString.toString());
ResultSet rs = ps.executeQuery();
if (rs == null)
return null;
else {
ArrayList rondeLijst = new ArrayList();
Calendar vandaag = Calendar.getInstance();
int jaar = vandaag.get(Calendar.YEAR);
int maand = vandaag.get(Calendar.MONTH);
int dag = vandaag.get(Calendar.DAY_OF_MONTH);
int datumAS = (jaar * 10000) + ((maand * 100) + 1) + dag;
while (rs.next() )
Meterronde meterronde = new Meterronde(rs);
findPlanningsAantallen(meterronde, datumAS);
return rondeLijst;
} /* rs != null */

} // end findMeterrondes
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!