java - 我想将 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 ;
}
解决方案
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 ;
您的代码没有任何问题,您只需要z
在while
.
推荐阅读
- vue.js - 将 nuxt.js 集成到我们的 vue.js 应用程序中需要大修吗?
- opengl - 什么是 GPU 驱动的渲染?
- flutter - 为什么在拖动图像期间缩放重置?
- mysql - 限制列值
- python-3.x - Keras 功能 API 比 Sequential 慢 / 没有改进
- javascript - react-native 中的 {' '} 是什么?
- php - 为什么 PHP 和 PostgreSQL 对什么是有效的 UTF-8 有截然不同的想法?
- php - 使用 PHP72 和 ImageMagick 在 Google App Engine 上是否可以进行 WEBP 输出?
- python - 根据列表中的另一列内容创建新列值
- php - 使用 php 将文件上传到谷歌驱动器并检索链接?