Is java – spring too complex for JDBC operations?

I've just seen spring's JDBC framework - it looks like a learning curve - and I still can't find the latest quick start spring / JDBC tutorial of any quality!

Is there anything lighter than spring for basic JDBC operations - or does anyone have a good tutorial link

Thank you.

Solution

On the contrary JDBC support in spring is very simple Here is a basic example:

dataSource = ... obtain data source... (e.g. via Spring config)
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
Map<String,Object> row = jdbcTemplate.queryForMap(
        "SELECT * FROM MyTable WHERE ID=? LIMIT 1",100);

Jdbctemplate and simplejdbctemplate have many query methods that you may find useful To map rows to objects, see rowmapper and parameterizedrowmapper < T > For your data source, you usually want to use some advanced datasource with pool support For testing, the simple basicdatasource will perform:

BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("driverClassName");
ds.setUrl("jdbc://...");
ds.setUsername("username");
ds.setPassword("password");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>