我正在测试official teradata website的fastload示例代码。为了谨慎起见,我使用samples.jar here
上的示例FastLoad1.csv
当我运行此示例代码时,我在此行中收到错误
pstmtFld.setAsciiStream(1, dataStream, -1); // This method is not implemented
如何将setAsciiStream与预准备语句一起使用?
我正确使用setAsciiStream
吗?
以下是控制台中的错误消息
Attempting connection to Teradata with FastLoadCSV.
Connection to Teradata with FastLoadCSV established.
Creating a PreparedStatement object with FastLoadCSV.
Created a PreparedStatement object with FastLoadCSV.
Checking connection for warnings
Streaming FastLoad1.csv
SQL State = HY000, Error Code = 1151
com.teradata.jdbc.jdbc_4.util.JDBCException: [Teradata JDBC Driver] [TeraJDBC 14.10.00.17] [Error 1151] [SQLState HY000] A failure occurred while setting a parameter value for database table "xxxxxxxxx"."my_table". Details of the failure can be found in the exception chain that is accessible with getNextException.
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:93)
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:68)
at com.teradata.jdbc.jdbc.fastload.FastLoadManagerPreparedStatement.setAsciiStream(FastLoadManagerPreparedStatement.java:1366)
at T20208JD.main(T20208JD.java:160)
SQL State = HY000, Error Code = 1155
com.teradata.jdbc.jdbc_4.util.JDBCException: [Teradata JDBC Driver] [TeraJDBC 14.10.00.17] [Error 1155] [SQLState HY000] The next failure(s) in the exception chain occurred in FastLoadPreparedStatement[0] of 16 FastLoadPreparedStatement(s).
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:93)
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:73)
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:101)
at com.teradata.jdbc.jdbc.fastload.FastLoadManagerPreparedStatement.setAsciiStream(FastLoadManagerPreparedStatement.java:1361)
at T20208JD.main(T20208JD.java:160)
SQL State = HY000, Error Code = 1093
com.teradata.jdbc.jdbc_4.util.JDBCException: [Teradata JDBC Driver] [TeraJDBC 14.10.00.17] [Error 1093] [SQLState HY000] This method is not implemented
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:93)
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:63)
at com.teradata.jdbc.jdbc.fastload.FastLoadPreparedStatement.setAsciiStream(FastLoadPreparedStatement.java:759)
at com.teradata.jdbc.jdbc.fastload.FastLoadManagerPreparedStatement.setAsciiStream(FastLoadManagerPreparedStatement.java:1359)
at T20208JD.main(T20208JD.java:160)
SQL State = HY000, Error Code = 1151
com.teradata.jdbc.jdbc_4.util.JDBCException: [Teradata JDBC Driver] [TeraJDBC 14.10.00.17] [Error 1151] [SQLState HY000] A failure occurred while setting a parameter value for database table "xxxxxxxx"."my_table". Details of the failure can be found in the exception chain that is accessible with getNextException.
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:93)
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:68)
at com.teradata.jdbc.jdbc.fastload.FastLoadManagerPreparedStatement.setAsciiStream(FastLoadManagerPreparedStatement.java:1366)
at T20208JD.main(T20208JD.java:160)
SQL State = HY000, Error Code = 1155
com.teradata.jdbc.jdbc_4.util.JDBCException: [Teradata JDBC Driver] [TeraJDBC 14.10.00.17] [Error 1155] [SQLState HY000] The next failure(s) in the exception chain occurred in FastLoadPreparedStatement[0] of 16 FastLoadPreparedStatement(s).
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:93)
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:73)
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:101)
at com.teradata.jdbc.jdbc.fastload.FastLoadManagerPreparedStatement.setAsciiStream(FastLoadManagerPreparedStatement.java:1361)
at T20208JD.main(T20208JD.java:160)
SQL State = HY000, Error Code = 1093
com.teradata.jdbc.jdbc_4.util.JDBCException: [Teradata JDBC Driver] [TeraJDBC 14.10.00.17] [Error 1093] [SQLState HY000] This method is not implemented
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:93)
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDriverJDBCException(ErrorFactory.java:63)
at com.teradata.jdbc.jdbc.fastload.FastLoadPreparedStatement.setAsciiStream(FastLoadPreparedStatement.java:759)
at com.teradata.jdbc.jdbc.fastload.FastLoadManagerPreparedStatement.setAsciiStream(FastLoadManagerPreparedStatement.java:1359)
at T20208JD.main(T20208JD.java:160)
Exception in thread "main" java.lang.IllegalStateException: Sample failed.
at T20208JD.main(T20208JD.java:336)
答案 0 :(得分:8)
我尝试编译示例T20208JD,只修改了DNS /用户/密码,它在我的Mac上运行顺畅。所以 pstmtFld.setAsciiStream(1,dataStream,-1); 似乎是正确的。
我使用了JDBC 14.10.00.18,您可以尝试从Teradata的Developer Exchange下载最新版本14.10.00.26:http://downloads.teradata.com/download/connectivity/jdbc-driver
我认为这不会解决问题,但是......
答案 1 :(得分:1)
我认为错误是由-1
引起的,第三个参数告诉setAsciiStream byteStream有-1
个字节。
我过去使用过setAsciiStream()
时,如果超过254个字符,我会使用bufferInputStream
和String
的大小。
String convRule;
...
if (convRule.length() > 254) {
int size = convRule.length();
BufferedInputStream bais = new BufferedInputStream( new ByteArrayInputStream( convRule.getBytes() ) );
pStmt.setAsciiStream( 4, bais, size );
}
所以,比较我和你的,我可以告诉第三个参数是不同的,应该是输入流的length
。