Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Use Grails for database-related code in stand alone application?

843859Jul 22 2009 — edited Nov 20 2014
I have a Java application that uses MySQL through JDBC.

Currently I have one DbFooHandler class for each table Foo and I collect all sql code related to the Foo table in this class.

It works quite well and I get the interface I want. The drawback is the ammount of boiler-plate code. I have a bunch of methods that looks roughly like this:
    public int getUserPostCount(int accId) {
        String sql =
            "SELECT COUNT(*) AS postCount " +
            "FROM ForumPosts " +
            "WHERE accId = ?";
        
        try {
            PreparedStatement ps = db.prepare(sql, accId);
            ResultSet rs = ps.executeQuery();
            rs.first();
            int postCount = rs.getInt("postCount");
            ps.close();
            return postCount;
        } catch (SQLException sqle) {
            throw new RuntimeException(sqle);
        }
    }
I've now looked at Grails and that kind of code is just beautiful.

My question is: Can/should grails be used for database-parts in a generic java-application?

(I have tried Cayenne and looked at Hibernate but those frameworks doesn't work well with my class-hierarchy.)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 20 2009
Added on Jul 22 2009
9 comments
91 views