首先配置applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="springDSN" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:ORCL" />
<property name="username" value="ipsys" />
<property name="password" value="123456" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
abstract="false" lazy-init="false" autowire="default">
<property name="dataSource">
<ref bean="springDSN" />
</property>
</bean>
</beans>
写jdbctemplate,
// 更新资源和网管表内一致性标记
public static boolean updateIpsrmCon1() {
jdbcTemplate.update("update ipsrm set con=-2 where ipstate=0 and iplevel=0");
return true;
}
public static boolean updateIpsrmCon2() {
if (jdbcTemplate.update("update ipsrm set con=0 where ip in (select "
+ "ipsrm.ip from ipsrm,ipms where ipsrm.ip=ipms.ip and (ipsrm.ipstate=1 or ipsrm.IPLEVEL=1))")==1){
return true;
}
else
return false;
}
public static boolean updateIpmsCon() {
if (jdbcTemplate.update("update ipms set con=0 where ip in "
+ "(select ipms.ip from ipsrm,ipms where ipsrm.ip=ipms.ip and (ipsrm.ipstate=1 or ipsrm.IPLEVEL=1))")==1){
return true;
}
else
return false;
}
// 详表
public static boolean IpdetailTable1() {
if (jdbcTemplate.update("insert into IPDETAIL (select ip,brasip,city,ipstate,iplevel,con from ipsrm )")==1){
return true;
}
else
return false;
}
public static boolean IpdetailTable2() {
if (jdbcTemplate.update("update IPDETAIL set con=1 where ip in (select ipms.ip from ipsrm,ipms where ipms.ip=ipsrm.ip and ipms.con=1)")==1){
System.out.println("详表 2");
return true;
}
else
return false;
}
// 总表
public static boolean IpsummaryTable1() {
if (jdbcTemplate.update("insert into ipsummary (brasip,city) (select brasip,city from brasip)")==1){
return true;
}
else
return false;
}
public static boolean IpsummaryTable2() {
if (jdbcTemplate.update("update ipsummary a set a.con=(select consistency from (select count(*) as consistency,brasip from IPDETAIL where con=0 or con=-2 group by BRASIP) b where a.brasip=b.brasip)")==1){
return true;
}
else
return false;
}
public static boolean IpsummaryTable3() {
if (jdbcTemplate.update("update ipsummary a set a.srm=(select srm from (select count(*) as srm,brasip from IPDETAIL where con=-1 group by BRASIP) b where a.brasip=b.brasip)")==1){
return true;
}
else
return false;
}
public static boolean IpsummaryTable4() {
if (jdbcTemplate.update("update ipsummary a set a.ms=(select ms from (select count(*) as ms,brasip from IPDETAIL where con=1 group by BRASIP) b where a.brasip=b.brasip)")==1){
return true;
}
else
return false;
}
public static boolean IpsummaryTable5() {
if (jdbcTemplate.update("update ipsummary set ms=0 where ms is null")==1){
return true;
}
else
return false;
}
再写执行语句
package com.ipconn.db;
public class IpSummaryAddDetail {
public static void main(String[] args) {
//注意:运行时,一定要关闭 sqldeveloper.exe,不然数据刷不出来!!!至于原因我也不知道为什么!
// --更新资源和网管表内一致性标记
IpDac.updateIpsrmCon1(); //update ipsrm set con=-2
IpDac.updateIpsrmCon2(); //update ipsrm set con=0
IpDac.updateIpmsCon(); //update ipms set con=0
// --生成详表
IpDac.IpdetailTable1();
IpDac.IpdetailTable2();
//--生成总表
IpDac.IpsummaryTable1();
IpDac.IpsummaryTable2();
IpDac.IpsummaryTable3();
IpDac.IpsummaryTable4();
IpDac.IpsummaryTable5();
}
}