1
Good morning guys. I’m new to Java programming, and I’d like a little help. Well, the thing is, I want to do a method and check if there is any record in my table, if you have, proceed with the action, otherwise it gets out of the if. I already have this select ready, now I just need to implement it in my method and do the check.
Here’s the class you check into:
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");
}
Right below is my stabbing, where I’m in trouble, I don’t know what kind of feedback that has to be.. I put Boolean, but it’s not working:
public boolean selectTemporary() throws ServiceException {
try {
acknowledgementsDao = new AcknowledgementsTemporaryDao();
if(acknowledgementsDao.selectAckTemporary2());
return true;
}
catch(Exception e){
e.printStackTrace();
}
return false;
}
And this is my select, where you search my base for the records.
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;
}