开发者社区> 问答> 正文

java怎么调用MySQL存储过程?

screenshot
Java调用存储过程报错,存储过程有两个int型参数,在数据库里存储过程可以运行,运行结果如上图:java.sql.SQLException: Parameter index out of range (0 < 1 ).
代码如下,不知道怎么改?

public ArrayList getzhdltj(String Time,String Dzbm) 
{
//定义一些变量
ResultSet rs=null;
Connection ct=null;
PreparedStatement csmt=null;
Statement ps=null;
ArrayList al = new ArrayList();
try
{
ct=(new ConnectDB()).ConnDB();
int Dzbmint=Integer.parseInt(Dzbm);
int Timeint=Integer.parseInt(Time);
//ct.setAutoCommit(false);
csmt=ct.prepareCall("{PRO_综合电力统计(IN_YEAR,IN_STATIONID)}");
csmt.setInt(0, Timeint);
csmt.setInt(1, Dzbmint);
            csmt.execute();
            ct.commit();
            rs=csmt.executeQuery();
            while(rs.next())
            {
                Wnbqgl nbqgl=new Wnbqgl();
                //nbqgl.setMaxdl(rs.getDouble(2));
                /*月计划发电量*/
                nbqgl.setYjfdl(rs.getDouble(1));
                nbqgl.setEjfdl(rs.getDouble(2));
                nbqgl.setSjfdl(rs.getDouble(3));
                nbqgl.setSijfdl(rs.getDouble(4));
                nbqgl.setWjfdl(rs.getDouble(5));
                nbqgl.setLjfdl(rs.getDouble(6));
                nbqgl.setQjfdl(rs.getDouble(7));
                nbqgl.setBjfdl(rs.getDouble(8));
                nbqgl.setJjfdl(rs.getDouble(9));
                nbqgl.setShijfdl(rs.getDouble(10));
                nbqgl.setSyjfdl(rs.getDouble(11));
                nbqgl.setSejfdl(rs.getDouble(12));

展开
收起
蛮大人123 2016-06-14 14:40:39 4428 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    参考代码

    conn = JdbcUtils.getConnection();
    CallableStatement cstmt = (CallableStatement) conn.prepareCall("{call updatePopularUserMore(?,?,?,?,?)}", iRsType, iRsConcurrency);
    cstmt.setObject("aUserId", aUserId);
    cstmt.setObject("aMood", aMood);
    cstmt.setObject("aPersonalityLabel", aPersonalityLabel);
    cstmt.setObject("aFriendClaim", aFriendClaim);
    cstmt.setObject("aHeaderPic", aHeaderPic);
    2019-07-17 19:37:41
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载

相关镜像