exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'serverid' cannot be null

本文介绍了一个在Presto中使用SQL时遇到的问题:当使用union all操作时出现的列serverid不能为null的错误。通过分析发现,问题出现在多个子查询未正确封装。最终解决方案是在每个子查询外部添加括号。

前文:

第一次使用presto,之前一直用的impala。两个的sql语法还是有一些不同的。之前的一个sql在impala计算是没有问题的,但是同样的sql在presto里跑,老报jdbc4.MySQLIntegrityConstraintViolationException: Column 'serverid' cannot be null。但是serverid不是空的。

分析:

1,发现跑多个sql时,只有这一个sql报这个错,其他sql一切正常

2,发现这个sql与其他sql不同的地方在于:这个sql是多个sql union all在一起的。

解决:

每个sql开头结尾加上括号之后再 union all在一起计算,就不报错了。

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. Exception in thread "main" org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [insert into user values(null, ?, ?)]; Column 'uid' cannot be null; nested exception is java.sql.SQLIntegrityConstraintViolationException: Column 'uid' cannot be null at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:87) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1443) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:633) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:862) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:917) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:927) at dao.TestDaoImpl.update(TestDaoImpl.java:20) at service.TestServiceImpl.testJDBC(TestServiceImpl.java:24) at config.TestJDBC.main(TestJDBC.java:14) Caused by: java.sql.SQLIntegrityConstraintViolationException: Column 'uid' cannot be null at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:118) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:916) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1061) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1009) at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1320) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:994) at org.springframework.jdbc.core.JdbcTemplate.lambda$update$0(JdbcTemplate.java:867) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617) ... 6 more jdbc.driverClassName=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/springtest?characterEncoding=utf8 jdbc.username=root jdbc.password=111111
最新发布
10-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值