java - 在java中使用数据库处理程序执行操作的问题
问题描述
我正在努力调试为什么我的程序在特定行停止,我试图了解它是否与创建表或语句有关,但控制台没有给我任何错误,并且程序在运行此功能后仍然卡住:
@FXML
private void loadIssueOperation(ActionEvent event) {
String memberID = memberIdInput.getText();
String bookID = bookIdInput.getText();
Alert confAlert = new Alert(Alert.AlertType.CONFIRMATION);
confAlert.setTitle("Confirm New Opperation");
confAlert.setHeaderText(null);
//TASK1
confAlert.setContentText("Are you sure about issue the book "+bookName.getText()+
"\n to "+memberName.getText()+"?");
Optional<ButtonType> response = confAlert.showAndWait();
if(response.get()==ButtonType.OK){
String insertStr = "INSERT INTO ISSUE(memberID,bookID) VALUES("
+ "'" + memberID + "',"
+ "'" + bookID + "')";
String updateStr = "UPDATE BOOK SET isAvail = false WHERE id = '"+bookID+"'";
System.out.println(insertStr+" and "+updateStr);
if(dataBaseHandler.execAction(insertStr) && dataBaseHandler.execAction(updateStr)){
Alert successAlert = new Alert(Alert.AlertType.INFORMATION);
successAlert.setTitle("Success");
successAlert.setHeaderText(null);
successAlert.setContentText("Complete");
successAlert.showAndWait();
}else{
Alert failedAlert = new Alert(Alert.AlertType.ERROR);
failedAlert.setTitle("Failed");
failedAlert.setHeaderText(null);
failedAlert.setContentText("Issue Operation Failed");
failedAlert.showAndWait();
}
}else{
Alert cancelAlert = new Alert(Alert.AlertType.INFORMATION);
cancelAlert.setTitle("Canceled");
cancelAlert.setHeaderText(null);
cancelAlert.setContentText("Issue Operation Canceled");
cancelAlert.showAndWait();
}
}
我试图插入和更新的表是这样的:
void setupIssueTable(){
String TABLE_NAME="ISSUE";
try {
stmt = conn.createStatement();
DatabaseMetaData dbm = conn.getMetaData();
ResultSet tables = dbm.getTables(null, null, TABLE_NAME.toUpperCase(), null);
if(tables.next()){
System.out.println("Table "+ TABLE_NAME + "Already exist, ready for go!");
}else{
stmt.execute("CREATE TABLE "+ TABLE_NAME + "("
+ " bookID varchar(200) primary key,\n"
+ " memberID varchar(200),\n"
+ " issueTime timestamp default CURRENT_TIMESTAMP,\n"
+ " renew_Count integer default 0,\n"
+ " FOREIGN KEY (bookID) REFERENCES BOOK(id),\n"
+ " FOREIGN KEY (memberID) REFERENCES MEMBER(id)\n"
+ " )");
}
} catch (SQLException e) {
System.err.println(e.getMessage()+".......setupDatabase");
}finally{
}
}
代码有问题吗?我是java新手
解决方案
推荐阅读
- ios - 何时必须调用 CLLocationManager requestAlwaysAuthorization?
- javascript - 吉克立方体 api。从状态配置
- r - 有没有更快的方法来计算库克与 R 的距离?
- javascript - 通过 vue-router 传递多个参数,其中一个在 URL 中使用
- r - 根据特定逻辑计算条件累积值
- laravel - 使用 firstOrCreate 创建后立即附加模型
- mysql - 如何在 TEXT 列中存储无限数据
- office-js - 将 Word 的 Office 加载项托管/部署到外部客户的最佳方式 - 是否需要 SPLA 或其他许可证?
- node.js - 如何在 ExpressJS 中处理同步
- c++ - 样式检查:错误:左括号 '(' 之前需要空格