I am developing a small app in Java, in which I make a connection to a database and I get a JSON field, that JSON I transform it into an object, and later I insert them into a hashtable, and finally I return the hashtable. ..
The Subject is in which I have 4 rows in the database, and in the App when adding the hashtable data to the table, it only takes 3 ... If I add another data to the database, only take 4 of 5 ... and so on
Code: (DatabaseConnection.java)
public static <T> Hashtable<Integer, T> GetList(String Table) throws Exception{
T obj = null;
Hashtable<Integer, T> objs = new Hashtable<Integer, T>();
int id = 0;
String data;
Connection Connector = Connect();
try{
Statement Stats = Connector.createStatement();
String sql = "SELECT * FROM " + Table;
ResultSet result = Stats.executeQuery(sql);
while(result.next()){
id = result.getInt(1);
data = result.getString(2);
obj = SerializerClass.Deserialize(data);
objs.put(id, obj);
System.out.println(id);
}
}catch(SQLException sqlEx){
throw new Exception("Exeption Ocurred. " + sqlEx.getMessage());
}
return objs;
}
Code # 2 (PrincipalForm.java)
public void UpdateGUI(){
Columns = new String[] {"Nombre", "Servicio", "Fecha", "Estado"};
n = new DefaultTableModel(Columns, 0);
SessionsTable.setModel(n);
try{
this.SesionesList = DataBaseConnection.GetList("sesiones");
if (!SesionesList.isEmpty()) {
for (int i = 0; i < SesionesList.size(); i++) {
if (SesionesList.get(i) != null) {
String Name = SesionesList.get(i).Name;
PaqueteCasual Service = SesionesList.get(i).Servicio;
String fecha = SesionesList.get(i).Fecha;
Estado State = SesionesList.get(i).State;
Object[] data = { Name, Service, fecha, State };
n.addRow(data);
}else { System.out.println("Is null"); }
}
}else{
System.out.print("Its Empty.");
}
} catch (Exception ex) {
System.err.print("ERROR: " + ex.getMessage());
Logger.getLogger(SesionesPrincipalForm.class.getName()).log(Level.SEVERE, null, ex);
}
}
From what I have noticed, it is that when it reaches the 4th value, it returns a null. As you may notice in Code # 2, I have an IF that confirms if it is null or not, and indeed ... with the first 3 values it takes, but the 4th one is Null