Java and SQL...
How do I get class 1 to talk to the databasehandler (class 2) and extract all of the primary key numbers?
All the code I can think of uses the key to get the other data... but I want to list everything in the database in various ways in various class based windows...
The way I have been doing it
debug.append(StockData.getName(key));
calling
public static String getName(String key) {
try {
ResultSet res = stmt.executeQuery("SELECT * FROM StockDB WHERE stockID = '" + key + "'");
if (res.next()) { // there is a result
return res.getString(2);
} else {
return null;
}
} catch (SQLException e) {
System.out.println(e);
return null;
}
}
Which works just fine. But I've been manually adding the keys to save time... which is fine if the database were never to change size, but pretty annoying if it did change as I'd have to hard code in all the new calls for it... and on one text field I want to list all the primary keys anyway.
All the online examples I'm looking at connect to, query and print within the same class so the syntax is not right so I'm getting befuddled
Comments
My YouTube Channel
Afraid I'm not geek enough for this Myranda! Good luck
Do you want the code to know how many entities there is?
Seriously: If you value it, take/fetch it yourself
In which case you just need to remove the where part of your query
Offset "(Emp) - a little heavy on the hyperbole."
"Nobody is really researching robot jokes"
# do something
end