Java开发常见错误
一、ShardingSphere数据库加密
公司在统一数据库加密字段,通过ShardingSphere的方案进行数据库加密改造,具体原理如下所示:
具体shardingsphere如上图所示,根据配置的脱敏规则,在执行insert、update的时候,将逻辑列和逻辑列的值,转换成密文列和密文值,进行存储。反之,在执行select语句的时候,则找到对应的密文列,将密文值解密赋值给逻辑列。这样就可以不改动上层应用程序的代码。
但是shardingsphere的加密方案,也有一些缺陷,有一些不支持的语法。
- 需自行处理数据库中原始的存量数据;
- 加密字段无法支持查询不区分大小写功能;
- 加密字段无法支持比较操作,如:大于、小于、ORDER BY、BETWEEN、LIKE 等;
- 加密字段无法支持计算操作,如:AVG、SUM 以及计算表达式;
- 多表关联时,只能识别主表的逻辑列,若加密字段不在主表,可以通过right join的方式调换位置;若连表查询的时候,有两个或两个以上的表存在逻辑列且需要查询出来,则要进行sql拆分才行。
二、mysql表插入失败
软件架构采用SpringBoot + MyBatis + Mysql的方式,insert 语句是自动生成的,PO也是通过数据库表自动解析的。
Error updating database. Cause: java.sql.SQLException: No value specified for parameter 1
The error may exist in file [E:\svn ideaproject\product\out\production\resources\mapper\order\base\CustomerVoucherBaseDao.xml]
The error may involve com.sdstc.order.dao.base.CustomerVoucherBaseDao.insert-Inline
The error occurred while setting parameters
SQL: insert into customer_voucher ( id,voucher_id,order_id,type,state,gmt_create,gmt_modified,create_account,modified_account,customer_id,is_delete,start_time,end_time,prod_promote_id,source ) values ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )
Cause: java.sql.SQLException: No value specified for parameter 1
; bad SQL grammar []; nested exception is java.sql.SQLException: No value specified for parameter 1
发现有几个字段,如source是mysql的关键字,所以猜测是这个问题,于是加上··即可正常运行。