Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PSQLException: Can't infer the SQL type ... Use setObject() (I am using it!)

Hi maybe I can get some help here once again! I am testing a server to connect to a DB and so far it works and I can insert UUID Data. But when I try to migrate to another project, the same function doesn't work as it should. It doesn't save the data in the DB...I have checked everything but there must be something I haven't notice that's bugging... any help or direction will be greatly appreciate.

package ...


imports ...

@Path("/UserPoints")
public class getNewPoints {

    @Path("/getNewPoints")
    @GET
    @Produces(MediaType.TEXT_PLAIN)

    public Response getUserPoints(@QueryParam("user_id") UUID username,
                                   @QueryParam("point_id") int pointId,
                                   @QueryParam("earned_points") int points
    ) {
        try {
            if (username == null)
                throw new Exception("Invalid data");
            else {
                Class.forName("org.postgresql.Driver");
                Connection connection  = DriverManager.getConnection(DBURL,DBUSER, DBPASS);
                PreparedStatement statement = connection.prepareStatement(SQLQuery.getQuery("new_earned_points"));
                statement.setObject(1, UUID.fromString(username.toString()));  //THIS WORKS IN THE ORIGINAL PROJECT
                statement.setInt(2, pointId);
                statement.setInt(3, points);
                statement.executeUpdate();
                statement.close();
                System.out.println("points.. on get New Points... " + points);
            }

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
        return Response.status(Response.Status.OK).entity("new points added to user " + pointId).build();
    }

}

Solution After checking the stacktrace I notice the postgresql version was an old one... so I updated it in the pom and then it worked.

like image 497
EdC Avatar asked Dec 30 '25 20:12

EdC


1 Answers

I'm posting the answer which was edited into the original question:

Solution After checking the stacktrace I notice the postgresql version was an old one... so I updated it in the pom and then it worked.

like image 66
payne Avatar answered Jan 01 '26 10:01

payne