This is a very broad question, but I'm having trouble with the entire concept of Objects, mapping mysql table with objects, and how would I map my data, which is a resultset to that object.
So I' don't know how to go about creating an Object, mapping mysql table to that object, and storing data into that object. Let's say I have a table with the following rows:
String sql = "CREATE TABLE IF NOT EXISTS `mocha` ( " +
" `id` INT NOT NULL AUTO_INCREMENT ," +
"`uuid` VARCHAR(255) NOT NULL ," +
" `join_message` VARCHAR(255) NOT NULL ," +
" `quit_message` VARCHAR(255) NOT NULL ," +
" `change_points` INT NOT NULL," +
" `last_modified` TIMESTAMP NOT NULL," +
" PRIMARY KEY (`id`)" +
")";
And a method getting data:
private ResultSet getDataWithUUID(String uuid) {
String sqlPlayer = "SELECT * FROM `mocha` WHERE `uuid` = ?";
ResultSet rs[] = new ResultSet[1];
try (PreparedStatement q = conn.connect().prepareStatement(sqlPlayer)) {
q.setString(1, uuid);
rs[0] = q.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
return rs[0];
}
Which is bad, because, well, I shouldn't be passing around resultsets (In-fact this doesn't even work)
How do I do this properly? What classes would I create? What would the java class look like for the object?
I'm so confused and I have no idea how this works.