Example usage for java.sql Date Date

List of usage examples for java.sql Date Date

Introduction

In this page you can find the example usage for java.sql Date Date.

Prototype

public Date(long date) 

Source Link

Document

Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Usage

From source file:com.petclinic.entity.mysql.Visit.java

/**
 * Creates a new instance of Visit for the current date
 */
public Visit() {
    this.date = new Date(System.currentTimeMillis());
}

From source file:com.sap.dirigible.repository.db.dao.DBMapper.java

/**
 * ResultSet current row to DB Repository transformation
 * //from  ww  w.  j  a  v a  2  s .c  om
 * @param repository
 * @param resultSet
 * @return
 * @throws SQLException
 * @throws DBBaseException
 */
static DBObject dbToObject(DBRepository repository, ResultSet resultSet) throws SQLException, DBBaseException {

    String name = resultSet.getString(FILE_NAME);
    String path = resultSet.getString(FILE_PATH);
    int type = resultSet.getInt(FILE_TYPE);
    String content = resultSet.getString(FILE_CONTENT_TYPE);
    String createdBy = resultSet.getString(FILE_CREATED_BY);
    Date createdAt = new Date(resultSet.getTimestamp(FILE_CREATED_AT).getTime());
    String modifiedBy = resultSet.getString(FILE_MODIFIED_BY);
    Date modifiedAt = new Date(resultSet.getTimestamp(FILE_MODIFIED_AT).getTime());

    DBObject dbObject = null;
    if (type == OBJECT_TYPE_FOLDER) {
        dbObject = new DBFolder(repository);
    } else if (type == OBJECT_TYPE_DOCUMENT) {
        dbObject = new DBFile(repository, false, content);
    } else if (type == OBJECT_TYPE_BINARY) {
        dbObject = new DBFile(repository, true, content);
    } else {
        throw new DBBaseException(Messages.getString("DBMapper.THE_OBJECT_IS_UNKNOWN")); //$NON-NLS-1$
    }

    dbObject.setName(name);
    dbObject.setPath(path);
    dbObject.setCreatedBy(createdBy);
    dbObject.setCreatedAt(new java.util.Date(createdAt.getTime()));
    dbObject.setModifiedBy(modifiedBy);
    dbObject.setModifiedAt(new java.util.Date(modifiedAt.getTime()));

    return dbObject;
}

From source file:cz.fi.muni.pa165.dao.AlbumDaoImplementationTest.java

@BeforeMethod
public void setUpClass() {
    metallica = new Musician();
    acdc = new Musician();
    avicii = new Musician();
    dio = new Musician();

    metallica.setRealName("James Hetfield");
    metallica.setArtistName("Metallica");
    metallica.setDateOfBirth(new Date(123));

    acdc.setRealName("Brian Johnson");
    acdc.setArtistName("AC-DC");
    acdc.setDateOfBirth(new Date(456));

    avicii.setRealName("Tim Bergling");
    avicii.setArtistName("Avicii");
    avicii.setDateOfBirth(new Date(789));

    dio.setRealName("Ronnie James Dio");
    dio.setArtistName("Dio");
    dio.setDateOfBirth(new Date(666));

    musicianDao.create(metallica);/*from   w w  w  .  j ava 2s . com*/
    musicianDao.create(acdc);
    musicianDao.create(avicii);
    musicianDao.create(dio);

    albumOne = new Album();
    albumTwo = new Album();
    albumOne.setTitle("album one");
    albumTwo.setTitle("album two");
    albumOne.setMusician(metallica);
    albumOne.setReleaseDate(new Date(0));
    albumTwo.setReleaseDate(new Date(0));
    albumTwo.setMusician(metallica);
}

From source file:app.order.OrderMetier.java

@Override
public void newOrder(Customer customer) {
    this.order = (Order) GenericController.context.getBean(Order.class);
    this.order.setCustomer(customer);
    this.order.setUser(this.user);//TODO
    this.order.setShippingDate(new Date(Calendar.getInstance().getTime().getTime()));
    this.order.setCreationDate(this.order.getShippingDate());//TODO

    orderlineMetier.setOrder(this.order);

    //makePersistent(order);
    customer.addOrder(order);//from   w  ww  .  j  a v a 2s .  c o m
}

