我的代码:
String txt = abc.getstr(no);
response.setHeader("Content-Disposition", "attachment; filename=10000"+today+".txt");
response.setHeader("Content-Type ", "application/octet-stream");
ServletOutputStream servletOS = response.getOutputStream();
IOUtils.write(txt, servletOS);
servletOS.flush();
public static String getstr(String no)
{
StringBuffer strb = new StringBuffer();
String sql = " select a1,a2,a3,a4from tablewhere no= '"+ no+ "'";
try
{
DBAccess dbAgent = new DBAccess();
dbAgent.setConnection("ora");
dbAgent.connect();
Connection conn = dbAgent.getConnection();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next())
{
String a1 = rs.getString("a1");
String a2= rs.getString("a2");
String a3= rs.getString("a3");
String a4= rs.getString("a4");
strb.append(a1);
strb.append(" ");
strb.append(a2);
strb.append(" ");
strb.append(a3);
strb.append(" ");
strb.append(a4);
strb.append("\r\n");
Process ps;
try
{
ps = Runtime.getRuntime().exec(
"/home/tomcat/bin/11 " + a1+ " "+ a2+ "");
BufferedReader br = new BufferedReader(
new InputStreamReader(ps.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null)
{
sb.append(line).append("");
}
String result = sb.toString();
if(result.length()==16)
{
try
{
String ret = update(dbAgent,a1,result);
}
catch (Exception e)
{
e.printStackTrace();
}
}
br.close();
ps.destroy();
ps = null;
}
catch (IOException e)
{
e.printStackTrace();
}
}
rs.close();
st.close();
conn.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
return strb.toString();
}
我在导出生成strb的时候,需要去执行Linux上的一个脚本,将返回的值update到数据库里,然后再进行导出
现在的问题是我执行的导出数据当有5000条的时候,速度慢但是能全部导出;当数据记录达到10000条的时候,导出的txt里的数据就不完整,只有很少的几条;在tomcat日志里报错,显示conn is closed;
谁能帮忙看下是什么地方出现了问题?非常感谢!