#Auction plugin help
1 messages · Page 1 of 1 (latest)
Thanks for starting this thread. However, I don't have much experience working with databases other than MongoDB and a bit of MySQL. Can you suggest how I can filter out non-expired items from the database?
SQLite shouldn't be much different from MySQL
SELECT * FROM auction_items WHERE date BETWEEN '2023-05-01' AND '2023-05-02'
Something like that
// Load the SQLite JDBC driver
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
System.err.println("Could not load SQLite JDBC driver.");
e.printStackTrace();
return;
}
// Connect to the SQLite database
try (Connection connection = DriverManager.getConnection("jdbc:sqlite:database.db")) {
// Create a statement to query the database
try (Statement statement = connection.createStatement()) {
// Calculate the timestamp 24 hours ago
LocalDateTime now = LocalDateTime.now();
LocalDateTime twentyFourHoursAgo = now.minus(24, ChronoUnit.HOURS);
long timestampTwentyFourHoursAgo = twentyFourHoursAgo.toEpochSecond(ZoneOffset.UTC);
// Query the database for entries with a TimeStamp value that is not expired (less than 24 hours old)
String query = "SELECT * FROM table WHERE TimeStamp > " + timestampTwentyFourHoursAgo + ";";
try (ResultSet resultSet = statement.executeQuery(query)) {
// Process the results
while (resultSet.next()) {
// Retrieve the columns from the result set and process them as needed
int id = resultSet.getInt("id");
String someColumn = resultSet.getString("some_column");
long timeStamp = resultSet.getLong("TimeStamp");
// Do something with the retrieved data
System.out.println("ID: " + id + ", Some Column: " + someColumn + ", TimeStamp: " + timeStamp);
}
}
}
} catch (Exception e) {
System.err.println("Error while connecting to the SQLite database or querying it.");
e.printStackTrace();
}
}
What do you think about something like this?
Is that from ChatGPT