Java Spark JDBC SQLException
我不断得到SQLException,但我怀疑这不是问题所在。 表为:Java Spark JDBC SQLException,java,jdbc,apache-spark,Java,Jdbc,Apache Spark,我不断得到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 i
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);
火花代码:
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();
我尝试更改表stmt(@jmj):
然后它对一些查询起作用,但主要是给出:
Caused by: java.sql.SQLException: Out of range value for column 'age' : value age is not in Integer range
问题的根源在于使用TINYINT(4)来存储年龄 通过INTinseadTINYINT(4)更改类型 要了解原因,请检查此项 希望这有帮助
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