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!

JDBC is dead!

449334Sep 28 2005 — edited Oct 6 2005
Hi All,

just wanted to let you guys know if you don't already about the Spring Framework (www.springframework.org) you should check it out.

It provides alot of functionality for Java enterprise apps but the JDBC abstraction layer is unbelievable!! No more, messy boiler plate code, try/catch/finally blocks, memory leaks, etc.

Here are some examples of the sort of code you can write:

JdbcTemplate jt = new JdbcTemplate(datasource);

jt.execute("delete from mytable");
jt.execute("insert into mytable (id,name) values (1,'John')");

int count = jt.queryForInt("select count(*) from emp");

Object[] parameters = new Object[] {"Scott"};
int count = jt.queryForInt("select count(*) from emp where name = ?", parameters);

jt.execute("{call testpkg.someproc}");

You dont need to close jt or anything! Here's an actual method from my app:

public void updateStatusToNotified(String id, String resultLocation) {
jt = new JdbcTemplate(dataSource);
jt.update("call pkg_amlquery.p_setquerystatusasloc(?,?)",
new Object[] { resultLocation, id });
}


there's soo much functionality and many different ways to interact with the db its quite formidable but definatley worth the effort. There's a special class for calling stored procs too.

The creator (Rod Johnson) joked at a recent conference that if your developers are still using straight JDBC then they should be sacked!!! Tongue in cheek of course but when you see how easy it is to do db interactions with this framework, you'll never want to go back!!!

The url above is the best place for info including tutorials. If you have any questions I can try and help here but i have only been using it for a few months and am learning new things each day.

Take care

Rakesh
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 3 2005
Added on Sep 28 2005
3 comments
979 views