首页 > 解决方案 > 我想将 z 作为 int 返回,但无法返回

问题描述

我试图z作为一个返回,int但我无法这样做。我用来实现此目的的代码如下所示。

public static int pagenumber(String DBmatter, String ClassYear) throws SQLException {

        Statement stmt;
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("select * from page_number where 'matter_name' = '" + DBmatter + ClassYear + "';");
        while (rs.next()) {
            String y = rs.getString(3);
            int z = Integer.parseInt(y);
        }
        return z ;

    }

标签: javamysql

解决方案


Statement stmt;
stmt = con.createStatement();
int z = 0;
ResultSet rs = stmt.executeQuery("select * from page_number where 'matter_name' = '" + DBmatter + ClassYear + "';");
while (rs.next()) {
    String y = rs.getString(3);
    z = Integer.parseInt(y);
}
return z ;

您的代码没有任何问题,您只需要zwhile.


推荐阅读