日期:2014-05-20  浏览次数:20894 次

java 内存溢出
下面是我的代码,大家看看,是啥原因造成的内存溢出啊,数据一跑到9700+就溢出了。
我的设置是set JAVA_OPTS=-Xms64m -Xmx512m
代码:
public class Ods_main {
private static String id = "";
private static String ztbs = "";
private static String PK_HJ ="";//判断参数合计 
private static Connection db2Conn = DBConnection.getDB2Connection();
 
private static Log log = LogFactory.getLog(Ods_main.class);
public static void main (String[] arg)
{
try {
 

String sql_getztbs = "select nextval for ods.SEQ_ods as id ,bs from topicis.dj_zt where " +
"bs not in (select ztbs from ods.ods_lsjl where xybz='Y' )" +
"and qylx_dm!='04'";
  Statement stmtgetztbs = db2Conn.createStatement();
ResultSet rsgetztbs = stmtgetztbs.executeQuery(sql_getztbs);
int bz = 0;//失败计数
int js = 0;//遍历条目计数,包括成功和失败
String time = java.text.DateFormat.getDateTimeInstance().format(new java.util.Date());
// String time=new java.util.Date().toString() ;
log.info("运行时间:" + time + ".");
while (rsgetztbs.next())

{
id = rsgetztbs.getString(1); 
ztbs = rsgetztbs.getString(2);
 
// 调试-
// ztbs ="340000000004344368";
 
//*********插入数据******************************************************/
PK_HJ = Insert_cx.in_ODS_DJ_ZT(id,ztbs,db2Conn,PK_HJ); //插入主体
PK_HJ = Insert_cx.in_ods_dj_gdml(id, ztbs, db2Conn,PK_HJ);
PK_HJ = Insert_cx.in_ODS_XY(id, ztbs, db2Conn,PK_HJ);
PK_HJ = Insert_ods.in_T_XY_DX(id, ztbs, db2Conn,PK_HJ);
PK_HJ = Insert_ods.in_T_XY_FZ(id, ztbs, db2Conn,PK_HJ);
PK_HJ = Insert_ods.in_T_XY_GD(id, ztbs, db2Conn,PK_HJ);
PK_HJ = Insert_ods.in_T_XY_NJJG(id, ztbs, db2Conn,PK_HJ);
PK_HJ = Insert_ods.in_T_XY_QZSP(id, ztbs, db2Conn,PK_HJ);
PK_HJ = Insert_ods.in_T_XY_ZRRGD(id, ztbs, db2Conn,PK_HJ);
PK_HJ = Insert_ods.in_T_XY_ZT(id, ztbs, db2Conn,PK_HJ);
PK_HJ = Insert_ods.in_T_XY_ZX(id, ztbs, db2Conn,PK_HJ);
//*******************************************************************/
 
if(PK_HJ .equals("") )
{
// 成功
 
String insert_log ="insert into ods.ods_lsjl values (" + id + "," + ztbs + ",'','Y')";
Statement stmtInsert_log = db2Conn.createStatement();  
stmtInsert_log.executeUpdate(insert_log); 
js=js+1;
System.out.println( "插入主体数据成功!----企业标识:" + ztbs + " 第"+ js + "条企业数据" );
stmtInsert_log.close();
 
}
else
{
// 失败
 
String insert_log ="insert into ods.ods_lsjl values (" + id + "," + ztbs + PK_HJ + ",'N')";
Statement stmtInsert_log = db2Conn.createStatement();  
stmtInsert_log.executeUpdate(insert_log); 
bz=bz+1;
js=js+1;
System.out.println( "插入主体数据失败!----企业标识:" + ztbs + " 第"+ js + "条企业数据" );
log.error("插入主体数据失败!企业标识:" + ztbs );
stmtInsert_log.close();
}
 
PK_HJ="";//初始化标志
}


 
System.out.println( "插入数据完成。" + " 本次遍历共" + js + "条数据"+"插入数据失败数目" + bz + "条。" + "\n" + "请查证" );
 
rsgetztbs.close();//最后关闭取主体标识连接
stmtgetztbs.close();
db2Conn.close();
}

catch(Exception ex)
{  
System.out.println(ex.toString());
log.error("系统错误:", ex);
}