MyBatis(三):数据库查询结果不为空,但是使用MyBatis框架查询为空问题

1、这个问题主要和返回字段是否和实体类javabean中的字段是否一致导致的问题。

解决方案:

sql语句  : select    account_id  as "accountId"  account_name as "accountName"  from account_t
数据库的字段  account_id    account_name
java的实体类:accountId   accountName

2、是否手动的修改了oracle数据库中的记录,默认查询时是走缓存的,如果手动修改数据库中的数据,很可能造成这种情况。

3、使用update/delete/insert语句时,必须使用事物commit。

jdbc api使用事物的方式:

try{
  //Assume a valid connection object conn
  conn.setAutoCommit(false);
  Statement stmt = conn.createStatement();
   
  String SQL = "INSERT INTO Employees " +
        "VALUES (106, 20, 'Rita', 'Tez')";
  stmt.executeUpdate(SQL); 
  //Submit a malformed SQL statement that breaks
  String SQL = "INSERTED IN Employees " +
        "VALUES (107, 22, 'Sita', 'Singh')";
  stmt.executeUpdate(SQL);
  // If there is no error.
  conn.commit();
}catch(SQLException se){
  // If there is any error.
  conn.rollback();
}
原文地址:https://www.cnblogs.com/yy3b2007com/p/6761715.html