Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException occurs when executing PreparedStatement execute #104

Closed
codering opened this issue Oct 13, 2023 · 1 comment · Fixed by #105 or #112
Closed

NullPointerException occurs when executing PreparedStatement execute #104

codering opened this issue Oct 13, 2023 · 1 comment · Fixed by #105 or #112
Assignees

Comments

@codering
Copy link

    // NullPointerException
    @Test
    public void testPrepareStatementQuery() throws SQLException {
        String sql = "SELECT number from numbers(100) where number = ?";
        try(PreparedStatement statement  = conn.prepareStatement(sql)) {
            statement.setInt(1, 1);
            ResultSet r = statement.executeQuery();
            r.next();
            Assertions.assertEquals(1, r.getLong("number"));
        }
    }

     // NullPointerException
    @Test
    public void testPrepareStatementExecute() throws SQLException {
        String sql = "SELECT number from numbers(100) where number = ?";
        try(PreparedStatement statement  = conn.prepareStatement(sql)) {
            statement.setInt(1, 1);
            statement.execute();
            ResultSet r = statement.getResultSet();
            r.next();
            Assertions.assertEquals(1, r.getLong("number"));
        }
    }

     //  Not execute
    @Test
    public void testPrepareStatementExecuteUpdate() throws SQLException {
        String sql = "insert into ta values (?)";
        try(PreparedStatement statement  = conn.prepareStatement(sql)) {
            statement.setInt(1, ThreadLocalRandom.current().nextInt(1, 10));
            int result = statement.executeUpdate();
            Assertions.assertEquals(1, result);
        }
    }

These method implementations should follow the PreparedStatement interface definition.

image image
@hantmac hantmac self-assigned this Oct 13, 2023
@hantmac
Copy link
Member

hantmac commented Oct 13, 2023

Hi @codering , thanks for your issue! I will look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants