afunms

My Software,My Dream—Forge a more perfect NMS product.

PSAX Trap 翻译(2)

 接着,用mibbleacmib中所有事件导入数据库:
/**
     * 导入事件
     
*/

    
public void importEvent(){
        MibBrowser mb 
= new
 MibBrowser();
        Mib mib 
= mb.getMib("e:/ACMIB.mib"
);
        List mvss 
=
 (List)mib.getAllSymbols();
        Connection conn 
=
 ConnectionManager.getConnection();
        
int id = 1
;            
        
try
{
            Statement stat 
=
 conn.createStatement();            
            
for(int i=0,n=mvss.size();i<n;i++)

                
if(mvss.get(i) instanceof
 MibValueSymbol
                    
&& ((MibValueSymbol)mvss.get(i)).getType() instanceof SnmpNotificationType)    
{
                    MibValueSymbol mvs 
=
 (MibValueSymbol)mvss.get(i);
                    SnmpNotificationType snt 
=
 (SnmpNotificationType)mvs.getType();
                    String descr 
= null
;
                    String originDescr 
= null
;
                    
if(snt.getDescription().indexOf(":"> 0
)
                        descr 
= snt.getDescription().substring(snt.getDescription().indexOf(":"+ 2
);    
                    
else

                        descr 
= snt.getDescription();
                    
if(descr.indexOf("Return value"> 0
)
                        descr 
= descr.substring(0,descr.indexOf("Return value"
));    
                    
if(descr.indexOf("Data send with the trap"> 0
)
                        descr 
= descr.substring(0,descr.indexOf("Data send with the trap"
));
                    descr 
= descr.replaceAll("\n"" "
);
                    descr 
= descr.replaceAll("'""''"
);
                    originDescr 
= snt.getDescription().replaceAll("'""''"
);
                    stat.addBatch(
"insert into acmib_event(id,symbol,description,origin_description)values(" + id + ",'" + mvs.getName() + "','" + descr + "','" + originDescr + "')"
);    
                    id
++
;      
                    
if( id % 100 == 0
)
                        stat.executeBatch();
                }

            }

            stat.executeBatch();
        }
catch(Exception e){
            e.printStackTrace();
        }

    }

结果如下:
 

posted on 2009-10-22 10:52 afunms 阅读(94) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

My Links

News

留言簿(18)

随笔档案

相册

搜索

最新评论

阅读排行榜