'Java Jersey CRUD operation POST not working giving 500 Internal Server Error

When I try to retrieve the data from my database using postman I get this error:

enter image description here

What is the cause of this error, is it dependency problem or the code I have made not working properly, here is my code:

Student Resource

   @Path("/retrieve")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public ArrayList<Student> getStudent() throws Exception
    {
        StudentService studentService = new StudentService();
        return studentService.getStudent();
    }

StudentService

 public ArrayList<Student> getStudent() throws Exception {

        ArrayList<Student> data = new ArrayList<Student>();
        Connection connection = null;
        try {
            connection = new MysqlDbConnectionService().getConnection();

            String select = "select * from users";
            PreparedStatement ps = connection.prepareStatement(select);
            ResultSet rs = ps.executeQuery();

            Student model = null;

            while (rs.next()) {
                model = new Student();
                model.setId(rs.getString("user_id"));
                model.setUsername(rs.getString("username"));
                model.setPassword(rs.getString("password"));
                model.setFullName(rs.getString("fullname"));
                model.setEmail(rs.getString("email"));
                data.add(model);
            }
        } catch(Exception e)
        {
            System.out.println(e + "Retrieve not successful");
        }
        return data;
    }

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>com.vogella.jersey.first</display-name>
    <servlet>
        <servlet-name>First Servlet</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.resources</param-value>
        </init-param>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.common.Application</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>



    </servlet>
    <servlet-mapping>
        <servlet-name>First Servlet</servlet-name>
        <url-pattern>/*</url-pattern>

    </servlet-mapping>




    <welcome-file-list>
        <welcome-file>home.html</welcome-file>
        <welcome-file>default.html</welcome-file>

    </welcome-file-list>

</web-app>

Pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>WebJava</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>WebJava</name>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
        <junit.version>5.8.1</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>2.25.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.9.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider -->
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
            <version>2.13.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.28</version>
        </dependency>


<!--         https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson-->
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>3.0.4</version>
        </dependency>




    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.2</version>
            </plugin>


            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.4.45.v20220203</version>
            </plugin>
        </plugins>
    </build>
</project>

Is there a dependency problem or the best solution should be to create a new project and add the code there again? Thank you in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source