zoukankan      html  css  js  c++  java
  • sqlserver存储过程创建和java调用

    创建存储过程

    CREATE  procedure [dbo].[getdata_monitor_city_hour_hb] 
    @aaa varchar(50),   
    @test varchar(50) OUT
    as 
    begin
    
    SET @test = '失败';
    
    if not exists(select DATETIME FROM monitor_city_hour where city like 'hb%' and DATETIME =(select max(DATETIME) from monitor_site_hour where city like 'hb%'))
    begin
    insert into monitor_city_hour(DATETIME,so2,no2,pm10,co,o3_1,o3_8,pm25,city)
    SELECT DATETIME
          ,round(avg(cast([so2] as float)),0)  so2
          ,round(avg(cast([no2] as float)),0)  no2
          ,round(avg(cast([pm10] as float)),0) pm10
          ,round(avg(cast([co] as float)),3)   co
          ,round(avg(cast([o3_1] as float)),0) o3_1
          ,round(avg(cast([o3_8] as float)),0) o3_8
          ,round(avg(cast([pm25] as float)),0) pm25
          ,[city]
      FROM monitor_site_hour
      where DATETIME=(select max(DATETIME) from monitor_site_hour where city like 'hb%')
       and city like 'hb%'
      and so2!='' and no2!=''and pm10!=''and co!=''
      and o3_1!='' and o3_8!='' and pm25!=''
      group by DATETIME,city;
      SET @test ='成功';
      end
    
    end ;

    JAVA调用

    Connection conn=JDBCUtilSingle.getInitJDBCUtil().getConnection();
                    conn.setAutoCommit(true);
                    PreparedStatement pst = null;
                    
                    //执行存储过程
                    CallableStatement proc=conn.prepareCall("{call getdata_monitor_city_hour_hb(?,?)}");
                    proc.setString(1, "aa");  
                    proc.registerOutParameter(2, Types.VARCHAR);  
                    proc.execute();  
                    String testPrint = proc.getString(2);  
                    System.out.println(new Date()+",hebeiDataJob,hb城市小时值,存储过程返回的值是:"+testPrint);
                    
                    
                    
                    // 批量入库完成,数据库连接关闭
                    JDBCUtilSingle.getInitJDBCUtil().closeConnection(pst, conn);
  • 相关阅读:
    [AGC030F] Permutation and Minimum
    nginx
    Flex建立AS项目时,如何设定发布的舞台大小
    让Flex 支持VSS
    Flex编程实用技巧
    Flash/Flex学习笔记(57):实用技巧
    sql 2000 "无法执行查询,因为一些文件缺少或未注册"的解决办法
    Flash/Flex学习笔记(56):矩阵变换
    什么是反向代理,如何利用反向代理提高网站性能
    AS3及Flex的百条常用知识
  • 原文地址:https://www.cnblogs.com/tiandi/p/12032357.html
Copyright © 2011-2022 走看看