#PreparedStatement.getResults() returning null

1 messages · Page 1 of 1 (latest)

pale copper
#

I'm using Hikari for my MySql DB and I'm trying to query stuff but for some reason, the getResultSet() method returns null even though it shouldn't according to the method docstring. Here's the part of the docstring: returns: the current result as a ResultSet object or null if the result is an update count or there are no more results and here's the chunk of code the error's triggered in: PreparedStatement input = connection.prepareStatement("SELECT uuid FROM Connections WHERE ip = '" + ip + "'"); ResultSet set = input.getResultSet(); while (set.next()) { out.add(set.getString("uuid")); }

#

Sorry if I'm being dumb but if someone knows, please lmk why it's returning null

atomic lintel
#

im not sure if this code is actually right

#

but might be because of the difference between the driver's version

#

but here is one of my code that works:

PreparedStatement ps = // preparestatement code here
ps.codehere();
ResultSet rs = ps.executeQuery();
if (if.next()) {
    //code here
}
pale copper
#

Thing is, most times I've used the same technique and it's worked

atomic lintel
#

wdym

pale copper
#

Like, not had an issue with this: PreparedStatement input = connection.prepareStatement("SELECT ip FROM Connections WHERE uuid = '" + uuid + "'"); ResultSet set = input.executeQuery(); while (set.next()) { out.add(set.getString("ip")); }

atomic lintel
#

oh wait you mean your code?

pale copper
#

Yeah, my other functions are working fine

atomic lintel
#

where uuid probably should not be "", instead set it to ?

pale copper
#

Oh shoot, just realised

#

I never executed the query ;-;

atomic lintel
#
PreparedStatement ps = connection().prepareStatement("SELECT `ip` FROM `Connections` WHERE `uuid` = ?");
ps.setString(1, uuid);
atomic lintel
pale copper
#

It might be, lemme test xD

#

It would make sense, ffs

atomic lintel
#

well yes, executing query is always required. I remember I had many issues when I forgot to execute the query. I was so angry when I realsed the error. xD

#

But one thing I learned: if it says it has errors in it, it really is debugged. XD

pale copper
#

Ugh. That's why I always add "sorry if I'm being dumb" in my messages. Because 80% of the time when I get stuck, it's because I'm being dumb

atomic lintel
#

I don't think you're dumb, you just... forget to add lines.

#

and... that is actually normal.

pale copper
#

I know but there's lack of knowledge and then there's...

#

A lack of noticing xD

atomic lintel
#

Y E S xd

#

totally relatable

#

xd

pale copper
#

And, naturally, it works fine now. It was that I didn't execute it ;-;

#

Anyway thanks for your help