Good morning everyone. I'm new to Java programming, and would like some help. Well, it's the following, I want to make a method and check if it has any record in my table, if it has, proceed with the action, otherwise it falls outside the if. I already have this select ready, now I just need to implement this in my method and do the verification.
Here is the class you are checking:
public static void main(String args[]) {
AcknowledgementsTemporaryFacade ack = new AcknowledgementsTemporaryFacade();
try {
if(ack.selectTemporary()){
System.out.println("Tem registros");
}
else{
System.out.println("Não tem registros");
}
public boolean selectTemporary() throws ServiceException {
try {
acknowledgementsDao = new AcknowledgementsTemporaryDao();
if(acknowledgementsDao.selectAckTemporary2());
return true;
}
catch(Exception e){
e.printStackTrace();
}
return false;
}
And here is my select, where it searches my records base.
public AcknowledgementsTemporary selectAckTemporary2() throws ServiceException {
AcknowledgementsTemporary ack = null;
PreparedStatement ps = null;
ResultSet rs = null;
Connection conn = null;
String commandSQL = "SELECT \"ds_code\", \"it_date_time_ack\" "
+ "FROM \"tb_ack_temporary\" ";
try {
openConnection();
conn = this.conn;
ps = conn.prepareStatement(commandSQL);
rs = ps.executeQuery();
if(rs.next()){
ack = new AcknowledgementsTemporary();
ack.setCode(rs.getString("ds_code"));
ack.setDateTimeAck(rs.getLong("it_date_time_ack"));
return ack;
};
} catch (Exception e) {
e.printStackTrace(System.err);
LOGGER.error("command sql: " + commandSQL + "parameters: " + ack.getCode() + ack.getDateTimeAck());
} finally {
ConnectionDatabaseFactory.closeConnection(conn, ps);
}
return null;
}