apache phoenix插入中文字符

最近在研究phoenix,在进行对中文处理时出现以下异常,
Exception in thread "main" java.sql.SQLException: ERROR 201 (22000): Illegal data.
	at org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:309)
	at org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:133)
	at org.apache.phoenix.expression.LiteralExpression.newConstant(LiteralExpression.java:178)
	at org.apache.phoenix.expression.ComparisonExpression.create(ComparisonExpression.java:168)
	at org.apache.phoenix.compile.ExpressionCompiler.visitLeave(ExpressionCompiler.java:191)
	at org.apache.phoenix.compile.ExpressionCompiler.visitLeave(ExpressionCompiler.java:106)
	at org.apache.phoenix.parse.ComparisonParseNode.accept(ComparisonParseNode.java:45)
	at org.apache.phoenix.compile.WhereCompiler.compile(WhereCompiler.java:92)
	at org.apache.phoenix.compile.QueryCompiler.compileSingleQuery(QueryCompiler.java:260)
	at org.apache.phoenix.compile.QueryCompiler.compile(QueryCompiler.java:128)
	at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:264)
	at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:253)
	at org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:199)
	at org.apache.phoenix.jdbc.PhoenixPreparedStatement.executeQuery(PhoenixPreparedStatement.java:157)
	at com.zte.esb.nosql.dao.hbase.HBaseDaoImpl.executeQuery(HBaseDaoImpl.java:43)
	at com.zte.esb.nosql.test.Test_Phoenix.main(Test_Phoenix.java:29)
Caused by: org.apache.phoenix.schema.IllegalDataException: CHAR types may only contain single byte characters (中)
	at <span style="color:#ff0000;">org.apache.phoenix.schema.PDataType$2.toBytes(PDataType.java:204)</span>
	at org.apache.phoenix.schema.PDataType.toBytes(PDataType.java:6748)
	at org.apache.phoenix.expression.LiteralExpression.newConstant(LiteralExpression.java:160)
	... 13 more
查看抛出异常源码位置
@Override
        public byte[] toBytes(Object object) {
            if (object == null) {
                throw new ConstraintViolationException(this + " may not be null");
            }
            byte[] b = VARCHAR.toBytes(object);
            if (b.length != ((String) object).length()) {//当看到这,有点蒙了,中文获取的字节长度怎么才能等于本身leng?
                throw new IllegalDataException("CHAR types may only contain single byte characters (" + object + ")");
            }
            return b;
        }
<pre name="code" class="java">后来想到表字段类型是char类型,此处是VARCHAR.toBytes(object),然后就把表字段类型修改成VARCHAR。然后就正常了

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值