I am trying to take relevant values from an existing table and put them into a Virtual table, which I can then search through and get the entries I want.
I have everything more or less working except the actual loading of the entries into this Virtual Table via the program. I have tested these statements to the best of my ability inside of sqliteManager and they seem to have no issues, but when I try to execute them through the program, nothing happens, and stmt.execute()
returns false.
Code in question:
public void getResults() {
String sqlGetData = "INSERT INTO VirtualProductTable SELECT * FROM
H4HProductTable WHERE id = ? AND price <= ?" +
" AND length <= ? AND width <= ? AND height <= ?";
switch (((Categories)this.categorySelect.getValue()).toString()) {
case "Furniture":
sqlGetData = sqlGetData.concat(" AND isFurniture = 1");
break;
case "Appliances":
sqlGetData = sqlGetData.concat(" AND isAppliance = 1");
break;
case "Building_Materials":
sqlGetData = sqlGetData.concat(" AND isBuildingMaterial = 1");
break;
case "Tools":
sqlGetData = sqlGetData.concat(" AND isTool = 1");
break;
default:
break;
}
// corrects for empty/unimportant fields //
try {
Connection conn = DBConnection.getConnection();
PreparedStatement stmt = conn.prepareStatement(sqlGetData);
if(this.idSearch.getText().equals(null) ||
this.idSearch.getText().isEmpty()) {
stmt.setString(1, "id");
} else {
stmt.setString(1, this.idSearch.getText());
}
if(this.priceSearch.getText().equals(null) ||
this.priceSearch.getText().isEmpty()) {
stmt.setString(2, "price");
} else {
stmt.setString(2, this.priceSearch.getText());
}
if(this.lengthSearch.getText().equals(null) ||
this.lengthSearch.getText().isEmpty()) {
stmt.setString(3, "length");
} else {
stmt.setString(3, this.lengthSearch.getText());
}
if(this.widthSearch.getText().equals(null) ||
this.widthSearch.getText().isEmpty()) {
stmt.setString(4, "width");
} else {
stmt.setString(4, this.widthSearch.getText());
}
if(this.heightSearch.getText().equals(null) ||
this.heightSearch.getText().isEmpty()) {
stmt.setString(5, "height");
} else {
stmt.setString(5, this.heightSearch.getText());
}
if(!stmt.execute()) {
System.out.println("insert statement not executed");
}
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
this is then called by the searchProduct()
function below:
public void searchProduct (ActionEvent event) throws Exception {
// makes sure we are not just piling entry after entry every consecutive search //
String drop = "DELETE FROM VirtualProductTable";
PreparedStatement stmt = this.newSearchModel.connection.prepareStatement(drop);
stmt.execute();
stmt.close();
// 1. Creates a virtual table and inserts all entries of the category we're looking for, that are also within our other criteria
// 2. Sort that table into a list and print out the fields we need row by row
getResults();
showFirstSix();
}
Now, I know that my program is at the very least connected to my database, as the "DELETE FROM VirtualProductTable" statement works fine (I've tested it by having already manually entered items in the table in question).
The only other thing that I could possibly think might be causing this issue is that my stmt.setString(...)
s aren't working properly, but I don't know how to properly test those and see what values are actually being taken.
I should make it clear, I am not receiving any actual error message from eclipse, so I think I am syntactically sound statement-wise.