From source file:bq.jpa.demo.inherit.join.service.InheritJoinService.java

public void prepareDate() {
    // contract/*w  w w. ja  v a  2  s .  c  o m*/
    for (int i = 0; i < 10; i++) {
        ContractEmployee contractEmployee = new ContractEmployee();
        contractEmployee.setName("contractor_" + i);
        contractEmployee.setTerm(i);
        contractEmployee.setDailyRate(10 * i);
        contractEmployee.setStartDate(new Date(System.currentTimeMillis()));
        em.persist(contractEmployee);
    }

    for (int i = 0; i < 10; i++) {
        FullTimeEmployee fulltimeEmployee = new FullTimeEmployee();
        fulltimeEmployee.setName("fulltime_" + i);
        fulltimeEmployee.setPension(1000 * i);
        fulltimeEmployee.setSalary(300 * i);
        fulltimeEmployee.setVacation(2 * i);
        fulltimeEmployee.setStartDate(new Date(System.currentTimeMillis()));
        em.persist(fulltimeEmployee);
    }

    for (int i = 0; i < 10; i++) {
        PartTimeEmployee parttimeEmployee = new PartTimeEmployee();
        parttimeEmployee.setName("parttime_" + i);
        parttimeEmployee.setHourlyRate(10 * i);
        parttimeEmployee.setVacation(3 * i);
        parttimeEmployee.setStartDate(new Date(System.currentTimeMillis()));
        em.persist(parttimeEmployee);
    }
}

From source file:adalid.commons.util.TimeUtils.java

public static synchronized Date currentDate() {
    calendar.setTimeInMillis(currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return new Date(calendar.getTimeInMillis());
}

From source file:com.matthewmitchell.wakeifyplus.database.AlarmCursorAdapter.java

@Override
public void bindView(View v, Context context, Cursor c) {

    final String name = c.getString(c.getColumnIndex("name"));
    final long time = c.getLong(c.getColumnIndex("time"));

    TextView time_text = (TextView) v.findViewById(R.id.time);
    if (time_text != null) {
        time_text.setText(date_format.format(new Date(time)));
    }//from www . ja  va2  s  .co  m

    TextView name_text = (TextView) v.findViewById(R.id.name);
    if (name_text != null) {
        name_text.setText(name);
    }

    // Do on/off button alarm code

    CompoundButton onOff = (CompoundButton) v.findViewById(R.id.alarm_switch);
    // Make sure the change listener is not set for setting value from database.
    onOff.setOnCheckedChangeListener(null);
    onOff.setChecked(c.getInt(c.getColumnIndex("onOff")) == 1);
    final Context contextl = context;
    final long id = c.getInt(c.getColumnIndex("_id"));
    onOff.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            AlarmDatabase database = new AlarmDatabase(contextl);
            SQLiteDatabase write = database.getWritableDatabase();
            ContentValues values = new ContentValues(1);
            if (isChecked) {
                // Alarm has been turned on
                values.put("onOff", 1);
                // Add system alarm
                AlarmReceiver.scheduleAlarm(contextl, id, false);
            } else {
                // Alarm has been switched off
                values.put("onOff", 0);
                AlarmReceiver.removeAlarm(contextl, id);
            }
            write.update(AlarmDatabase.ALARMS_TABLE, values, "_id = " + id, null);
            write.close();
            database.close();
            // Reload cursor
            main.getSupportLoaderManager().restartLoader(0, null, main);
        }

    });
}

From source file:edu.br.model.dao.FormularioDAO.java

