免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1450 | 回复: 4
打印 上一主题 下一主题

急用,请大家帮忙把这段代码改写成db2的存储过程 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-08-31 09:12 |只看该作者 |倒序浏览
由于这段代码查询时间过长,因此,希望能将它改写成sp,但小妹我没写过,希望高手指点一二,最好能写个完整的范例出来,感激不尽!!!



  1.         public boolean setConn(String CUSTNO,String Qdate)
  2.         {
  3. //                int totalRows=1;
  4.                 int greatUnit=0;
  5.                 int smallUnit=0;       
  6.                 int nm_ly3204=0,nm_ly3205=0,nm_ly3206=0,nm_ly3211=0,nm_ly3208=0;       
  7.                 int ax_ly3204=0,ax_ly3205=0,ax_ly3206=0,ax_ly3211=0,ax_ly3208=0;
  8.                 String sql2="";
  9.                 String sql3="";
  10.                
  11.                 ResultSet rs;
  12.                 ResultSet rs2;
  13.                 ResultSet rs3;
  14.                
  15.                 String ly1105="";//名称
  16.                 String ly3202="";
  17.                 String ly3203="";
  18.                 String ly1146="";
  19.                 int ly3201=0;       
  20.                 int ly3204=0;
  21.                 int ly3205=0;
  22.                 int ly3206=0;
  23.                 int ly3211=0;
  24.                 int ly3208=0;
  25.                 int sum_ly3205=0,sum_ly3206=0;
  26.                 int goodsRate=0;//转换率
  27.                 float ly3211_b=0.00f,nm_ly3211_b=0.00f,ax_ly3211_b=0.00f;
  28.                 String rowLine;               
  29.                 String fromdate;
  30.                 fromdate=Qdate.substring(0,6);
  31.                 fromdate=fromdate+"01";               
  32.                 String flag="";
  33.                 try
  34.                 {
  35.                         db1=new getFromPool();
  36.                         if(!db1.isRight)
  37.                         {
  38.                           db1.restartConn();
  39.                         }                                       
  40.                         if(!db1.isRight)
  41.                         {
  42.                           db1=new getFromPool(1);
  43.                         }

  44.                         db2=new getFromPool();
  45.                         if(!db2.isRight)
  46.                         {
  47.                           db2.restartConn();
  48.                         }                                       
  49.                         if(!db2.isRight)
  50.                         {
  51.                           db2=new getFromPool(1);
  52.                         }
  53.                         Statement stmt = db1.getStatement();
  54.                         Statement stmt2 = db2.getStatement();
  55.                         String sql="select distinct ly3203 from LYPLIBS.lyf32 a inner join LYPLIBS.lyf11 b on a.ly3230=b.ly1120 and a.ly3212=b.ly1132 and a.ly3203=b.ly1101 where ly3230='"+CUSTNO+"' and ly3201="+Qdate+" and ly3212='"+DcNo+"'";
  56.                         System.out.println(sql);
  57.                         boolean isRS = stmt.execute(sql);       
  58.                         if (isRS)
  59.                         {
  60.                                 rs=stmt.getResultSet();
  61.                                 while(rs.next())
  62.                                 {               
  63.                                         ly3203=rs.getString(1);
  64.                                        
  65.                                         //求共同资料
  66.                                         sql2="select ly1105,ly1146,ly1112 from LYPLIBS.lyf11 where ly1101='"+ly3203+"' and ly1120='"+CUSTNO+"'";
  67.                                         System.out.println(sql2);
  68.                                         rs2=stmt2.executeQuery(sql2);
  69.                                         if(rs2.next())
  70.                                         {
  71.                                         ly1105=rs2.getString(1);
  72.                                         ly1146=rs2.getString(2);
  73.                                         goodsRate=rs2.getInt(3);               
  74.                                         }
  75.                                         rs2.close();
  76.                                        
  77.                                         //求A品数量
  78.                                         sql2="select ly3201,ly3204,ly3205,ly3206,ly3211,ly3208 from LYPLIBS.lyf32 where ly3230='"+CUSTNO+"' and ly3201="+Qdate+" and ly3203='"+ly3203+"' and ly3202='NM'";
  79.                                         System.out.println(sql2);
  80.                                         rs2=stmt2.executeQuery(sql2);
  81.                                         if (rs2.next())
  82.                                         {
  83.                                                 ly3201=rs2.getInt(1);
  84.                                                 nm_ly3204=rs2.getInt(2);                                               
  85.                                                 nm_ly3205=rs2.getInt(3);
  86.                                                 nm_ly3206=rs2.getInt(4);
  87.                                                 nm_ly3211=rs2.getInt(5);
  88.                                                 nm_ly3208=rs2.getInt(6);                                               
  89.                                         }
  90.                                         else
  91.                                         {
  92.                                                 nm_ly3204=0;
  93.                                                 nm_ly3205=0;
  94.                                                 nm_ly3206=0;
  95.                                                 nm_ly3211=0;
  96.                                                 nm_ly3208=0;
  97.                                         }
  98.                                         rs2.close();
  99.                                        
  100.                                         //求B品数量
  101.                                         sql2="select ly3201,ly3204,ly3205,ly3206,ly3211,ly3208 from LYPLIBS.lyf32 where ly3230='"+CUSTNO+"' and ly3201="+Qdate+" and ly3203='"+ly3203+"' and ly3202='AX'";
  102.                                         System.out.println(sql2);                                       
  103.                                         rs2=stmt2.executeQuery(sql2);
  104.                                         if (rs2.next())
  105.                                         {
  106.                                                 ly3201=rs2.getInt(1);
  107.                                                 ax_ly3204=rs2.getInt("ly3204");
  108.                                                 ax_ly3205=rs2.getInt("ly3205");
  109.                                                 ax_ly3206=rs2.getInt("ly3206");
  110.                                                 ax_ly3211=rs2.getInt("ly3211");
  111.                                                 ax_ly3208=rs2.getInt("ly3208");
  112.                                         }
  113.                                         else
  114.                                         {
  115.                                                 ax_ly3204=0;
  116.                                                 ax_ly3205=0;
  117.                                                 ax_ly3206=0;
  118.                                                 ax_ly3211=0;
  119.                                                 ax_ly3208=0;
  120.                                         }
  121.                                         rs2.close();                                       
  122.                                         sql2=null;
  123.                                
  124.                                         ly3204=nm_ly3204+ax_ly3204;
  125.                                         ly3205=nm_ly3205+ax_ly3205;                                       
  126.                                         ly3206=nm_ly3206+ax_ly3206;
  127.                                         ly3211=nm_ly3211+ax_ly3211;
  128.                                         ly3208=nm_ly3208+ax_ly3208;
  129.                                        
  130.                                         if (goodsRate==0)
  131.                                         {
  132.                                         ly3211_b=0;       
  133.                                         nm_ly3211_b=0;
  134.                                         ax_ly3211_b=0;
  135.                                         flag="单位转换运算出错,请修改";
  136.                                         System.out.println(flag);
  137.                                         }
  138.                                         else
  139.                                         {
  140.                                         ly3211_b=ly3211/goodsRate;       
  141.                                         nm_ly3211_b=nm_ly3211/goodsRate;
  142.                                         ax_ly3211_b=ax_ly3211/goodsRate;
  143.                                         }
  144.                                         total5+=ly3204;
  145.                                         total6+=ly3205;
  146.                                         total7+=ly3206;
  147.                                         total8+=ly3211;
  148.                                         total16+=ly3208;
  149.                                         total9+=ly3211_b;
  150.                                         total10+=nm_ly3211_b;
  151.                                         total11+=nm_ly3211;
  152.                                         total12+=ax_ly3211_b;
  153.                                         total13+=ax_ly3211;       
  154.        
  155.                                        
  156.                                         writeFile.writeCell(0,totalRows,ly3201,null);
  157.                                            writeFile.writeCell(1,totalRows,-0,ly3203);
  158.                                         writeFile.writeCell(2,totalRows,-0,ly1105);
  159.                                         writeFile.writeCell(3,totalRows,-0,ly1146);
  160.                                     writeFile.writeCell(4,totalRows,goodsRate,null);
  161.                                         writeFile.writeCell(5,totalRows,ly3204,null);
  162.                                     writeFile.writeCell(6,totalRows,ly3205,null);
  163.                                         writeFile.writeCell(7,totalRows,ly3206,null);
  164.                                 writeFile.writeCell(8,totalRows,ly3211,null);
  165.                                 writeFile.writeCell2(9,totalRows,ly3211_b,null);
  166.                                 writeFile.writeCell2(10,totalRows,nm_ly3211_b,null);
  167.                                         writeFile.writeCell(11,totalRows,nm_ly3211,null);
  168.                                 writeFile.writeCell2(12,totalRows,ax_ly3211_b,null);                                         
  169.                                         writeFile.writeCell(13,totalRows,ax_ly3211,null);                                        
  170.                                         writeFile.writeCell(14,totalRows,ly3208,null);  
  171.                                 sql2="select sum(ly3205),sum(ly3206) from LYPLIBS.LYF32 where ly3230='"+CUSTNO+"' and ly3201>;="+fromdate+" and ly3201<="+Qdate+" and ly3203='"+ly3203+"'";
  172.                                 System.out.println(sql2);                               
  173.                                 rs2=stmt2.executeQuery(sql2);
  174.                                 if(rs2.next())
  175.                                 {
  176.                                         sum_ly3205=rs2.getInt(1);
  177.                                         sum_ly3206=rs2.getInt(2);
  178.                                 writeFile.writeCell(15,totalRows,sum_ly3205,null);                                         
  179.                                         writeFile.writeCell(16,totalRows,sum_ly3206,null);           
  180.                                 }
  181.                                 rs2.close();
  182.                                 sql2="";
  183.                                 total14+=sum_ly3205;
  184.                                 total15+=sum_ly3206;
  185.                                 totalRows++;       
  186.                         }                               
  187.                                 rs.close();                               
  188.                                 stmt2.close();       
  189.                                 }
  190.                                 else
  191.                                 {
  192.                                         System.out.println("当时无相关记录");
  193.                                 }
  194.                                 stmt.close();       
  195.                 }
  196.                 catch(Exception e)
  197.                 {
  198.                         e.printStackTrace();
  199.                         errorMsg="数据查询出错";
  200.                         return false;
  201.                 }
  202.                 finally
  203.                 {
  204.                         try
  205.                         {
  206.                                 db1.getConnection().close();
  207.                                 db2.getConnection().close();
  208.                         }catch(Exception dd){
  209.                                 dd.printStackTrace();
  210.                         }
  211.                
  212.                 }
  213.                 return true;
  214.                
  215. }


复制代码

论坛徽章:
0
2 [报告]
发表于 2004-08-31 10:36 |只看该作者

急用,请大家帮忙把这段代码改写成db2的存储过程

呵呵,,java我不会啊,我只会c的sp,呵呵

论坛徽章:
0
3 [报告]
发表于 2004-08-31 10:41 |只看该作者

急用,请大家帮忙把这段代码改写成db2的存储过程

我也没有写过。
只是大概有个概念应该可以实现。
这周打算去借本db2/400的书看看。网上好像很少db2存储过程的入门书籍。

不过现在急需这个存储过程,有经验的高手们请帮忙呀。

论坛徽章:
0
4 [报告]
发表于 2004-08-31 14:29 |只看该作者

急用,请大家帮忙把这段代码改写成db2的存储过程

呵呵 其实你使用DB2自带的存储过程开发器 他会自动帮你生成主框架
非数据库操作不用变的 只要把数据库连接改一下就行了
如果正确的话 选择构建选项 就可以自动生成SP for java 了,编译 注册全帮你搞定
jhjjjgtgtf 该用户已被删除
5 [报告]
发表于 2004-09-01 22:27 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP