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);
}