Guest User

Untitled

a guest
Sep 8th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. public final class TestDerbyJDBI {
  2.  
  3. @Test
  4. public void testNullValueInQuery() throws SQLException {
  5. DBI dbi = new DBI("jdbc:derby:memory:TestDatabase;create=true");
  6. TestDAO dao = dbi.open(TestDAO.class);
  7. dao.createTestTable();
  8. dao.insertMessage(1, "message1");
  9. dao.insertMessage(2, null);
  10. }
  11.  
  12. public interface TestDAO {
  13. @SqlUpdate("create table testtable (id integer, message varchar(512))")
  14. void createTestTable();
  15.  
  16. @SqlUpdate("insert into testtable (id, message) values (:id,:message)")
  17. void insertMessage(@Bind("id") int id, @Bind("message") String message);
  18. }
  19. }
  20.  
  21. public final class TestDerbyJDBC {
  22.  
  23. @Test
  24. public void testNullValueInQuery() throws SQLException {
  25. Connection connection = DriverManager.getConnection("jdbc:derby:memory:TestDatabase;create=true");
  26. connection.createStatement().executeUpdate("create table testtable (id integer, message varchar(512))");
  27.  
  28. PreparedStatement statement = connection.prepareStatement("insert into testtable (id, message) values (?,?)");
  29.  
  30. statement.clearParameters();
  31. statement.setInt(1, 1);
  32. statement.setString(2, null);
  33. statement.executeUpdate();
  34. }
  35. }
Add Comment
Please, Sign In to add comment