JAVA向oracle 发送sql执行语句

首先配置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();
	}
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值