Re: Right version of jdbc - Mailing list pgsql-general

From Raivo Rebane
Subject Re: Right version of jdbc
Date
Msg-id CAMH5fpu8i2C94Whwcx7t-K3a0d6khFziThxNXa8OvLZ=LOjvrg@mail.gmail.com
Whole thread Raw
In response to Re: Right version of jdbc  (Ron <ronljohnsonjr@gmail.com>)
Responses Re: Right version of jdbc  (Dave Cramer <davecramer@postgres.rocks>)
List pgsql-general
Hi,

The code is :
package MushroomAPIs;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;

@WebServlet("/AddMushrooms")
public class AddMushrooms extends HttpServlet implements java.io.Serializable {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

final String DB_URL = "jdbc:postgresql://localhost:5432/mushroom_database";
final String USER = "mushroomer";
final String PASSWORD = "";

Connection connection = null;
Timestamp LastModifiedTS = Timestamp.valueOf("1970-01-01 00:00:00");

try {
connection = DriverManager.getConnection(DB_URL, USER, PASSWORD);

// SQL päring vanima timestamp-i leidmiseks
String query = "SELECT timestamp AS oldest_timestamp FROM mushrooms";
PreparedStatement statement = connection.prepareStatement(query);
ResultSet resultSet = statement.executeQuery();

while (resultSet.next()) {
Timestamp oldest_timestamp = resultSet.getTimestamp("oldest_timestamp");
if (oldest_timestamp.after(LastModifiedTS))
LastModifiedTS = oldest_timestamp;
}
System.out.println("Vanim timestamp: " + LastModifiedTS);

} catch (SQLException e) {
e.printStackTrace();
}

int count = ProcAddMushrooms.GetAddMushrooms(connection, LastModifiedTS);

response.getWriter().println("Added " + count + " mushrooms");
}
}
and available from github - https://github.com/raaivore/APIexperiment

May be somebody can help me to solve the problem ?

Raivo

On Fri, Sep 29, 2023 at 6:44 AM Ron <ronljohnsonjr@gmail.com> wrote:
On 9/28/23 01:18, Raivo Rebane wrote:
[snip]
I made a new Java application Eclipse Dynamic WEB application and want to use Postgres - PostgreSQL 10.14
[snip]
What's wrong. Or is better to use more newer postgres. And then which jdbc-I need to use ?

https://www.postgresql.org/support/versioning/

Pg 10 will be EOL in 6 weeks.  Thus, "yes, use a newer version of Postgresql" (unless, like me, you're constrained by circumstances like "the business won't let us upgrade").

Pg 15 and the latest JDBC are in the repositories: https://www.postgresql.org/download/

--
Born in Arizona, moved to Babylonia.

pgsql-general by date:

Previous
From: Vladimir Sitnikov
Date:
Subject: Re: [EXT] YNT: Need help tuning a query
Next
From: Dave Cramer
Date:
Subject: Re: Right version of jdbc