Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/library/assistant/database/DatabaseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static void inflateDB() {
System.out.println("Already loaded tables " + loadedTables);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(DatabaseHandler.class.getClass().getResourceAsStream("/resources/database/tables.xml"));
Document doc = dBuilder.parse(DatabaseHandler.class.getResourceAsStream("/resources/database/tables.xml"));
NodeList nList = doc.getElementsByTagName("table-entry");
for (int i = 0; i < nList.getLength(); i++) {
Node nNode = nList.item(i);
Expand Down Expand Up @@ -89,7 +89,7 @@ private static void createConnection() {
conn = DriverManager.getConnection(DB_URL);
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, "Cant load database", "Database Error", JOptionPane.ERROR_MESSAGE);
LOGGER.log(Level.ERROR, "Cant load database", e);
System.exit(0);
}
}
Expand Down Expand Up @@ -123,14 +123,30 @@ public ResultSet execQuery(String query) {
return result;
}

public ResultSet execQuery(String query, Object... params) {
ResultSet result;
try {
PreparedStatement pstmt = conn.prepareStatement(query);
for (int i = 0; i < params.length; i++) {
pstmt.setObject(i + 1, params[i]);
}
result = pstmt.executeQuery();
}
catch (SQLException ex) {
LOGGER.log(Level.ERROR, "Exception at execQuery:dataHandler", ex);
return null;
}
return result;
}

public boolean execAction(String qu) {
try {
stmt = conn.createStatement();
stmt.execute(qu);
return true;
}
catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error:" + ex.getMessage(), "Error Occured", JOptionPane.ERROR_MESSAGE);
LOGGER.log(Level.ERROR, "Error:" + ex.getMessage(), ex);
System.out.println("Exception at execQuery:dataHandler" + ex.getLocalizedMessage());
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/library/assistant/ui/main/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ private void loadMemberInfo(ActionEvent event) {
enableDisableGraph(false);

String id = memberIDInput.getText();
String qu = "SELECT * FROM MEMBER WHERE id = '" + id + "'";
ResultSet rs = databaseHandler.execQuery(qu);
String qu = "SELECT * FROM MEMBER WHERE id = ?";
ResultSet rs = databaseHandler.execQuery(qu, id);
Boolean flag = false;
try {
while (rs.next()) {
Expand Down