在同一个事物中,更新后(事务未提交)再查询也是可以查询到更新后的数据,所以你的这个过程是可以的,是有数据库保证的。
举个例子吧:
package com.lz.dao.base;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Test {
public static void main(String[] args){
execute();
}
/**
* 使用的数据库为mysql,数据库默认隔离级别为:repeatable
* 下面的代码只为演示用
*/
public static void execute(){
Connection con = null;
try{
con = DbUtils.getConnection();
con.setAutoCommit(false);
String updateSql = "update lz_nav_category set name = 'google' where id = 55";//更新分类名称
PreparedStatement ps = con.prepareStatement(updateSql);
ps.executeUpdate();
String querySql = "