Skip to content

Commit

Permalink
DAODisease v.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewaaa committed Dec 22, 2023
1 parent 3bac83d commit def858f
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/main/java/model/DAO/DAODisease.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package model.DAO;

import model.entity.Condition;
import model.entity.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DAODisease {

private Condition getConditionFromResultSet(ResultSet resultSet) throws SQLException {
Condition condition = new Condition();

condition.setIdCondition(resultSet.getInt("ID"));
condition.setDisorderName(resultSet.getString("Name_Disorder"));
condition.setDisorderDescription(resultSet.getString("Disorder_Description"));
return condition;
}

public Condition getConditionByID(int id) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;

try {

connection = DAOConnection.getConnection();
String query = null;

query = "SELECT * FROM condition WHERE ID = ?";


preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, id);

resultSet = preparedStatement.executeQuery();

if (resultSet.next()) {
return getConditionFromResultSet(resultSet);
}

} catch (SQLException e) {
// Handle the exception (e.g., log or throw)
e.printStackTrace();
} finally {
try {
if (resultSet != null) resultSet.close();
if (preparedStatement != null) preparedStatement.close();
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
// Handle the exception (e.g., log or throw)
e.printStackTrace();
}
}
return null; // or you may throw an exception here
}

}

0 comments on commit def858f

Please sign in to comment.