能select出数据来,但是update、insert语句都无法起作用,也不报错。
比如以下代码,
中间执行了一个更新操作,但前后打印内容是一模一样的:
public static void main(String[] args) {
SQLiteDataSource source = new SQLiteDataSource();
source.setUrl("jdbc:sqlite::resource:tester.db");
JdbcTemplate jdbcTemplate = new JdbcTemplate(source);
//查询
System.out.println(jdbcTemplate.queryForList("select * from module"));// 打印:[{mid=1, name=模块1}, {mid=2, name=模块2}]
//更新
jdbcTemplate.update(" update module set name = 'aaa' where mid = 1 ");
//再次查询
System.out.println(jdbcTemplate.queryForList("select * from module"));// 打印:[{mid=1, name=模块1}, {mid=2, name=模块2}]
}
请指点迷津,谢谢!
试了下可以执行
[{mid=1, name=模块1}, {mid=2, name=模块2}]
18:52:19.713 [main] DEBUG org.springframework.jdbc.core.JdbcTemplate - Executing SQL update [ update module set name = 'aaa' where mid = 1 ]
18:52:19.715 [main] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
18:52:19.724 [main] DEBUG org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
18:52:19.724 [main] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
18:52:19.724 [main] DEBUG org.springframework.jdbc.core.JdbcTemplate - Executing SQL query [select * from module]
18:52:19.724 [main] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
18:52:19.725 [main] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
[{mid=1, name=aaa}, {mid=2, name=模块2}]