Spring NamedParameterJdbcTemplate返回oracle db的空列表

时间:2017-12-26 19:59:04

标签: java spring oracle jdbc

我有这样的问题:

  

“ORA-12705:无法访问NLS数据文件或无效环境”

之前。 在阅读了这个问题的不同解决方案后,我添加了字符串

Locale.setDefault(Locale.ENGLISH);

到我的DAO类方法

但现在它返回空列表。 道类代码:

   public class StudentsDao {
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Autowired
    public StudentsDao(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
        this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
    }

    private static final String SELECT_ALL_STUDENTS = "SELECT Student_id, Name, Address, Info FROM Students_6_1";

    public List<Student> getAllStudents(){
        Locale.setDefault(Locale.ENGLISH);
        Object res = namedParameterJdbcTemplate.query(SELECT_ALL_STUDENTS, new RowMapper<Student>() {
            public Student mapRow(ResultSet resultSet, int i) throws SQLException {
                int studentId = resultSet.getInt("Student_id ");
                String studentName = resultSet.getString("Name");
                String studentAddress= resultSet.getString("Address");
                String studentInfo= resultSet.getString("Info");
                return new Student(studentId, studentName, studentAddress, studentInfo);
            }
        });
        return (List<Student>) res;
    }        
}

P.S。在oracle命令行查询中运行良好。

0 个答案:

没有答案