java - statement.executeQuery)在 NetBeans java 中不起作用
问题描述
我正在尝试在我的数据库中输出我的表 (StudentInfo) 的第一列 (nameID)。但是 statement.executeQuery 不起作用并且 ResultSet.next() 为假。
- Java NetBeans 程序
- 调用 sqlite 数据库
- 使用“jdbc:sqlite:ProjectWeekDB.sqlite”作为 url
private static Connection connection = null;
private static PreparedStatement stmt = null;
private static Statement statement = null;
private static ResultSet results = null;
public static void createNewDatabase() {
String sqlData = "SELECT * FROM StudentInfo";
String url;
try {
connection = DriverManager.getConnection(url);
if (connection != null) {
statement = connection.createStatement();
stmt = connection.prepareStatement(sqlData);
statement.executeUpdate(sqlData);
results = statement.executeQuery(sqlData);
while (results.next()) {
print(results.getInt("nameID"));
}
stmt.close();
results.close();
}
} catch (SQLException e) {
print(e.getMessage());
}
}
public static void main(String[] args) {
createNewDatabase();
}
它只是打印出 BUILD successful 而没有实际显示数据库中的第一列。
解决方案
推荐阅读
- javascript - Fabric JS + Gif图像动画不起作用
- ember.js - 在 ember 中访问控制器功能中的控制器属性
- git - 如何从 git remote 永久撤消最近的提交,但将其保存在我的本地?
- c# - 如何让 QnA maker 和 Luis BOT 的集成能够准确工作?
- r - 语言 R:变量在“for()”循环内不会改变?
- php - 如何从当前父类别中获取 Woocommerce 所有子类别
- reactjs - 当代码在服务器上时,从客户端或服务器端完成 React JS API 调用。?
- assembly - 试图将参数传递给过程但引发异常?
- node.js - 具有存储库的 Amazon AWS Lambda 函数......?
- php - 根据 WooCommerce 中的购物车项目总数隐藏所有运输方式