@After
 public void dispose() throws SQLException, IOException, ClassNotFoundException {
   Connection connection = BddConnecteur.getConnection();
   Statement statement = connection.createStatement();
   statement.execute("DROP TABLE Creneau");
   statement.execute("DROP TABLE Atelier");
   statement.execute("DROP TABLE Labo");
   statement.execute("DROP TABLE Utilisateur");
   statement.close();
   connection.close();
   BddConnecteur.dispose();
 }
예제 #2
0
  @Test
  public void timestamp() throws SQLException {
    connectWithJulianDayModeActivated();
    long now = System.currentTimeMillis();
    Timestamp d1 = new Timestamp(now);
    Date d2 = new Date(now);
    Time d3 = new Time(now);

    stat.execute("create table t (c1);");
    PreparedStatement prep = conn.prepareStatement("insert into t values (?);");
    prep.setTimestamp(1, d1);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select c1 from t;");
    assertTrue(rs.next());
    assertEquals(d1, rs.getTimestamp(1));

    rs = stat.executeQuery("select date(c1, 'localtime') from t;");
    assertTrue(rs.next());
    assertEquals(d2.toString(), rs.getString(1));

    rs = stat.executeQuery("select time(c1, 'localtime') from t;");
    assertTrue(rs.next());
    assertEquals(d3.toString(), rs.getString(1));

    rs = stat.executeQuery("select strftime('%Y-%m-%d %H:%M:%f', c1, 'localtime') from t;");
    assertTrue(rs.next());
    // assertEquals(d1.toString(), rs.getString(1)); // ms are not occurate...
  }
예제 #3
0
 @Test
 public void changeSchema() throws SQLException {
   stat.execute("create table t (c1);");
   PreparedStatement prep = conn.prepareStatement("insert into t values (?);");
   conn.createStatement().execute("create table t2 (c2);");
   prep.setInt(1, 1000);
   prep.execute();
   prep.executeUpdate();
 }
예제 #4
0
  @Test
  public void date2() throws SQLException {
    Date d1 = new Date(1092941466000L);
    stat.execute("create table t (c1);");
    PreparedStatement prep =
        conn.prepareStatement("insert into t values (datetime(?/1000, 'unixepoch'));");
    prep.setDate(1, d1);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select strftime('%s', c1) * 1000 from t;");
    assertTrue(rs.next());
    assertEquals(d1.getTime(), rs.getLong(1));
    assertTrue(rs.getDate(1).equals(d1));
  }
예제 #5
0
  @SuppressWarnings("deprecation")
  @Test
  public void time() throws SQLException {
    connectWithJulianDayModeActivated();
    Time d1 = new Time(System.currentTimeMillis());

    stat.execute("create table t (c1);");
    PreparedStatement prep = conn.prepareStatement("insert into t values (?);");
    prep.setTime(1, d1);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select c1 from t;");
    assertTrue(rs.next());
    assertEquals(d1.getHours(), rs.getTime(1).getHours());
    assertEquals(d1.getMinutes(), rs.getTime(1).getMinutes());
    assertEquals(d1.getSeconds(), rs.getTime(1).getSeconds());
  }
예제 #6
0
  @Test
  public void date1() throws SQLException {
    Date d1 = new Date(987654321);

    stat.execute("create table t (c1);");
    PreparedStatement prep = conn.prepareStatement("insert into t values(?);");
    prep.setDate(1, d1);
    prep.executeUpdate();
    prep.setDate(1, null);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select c1 from t;");
    assertTrue(rs.next());
    assertEquals(d1.getTime(), rs.getLong(1));
    assertTrue(rs.getDate(1).equals(d1));
    assertTrue(rs.next());
    assertEquals(null, rs.getDate(1));
    rs.close();
  }