概述
java.io.IOException: Attempted read on closed stream
原因是 ResultSet 数据读取完成之前已经把 ClickHousePreparedStatement 关闭。
public ResultSet QueryResultSet(Connection connection, String sql, String[] params) {
ResultSet rst=null;
ClickHousePreparedStatement pst=null;
if (connection==null) {
System.out.println("connection is empty");
System.exit(-1);
}
try {
pst= (ClickHousePreparedStatement) connection.prepareStatement(sql);
if (params!=null)
for (int i = 0; i < params.length; i++) {
pst.setObject(i+1,params[i]);
}
rst = pst.executeQuery();
} catch (SQLException throwables) {
throwables.printStackTrace();
}finally{
close(pst,connection);
}
return rst;
}
需要调整代码为
public ResultSet QueryResultSet(Connection connection,ClickHousePreparedStatement pst, String sql, String[] params) {
ResultSet rst=null;
if (connection==null) {
System.out.println("connection is empty");
System.exit(-1);
}
try {
pst= (ClickHousePreparedStatement) connection.prepareStatement(sql);
if (params!=null)
for (int i = 0; i < params.length; i++) {
pst.setObject(i+1,params[i]);
}
rst = pst.executeQuery();
} catch (SQLException throwables) {
throwables.printStackTrace();
}finally{
}
return rst;
}
然后调用该方法后 用
Connection conn1 =null;
ClickHousePreparedStatement pst=null;
ResultSet resultsll =null;
try
{
}catch
{
}
finally
{
ClickHouseDaoUtils.closeClickhouse(resultsll,pst,conn1);
}
最后
以上就是曾经小熊猫为你收集整理的clickhouse jdbc读取批量数据 报java.io.IOException: Attempted read on closed streamjava.io.IOException: Attempted read on closed stream的全部内容,希望文章能够帮你解决clickhouse jdbc读取批量数据 报java.io.IOException: Attempted read on closed streamjava.io.IOException: Attempted read on closed stream所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复