insert null into Integer column using JDBC - code improvements

This commit is contained in:
Mladen Savic
2021-06-03 12:26:02 +02:00
parent 239da42aab
commit 07af5a2687
2 changed files with 6 additions and 14 deletions
@@ -1,11 +1,9 @@
package com.baeldung.insertnull;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Test;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import static org.hamcrest.CoreMatchers.equalTo;
@@ -16,7 +14,7 @@ public class InsertNullUnitTest {
private final String SQL = "INSERT INTO Person VALUES(?,?,?,?)";
@Test
public void givenNewPerson_whenSetNullIsUsed_thenNewRecordIsCreated() throws Exception {
public void givenNewPerson_whenSetNullIsUsed_thenNewRecordIsCreated() throws SQLException {
Person person = new Person(1, "John", "Doe", null);
try (PreparedStatement preparedStatement = DBConfig.getConnection().prepareStatement(SQL)) {
@@ -30,12 +28,11 @@ public class InsertNullUnitTest {
int noOfRows = preparedStatement.executeUpdate();
assertThat(noOfRows, equalTo(1));
} catch (Exception ignored) {
}
}
@Test
public void givenNewPerson_whenSetObjectIsUsed_thenNewRecordIsCreated() throws Exception {
public void givenNewPerson_whenSetObjectIsUsed_thenNewRecordIsCreated() throws SQLException {
Person person = new Person(2, "John", "Doe", null);
try (PreparedStatement preparedStatement = DBConfig.getConnection().prepareStatement(SQL)) {
@@ -46,7 +43,6 @@ public class InsertNullUnitTest {
int noOfRows = preparedStatement.executeUpdate();
assertThat(noOfRows, equalTo(1));
} catch (Exception ignored) {
}
}
}