gpt4 book ai didi

java - Spark JDBC SQLException

转载 作者:行者123 更新时间:2023-11-30 03:04:52 26 4
gpt4 key购买 nike

我不断收到 SQLException,但我怀疑这不是问题所在。表是:

create table person (first varchar(30) DEFAULT NULL, last varchar(30)      DEFAULT NULL, gender char(1) DEFAULT NULL, age tinyint(4) DEFAULT NULL);

插入语句:

insert into person values('Barack','Obama','M',54);
insert into person values('Hillary','Clinton','f',34);

Spark 代码:

public static void main(String[] args) {
SparkConf conf = new SparkConf().setAppName("Stackoverflow")
.setMaster("local[4]");
JavaSparkContext sc = new JavaSparkContext(conf);
SQLContext sqlContext = new SQLContext(sc);
Map<String, String> options = new HashMap<>();
options.put("url", "jdbc:mariadb://localhost:3306/persondb");
options.put("user", "user");
options.put("password", "password333");
options.put("dbtable", "(select * from person where gender = 'M') as someone");

DataFrame jdbcDF = sqlContext.read().format("jdbc"). options(options).load();
jdbcDF.show();

错误:

Exception in thread "main" org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 0.0 failed 1 times, most recent failure: Lost task 0.0 in stage 0.0 (TID 0, localhost): java.sql.SQLException: Out of range value for column 'age' : value age is not in Integer range

我尝试更改表 stmt(@jmj):

create table person (first varchar(30) DEFAULT NULL, last varchar(30)      DEFAULT NULL, gender char(1) DEFAULT NULL, age int DEFAULT NULL);

然后它适用于一些查询,但大多数情况下它给出:

Caused by: java.sql.SQLException: Out of range value for column 'age' : value age is not in Integer range

最佳答案

问题的根源在于使用TINYINT(4)来存储年龄。

将类型更改为INT而不是TINYINT(4)

要了解为什么检查此 post .

希望这有帮助。

关于java - Spark JDBC SQLException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35041077/

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