Yes - they still use the RowMapper though and they could have avoided the queryForInt, queryForLong etc.
And wiring / configuration is probably a bit complex - compared to this: http://code.google.com/p/chalkmine/wiki/ExampleOne Anyway - I see where you are getting. On Feb 23, 2:24 am, Keith Haber <[email protected]> wrote: > Another +1 for Spring JDBC here too. > > The SimpleJdbcTemplate class makes use of Java 5 varargs and template > features in much the way you describe. The parts of Spring JDBC that > make use of Java 5 features are in the package > org.springframework.jdbc.core.simple. > > http://static.springframework.org/spring/docs/2.5.x/api/org/springfra... > > Keith > > On Feb 22, 1:11 pm, Christian Hvid <[email protected]> wrote: > > > I have worked with Hibernate but I think that is different approach > > altogether. > > > I haven't looked at Spring JDBC but I can see that they are similar in > > many ways (by looking at the documentation): > > > This > > (fromhttp://static.springframework.org/spring/docs/2.0.x/reference/jdbc.ht... > > > int rowCount = this.jdbcTemplate.queryForInt("select count(0) from > > t_accrual"); > > String surname = (String) this.jdbcTemplate.queryForObject("select > > surname from t_actor where id = ?", new Object[]{new Long(1212)}, > > String.class); > > > Would be identical to: > > > int rowCount = queryScalar(Integer.class, "select count(0) from > > t_accrual"); > > String surname = queryScalar(String.class, "select surname from > > t_actor where id = ?", 1212); > > > And it is really the same except I use some Java 5 features (static > > imports, generics, varags, boxing) and have the reference to > > "this.jdbcTemplate" hidden away in a ThreadLocal object. > > > However this: > > > Actor actor = (Actor) this.jdbcTemplate.queryForObject( > > "select first_name, surname from t_actor where id = ?", > > new Object[]{new Long(1212)}, > > new RowMapper() { > > public Object mapRow(ResultSet rs, int rowNum) throws > > SQLException { > > Actor actor = new Actor(); > > actor.setFirstName(rs.getString("first_name")); > > actor.setSurname(rs.getString("surname")); > > return actor; > > } > > }); > > > Would be written as: > > > Actor actor = queryScalar(Actor.class, "select first_name, surname > > from t_actor where id = ?", 1212); > > > And would require that Actor had a public constructor matching the > > types of first_name and surname (String, String). > > > And I think that is taking a different route ... maybe (?) > > > On Feb 22, 6:42 pm, Rakesh <[email protected]> wrote: > > > > have you looked at Spring JDBC? It has a similar interface and manages > > > the connections for you. > > > > I think if you go down a non-orm route and want to have lots of sql, > > > Ibatis is quite common - not used it so can't say for sure. > > > > Spring JDBC though is very nice and have used it extensively. > > > > Rakesh > > > > On Sun, Feb 22, 2009 at 2:21 PM, Christian Hvid > > > > <[email protected]> wrote: > > > > > Hi Java people. > > > > > I have been toying with simplier ways of doing embedded SQL in Java. > > > > > And would like your comments on this one? > > > > >http://code.google.com/p/chalkmine/ > > > > > It allows you to write code like this: > > > > > openConnection(); > > > > try { > > > > int count = queryScalar(Integer.class, "select count(*) from > > > > people"); > > > > System.out.println("There are "+count+" people in the bin."); > > > > } finally { > > > > closeConnection(); > > > > } > > > > > or > > > > > openConnection(); > > > > try { > > > > List<Person> people = queryList(Person.class, "select name, > > > > time_in_the_bin from people"); > > > > for (Person p : people) > > > > System.out.println(p.getName()+" has been "+p.getTimeInTheBin() > > > > +" hours in the bin."); > > > > } finally { > > > > closeConnection(); > > > > } > > > > > (Provided that Person has a constructor matching the types of name, > > > > time_in_the_bin. Probably Person(String, int).) > > > > > Where the methods openConnection, queryScalar, queryList, > > > > closeConnection are statically imported. > > > > > openConnection() figures out the name of the calling class, looks up a > > > > configuration, opens a connection and puts in a ThreadLocal container. > > > > > queryScalar(Class, String, ...) performs a query with a single row > > > > result that is "cast" to the given class. > > > > > queryList(Class, String, ...) performs a query and returns the result > > > > as a list of the given class. > > > > > I would like to turn it into a full-fledged open source project. > > > > > But since it is incredibly hard for a new open source project to gain > > > > traction I would like to figure out whether it is interesting enough > > > > first. > > > > > -- Christian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaposse?hl=en -~----------~----~----~----~------~----~------~--~---
