gpt4 book ai didi

java - Hive jdbc.query(sql, rowmapper) 抛出 UnCatogarized 异常

转载 作者:可可西里 更新时间:2023-11-01 16:52:55 26 4
gpt4 key购买 nike

我正在使用 spring-jdbc 模板 来查询 Hive-0.11.0以下代码效果很好。

public List<Student> listStudents() {
String SQL = "select * from Student";
List <Student> students = jdbcTemplateObject.query(SQL,
new StudentMapper());
return students;
}
public class StudentMapper implements RowMapper<Student> {
public Student mapRow(ResultSet rs, int rowNum) throws SQLException {
Student student = new Student();
student.setId(rs.getInt("id"));
student.setName(rs.getString("name"));
student.setAge(rs.getInt("age"));
return student;
}
}

升级到 Hive-0.14.x,一切保持不变。但是程序没有运行。抛出以下异常:

org.springframework.jdbc.UncategorizedSQLException: StatementCallback; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; null; nested exception is java.sql.SQLException
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:413)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:468)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:478)
Caused by: java.sql.SQLException
org.apache.hive.jdbc.HiveBaseResultSet.findColumn(HiveBaseResultSet.java:93)
at org.apache.hive.jdbc.HiveBaseResultSet.getString(HiveBaseResultSet.java:609)
at org.clinical3PO.model.StudentMapper.mapRow(StudentMapper.java:15)
at org.clinical3PO.model.StudentMapper.mapRow(StudentMapper.java:8)
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:93)
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60)
at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:457)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:402)
... 5 more

从 Hive-0.11.0 到 Hive-0.14.x 是否有代码更改?

最佳答案

Hive 0.14.0 按原样返回查询的列名。深入研究:考虑 2 个表 abcxyz。查询是:- SELECT abc.id, xyz.age, abc.name from db.abc JOIN ON db.xyz WHERE abc.id=xyz.id;

Hive-0.11.0 的结果集:

student.setId(rs.getInt("id"));
student.setName(rs.getString("name"));
student.setAge(rs.getInt("age"));

Hive-0.14.0 的结果集:

student.setId(rs.getInt("abc.id"));
student.setName(rs.getString("abc.name"));
student.setAge(rs.getInt("xyz.age"));

这就是它对我有用的方式。

关于java - Hive jdbc.query(sql, rowmapper) 抛出 UnCatogarized 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31286128/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com