Reputation: 225
I have a Java database set up in NetBeans 7, connected to it, but my query turns up null.
My database is named Questioneer
, and the table is named QNTABLE
, under the APP folder in the services tab.
I used the query
query = "select QNNAME from QNTABLE"; // (QNNAME is a field name) with the statement:
Statement st = dbConn.createStatement();
ResultSet rs = st.executeQuery(query);
with this, but st
and rs
turned up as null.
Upvotes: 1
Views: 2729
Reputation: 12069
Check your query
variable. Maybe you're using double '
instead of "
or a single '
.
Upvotes: 0
Reputation: 1499870
Your code won't compile, as Java uses " for string literals, not ''.
Your diagnostics are certainly off, as if st
is null then the final line will throw a NullPointerException
.
Basically, you should re-examine not just your code, but how you're approaching it. Work out whether you're really running the code you think you are, and how you're checking the values of variables.
If you have instance variables called st
and rs
and they're being hidden by local variables called st
and rs
, that could explain some of the confusion.
Upvotes: 3