It may be that I'm still so new to Java that I don't know a good way around this, or it may be that I'm so used to the convenience of Coldfusion that I build tools in Java to help it act more like Coldfusion, but I was having some trouble with
MVC in Java. I didn't see why something in my View layer should be importing anything from the package java.sql, such as
ResultSet.
Moreover, I wanted to open and close my
Connection to the database (and the
Statement/
PreparedStatement in the Model layer, and doing so would have prevented the
ResultSet from being available to the View.
Enter
QueryResult.
QueryResult simply takes as a parameter a
ResultSet and creates a
HashMap where each key is a column name, and accessing it gives you an array of the rows' values for that column.
Thus you can get the fifth row of the column
email by doing this:
QueryResult qr = new QueryResult(someResultSet);
String emailInRow4 = (String) qr.get("email")[4];
It's not the greatest thing in the world, but it works better than the alternative. I plan to put the code up here for it later, so maybe it could help someone else as well.
Hey! Why don't you make your life easier and subscribe to the full post
or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate
wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!
Leave a comment
There are no comments for this entry yet.
Leave a comment