java调用存储过程2


import java.sql.CallableStatement;
import java.sql.Connection;

import com.zte.cms.platform.util.db.DBUtil;

public class ConClickThread  implements Runnable{
    //app_fr.PKG_P2P_CONTRACTTRANS. pro_newclick_stat (5, null,  合同id, 用户电脑号);--用于手机合同点击率
    //app_fr.PKG_P2P_CONTRACTTRANS. pro_newclick_stat (22, null,  合同id, 用户电脑号);--用于设备合同点击率
       /**
        * 类型:手机5、设备22、邮件等
        */
       private String statType="";
       /**
        * 合同id
        */
       private String conid="";
       /**
        * 用户电脑号短工号
        */
       private String userno="";
       
        public void run() {                                  // 实现run方法
            insertData();
        }

          public String insertData() {       
                 String strData = null;
                Connection conn = null;
                CallableStatement pstmt = null;                
                try
                {
                    String sql = " {call app_fr.PKG_P2P_CONTRACTTRANS.pro_newclick_stat@CMS_TO_WMS(?,null,?,?) }  ";
                    conn = DBUtil.getConnection();
                    pstmt = conn.prepareCall(sql);
                    pstmt.setString(1, statType);
                    pstmt.setString(2, conid);
                    pstmt.setString(3, userno);
                    pstmt.execute();
                   
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
                finally
                {
                    try
                    {
                        
                        if (pstmt != null)
                        {
                            pstmt.close();
                        }
                        if (conn != null)
                        {
                            conn.close();
                        }
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
                return strData;
               }    
        
        
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
//        ConClickThread c=new ConClickThread();
//        c.setConid("1293862");
//        c.setStatType("22");
//        c.setUserno("10044953");
//        Thread t=new Thread(c);
//        t.start();
    }

    public String getConid() {
        return conid;
    }

    public void setConid(String conid) {
        this.conid = conid;
    }

    public String getStatType() {
        return statType;
    }

    public void setStatType(String statType) {
        this.statType = statType;
    }

    public String getUserno() {
        return userno;
    }

    public void setUserno(String userno) {
        this.userno = userno;
    }
    

}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java调用存储过程可以使用CallableStatement对象。首先,你需要创建一个CallableStatement对象,并使用prepareCall方法传入存储过程调用语句。例如,你可以使用以下代码创建一个CallableStatement对象并调用存储过程: ```java CallableStatement c = conn.prepareCall("{call FindCusts(?)}"); c.setString(1, "Tom"); ResultSet rs = c.executeQuery(); while (rs.next()) { String cust = rs.getString("customerid"); System.out.println(cust); } c.close(); ``` 在这个例子中,我们创建了一个CallableStatement对象c,并使用setString方法设置存储过程的参数值。然后,我们使用executeQuery方法执行存储过程,并通过ResultSet对象rs获取结果集。最后,我们使用while循环遍历结果集并打印结果。记得在结束后关闭CallableStatement对象。 另外,如果你想在Java中创建存储过程并直接调用,你可以使用Statement对象的executeUpdate方法执行创建存储过程的SQL语句。例如,你可以使用以下代码创建存储过程调用: ```java Statement stmt = conn.createStatement(); stmt.executeUpdate("create procedure OOP as select * from 学生成绩表"); CallableStatement c = conn.prepareCall("{call OOP}"); ResultSet rs = c.executeQuery(); while (rs.next()) { String chinese = rs.getString("Chinese"); System.out.println(chinese); } conn.close(); ``` 在这个例子中,我们使用Statement对象stmt的executeUpdate方法执行创建存储过程的SQL语句。然后,我们使用CallableStatement对象c调用存储过程,并通过ResultSet对象rs获取结果集。最后,我们使用while循环遍历结果集并打印结果。记得在结束后关闭连接。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值