sqoop导入时发生错误“将varchar值转换为JDBC数据类型DECIMAL”

时间:2011-12-10 11:18:59

标签: sqoop

情景:

当我输入sqoop导入查询时,我得到如下:

错误:

hadoop@ubuntu:~/sqoop-1.1.0/bin$ ./sqoop-import --driver 'com.microsoft.sqlserver.jdbc.SQLServerDriver' --connect 'jdbc:sqlserver://192.168.xx.xx;database=HadoopTest;user=xxxxx;password=xxxxxx' --table PersonInfo1 --target-dir /data/PersonInfoData --check-column email --incremental append --compress11/12/10 15:52:50 INFO tool.CodeGenTool: Beginning code generation
11/12/10 15:52:50 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM PersonInfo1 AS t WHERE 1=0
11/12/10 15:52:50 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM PersonInfo1 AS t WHERE 1=0
11/12/10 15:52:51 INFO orm.CompilationManager: HADOOP_HOME is /home/hadoop/hadoop-0.21.0/bin/..
11/12/10 15:52:51 INFO orm.CompilationManager: Writing jar file: /tmp/sqoop-hadoop/compile/e8d9b5cc0800d8cde97f533f477a8ebd/PersonInfo1.jar
11/12/10 15:52:51 ERROR tool.ImportTool: Encountered IOException running import job: java.io.IOException: com.microsoft.sqlserver.jdbc.SQLServerException: An error occurred while converting the varchar value to JDBC data type DECIMAL.
    at com.cloudera.sqoop.tool.ImportTool.initIncrementalConstraints(ImportTool.java:235)
    at com.cloudera.sqoop.tool.ImportTool.importTable(ImportTool.java:345)
    at com.cloudera.sqoop.tool.ImportTool.run(ImportTool.java:423)
    at com.cloudera.sqoop.Sqoop.run(Sqoop.java:134)
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:69)
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:83)
    at com.cloudera.sqoop.Sqoop.runSqoop(Sqoop.java:170)
    at com.cloudera.sqoop.Sqoop.runTool(Sqoop.java:196)
    at com.cloudera.sqoop.Sqoop.main(Sqoop.java:205)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: An error occurred while converting the varchar value to JDBC data type DECIMAL.
    at com.microsoft.sqlserver.jdbc.DDC.convertStreamToObject(DDC.java:473)
    at com.microsoft.sqlserver.jdbc.ServerDTVImpl.getValue(dtv.java:2474)
    at com.microsoft.sqlserver.jdbc.DTV.getValue(dtv.java:176)
    at com.microsoft.sqlserver.jdbc.Column.getValue(Column.java:113)
    at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:1981)
    at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:1966)
    at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getBigDecimal(SQLServerResultSet.java:2596)
    at com.cloudera.sqoop.tool.ImportTool.getMaxColumnId(ImportTool.java:187)
    at com.cloudera.sqoop.tool.ImportTool.initIncrementalConstraints(ImportTool.java:230)
    ... 8 more
Caused by: java.lang.NumberFormatException
    at java.math.BigDecimal.<init>(BigDecimal.java:459)
    at java.math.BigDecimal.<init>(BigDecimal.java:728)
    at com.microsoft.sqlserver.jdbc.DDC.convertStringToObject(DDC.java:285)
    at com.microsoft.sqlserver.jdbc.DDC.convertStreamToObject(DDC.java:436)
    ... 16 more

问题:

为什么会这样?请建议我解决这个问题。

感谢。

2 个答案:

答案 0 :(得分:1)

您的SQL Server表中是否有一个定义为varchar的字段,但有一些记录为数字。它可能是将数据类型分配给它决定您想要的字段。

答案 1 :(得分:0)

可能是因为您尝试将varchar转换为float或decimal。 它的DataType问题检查数据库和java代码中的列数据类型。