#Database code returns only null

1 messages · Page 1 of 1 (latest)

latent osprey
#

I'm trying to get values from a database. (I checked manually already and know that the values in the database aren't actually null) My Query is "SELECT * FROM LsGamesPlayers WHERE player_uuid = ? AND game = ?;". And I'm using the following code to loop through the columns and get the values (the if statements with the boolean isLifetime aren't important for this case).

ResultSet set = prep.executeQuery();
set.next();
ResultSetMetaData data = set.getMetaData();
int count = data.getColumnCount();
ArrayList<StatUnit<?>> units = new ArrayList<>();
  for(int i = 1; i <= count; i++){
  Function<ResultSet, ?> fun = StatItem.getMethod(data.getColumnTypeName(i), data.getColumnLabel(i));
  if(isLifetime && data.getColumnLabel(i).equals("game")){
    units.add(new StatUnit<>(p, data.getColumnLabel(i), gameId, "ls", isLifetime));
    continue;
  }else if(isLifetime && data.getColumnLabel(i).equals("was_winner")){
    units.add(new StatUnit<>(p, data.getColumnLabel(i), countGames(p, true), "ls", isLifetime));
    continue;
  }
  if(isLifetime && fun.apply(set) instanceof Integer){
    units.add(new StatUnit<>(p, data.getColumnLabel(i), sumColumns(data.getColumnLabel(i), p), "ls", isLifetime));
    continue;
  }
  units.add(new StatUnit<>(p, data.getColumnLabel(i), fun.apply(set), "ls", isLifetime));
  set.next();
}

Though the values it gets are alway null and I don't know why.

supple tinselBOT
#

<@&987246584574140416> please have a look, thanks.

supple tinselBOT
#

@latent osprey

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍

latent osprey
#

does anyone know what could cause this?

nova night
#

Don't you have to move to the next row first with a ResultSet?

#

I think it starts before the first row

#

ah nvm, you do that

#

Well, without the rest of the code it's hard to tell

nova night
#

while(result.next())

latent osprey
#

ok, I'll try that