public boolean cadastroFormu(Formulario formulario) {
    String bd = "INSERT INTO formulario(nome, matricula, email, telefone, titulo_proj, orientador,"
            + "curso, nivel_medio, nivel_superior, data_solicitacao, corrigido)"
            + "VALUES(?,?,?,?,?,?,?,?,?,?,?)";
    System.out.println("ti" + formulario.getTitulo());
    try (PreparedStatement ps = conexaobd.prepareStatement(bd)) {
        ps.setString(1, formulario.getUsuario());
        ps.setString(2, formulario.getMatricula());
        ps.setString(3, formulario.getEmail());
        ps.setString(4, formulario.getContato());
        ps.setString(5, formulario.getTitulo());
        ps.setString(6, formulario.getOrientador());
        ps.setString(7, formulario.getCurso());
        ps.setString(8, formulario.getMedio());
        ps.setString(9, formulario.getSuperior());
        ps.setDate(10, new Date(formulario.getData().getTime()));
        ps.setString(11, "nao");

        int testar = ps.executeUpdate();
        if (testar == 1) {
            return true;

        }/* w  w w  . j a  va2 s  . co m*/
    } catch (SQLException e) {
        Logger.getLogger(FormularioDAO.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        if (conexaobd != null) {
            try {
                conexaobd.close();
            } catch (SQLException ex) {
                Logger.getLogger(FormularioDAO.class.getName()).log(Level.SEVERE, null, ex);
            }
            System.out.println("Desconectado!");
        }
    }
    return false;
}

From source file:io.heming.accountbook.util.Importer.java

public int importRecords(File file) throws Exception {
    Iterable<CSVRecord> csvRecords;
    List<Record> records = new ArrayList<>();
    try (Reader in = new FileReader(file)) {
        csvRecords = CSVFormat.EXCEL.withQuote('"')
                .withHeader("ID", "CATEGORY", "PRICE", "PHONE", "DATE", "NOTE").parse(in);
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        // ??/* w  w w  .  j a v  a  2s . c o m*/
        categoryFacade.clear();
        int i = 0;
        for (CSVRecord csvRecord : csvRecords) {
            Integer id = Integer.parseInt(csvRecord.get("ID"));
            Category category = new Category(csvRecord.get("CATEGORY"));
            Double price = Double.parseDouble(csvRecord.get("PRICE"));
            String phone = csvRecord.get("PHONE");
            Date date = new Date(format.parse(csvRecord.get("DATE")).getTime());
            String note = csvRecord.get("NOTE");
            // category?
            if (!categoryFacade.list().contains(category)) {
                categoryFacade.add(category);
            }
            Record record = new Record(category, price, phone, date);
            record.setId(id);
            record.setNote(note);
            records.add(record);
        }
    }

    // ??
    recordFacade.clear();
    int i = 0;
    int total = records.size();
    for (Record record : records) {
        recordFacade.add(record);
    }
    return records.size();
}

From source file:dialog.DialogFunctionUser.java

private void actionAddUserNoController() {
    if (!isValidData()) {
        return;/*from w w  w .  j av  a2  s .c o m*/
    }
    if (isExistUsername(tfUsername.getText())) {
        JOptionPane.showMessageDialog(null, "Username  tn ti", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    String username = tfUsername.getText();
    String fullname = tfFullname.getText();
    String password = new String(tfPassword.getPassword());
    password = LibraryString.md5(password);
    int role = cbRole.getSelectedIndex();
    User objUser;
    if (mAvatar != null) {
        objUser = new User(UUID.randomUUID().toString(), username, password, fullname, role,
                new Date(System.currentTimeMillis()), mAvatar.getPath());
        String fileName = FilenameUtils.getBaseName(mAvatar.getName()) + "-" + System.nanoTime() + "."
                + FilenameUtils.getExtension(mAvatar.getName());
        Path source = Paths.get(mAvatar.toURI());
        Path destination = Paths.get("files/" + fileName);
        try {
            Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException ex) {
            Logger.getLogger(DialogFunctionRoom.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        objUser = new User(UUID.randomUUID().toString(), username, password, fullname, role,
                new Date(System.currentTimeMillis()), "");
    }
    if ((new ModelUser()).addItem(objUser)) {
        ImageIcon icon = new ImageIcon(getClass().getResource("/images/ic_success.png"));
        JOptionPane.showMessageDialog(this.getParent(), "Thm thnh cng", "Success",
                JOptionPane.INFORMATION_MESSAGE, icon);
    } else {
        JOptionPane.showMessageDialog(this.getParent(), "Thm tht bi", "Fail",
                JOptionPane.ERROR_MESSAGE);
    }
    this.dispose();
}