Guice and JDBC #2

4 11 2011

So a little while ago, I wrote about jdbc and guice.. I’ve been using mybatis since then.. And it just came to me yesterday “with mybatis you can do simple jdbc with guice”. Something similar to Spring JDBC templates.

So heres how (integer select), using annotation approach in something called a mapper class.

@Select(value = "select ${sql}")
public Integer updateCustomerEntrance(@Param("sql") String sql);

Thats it the only stuff you need to ensure are that your select will return an integer, and thats it. Mybatis will manage connection pool, connection etc for you.

It’s probably also possible for you to just return a object.. you’ll need at least 3 methods one for each type of sql, select update and delete.

However this approach are not at all utilizing mybatis’s power and are prone to SQL injection.. But it will do the job, and you can then go ahead an convert your legacy code slowly to use mybatis’s full potential.

Heres howto setup guice using it:




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: