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

@Deprecated
public Date(int year, int month, int date) 

Source Link

Document

Allocates a Date object and initializes it so that it represents midnight, local time, at the beginning of the day specified by the year , month , and date arguments.

Usage

From source file:utilities.itext.Turnover.java

public static void main(String[] args) {
    Date begin = new Date(2014 - 1900, 9, 1);
    Date end = new Date(2014 - 1900, 10, 30);
    createTurnOver("November 2014", StatisticType.CATEGORY, begin, end);
}

From source file:gui.statistics.PieChartTest.java

/**
 * Creates new form PieChartTest/*from  ww  w  .  j  av a2 s . c o m*/
 */
public PieChartTest(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    Date a = new Date(2014 - 1900, 11, 1);
    Date b = new Date(2014 - 1900, 11, 31);
    DefaultPieDataset data = new DefaultPieDataset();
    HashMap<String, BigDecimal> map = Database.getInstance().getTotalExpensesByCategory(a, b);

    for (String key : map.keySet()) {
        data.setValue(key, map.get(key).doubleValue());
    }

    JFreeChart pieChart = ChartFactory.createPieChart("PIE CHART", data, true, false, Locale.GERMAN);
    PiePlot plot = (PiePlot) pieChart.getPlot();
    plot.setLabelGenerator(null);

    BufferedImage pie = pieChart.createBufferedImage(500, 400);
    setSize(600, 500);
    jLabel1.setIcon(new ImageIcon(pie));
}

From source file:org.hellospring4.controller.DemoController.java

@RequestMapping(value = "holamundo.php", method = RequestMethod.GET)
public String holaMundo(Model model) {
    User user = new User();
    user.setEmail("user@example.com");
    user.setFname("Spring");
    user.setLname("Tester");
    user.setRegdate(new Date(2014, 07, 04));

    dao.create(user);//  ww  w. j  a  va2  s  .  co  m
    user = dao.find(1);
    System.out.println("\n\nUser name: " + user.getFname() + "\n" + user.getEmail());
    return "paginaHolaMundo";
}

From source file:br.com.fatecpg.repositories.mysql.MySqlLogRepository.java

@Override
public void add(Log log) {
    if (log == null) {
        throw new IllegalArgumentException("log can't be null.");
    }/*from   ww w  .j a v  a2s .  c  om*/

    String sql = "insert into log (applicationName, message, url, ipaddress, username, createdon, details) values (?, ?, ?, ?, ?, ?, ?)";
    Connection connection = dbProvider.getConnection();

    try {

        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, log.getApplicationName());
        preparedStatement.setString(2, log.getMessage());
        preparedStatement.setString(3, log.getUrl());
        preparedStatement.setString(4, log.getIpAddress());
        preparedStatement.setString(5, log.getUsername());

        Date sqlDate = new Date(log.getCreatedDate().getYear(), log.getCreatedDate().getMonth(),
                log.getCreatedDate().getDay());

        preparedStatement.setDate(6, sqlDate);
        preparedStatement.setString(7, log.getDetails());

        preparedStatement.execute();

    } catch (SQLException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:de.interseroh.report.parameter.BirtConvertingTest.java

@Test
public void testFromStringToDate() throws Exception {
    LocaleContextHolder.setLocale(Locale.US);
    Date converted = conversionService.convert("1/22/15", Date.class);
    assertThat(converted, is(new Date(115, 0, 22)));
}

From source file:de.interseroh.report.parameter.BirtConvertingTest.java

@Test
public void testFromDateToString() throws Exception {
    LocaleContextHolder.setLocale(Locale.US);
    String converted = conversionService.convert(new Date(115, 0, 22), String.class);
    assertThat(converted, is("1/22/15"));
}

From source file:com.splicemachine.db.iapi.types.SQLDateTest.java

@Test
public void serdeKeyData() throws Exception {
    GregorianCalendar gc = new GregorianCalendar();
    SQLDate value1 = new SQLDate(new Date(97, 9, 7));
    SQLDate value2 = new SQLDate(new Date(97, 10, 7));
    SQLDate value1a = new SQLDate();
    SQLDate value2a = new SQLDate();
    PositionedByteRange range1 = new SimplePositionedMutableByteRange(value1.encodedKeyLength());
    PositionedByteRange range2 = new SimplePositionedMutableByteRange(value2.encodedKeyLength());
    value1.encodeIntoKey(range1, Order.ASCENDING);
    value2.encodeIntoKey(range2, Order.ASCENDING);
    Assert.assertTrue("Positioning is Incorrect",
            Bytes.compareTo(range1.getBytes(), 0, 9, range2.getBytes(), 0, 9) < 0);
    range1.setPosition(0);/*from w w  w. j  a v a  2s  .com*/
    range2.setPosition(0);
    value1a.decodeFromKey(range1);
    value2a.decodeFromKey(range2);
    Assert.assertEquals("1 incorrect", value1.getDate(gc), value1a.getDate(gc));
    Assert.assertEquals("2 incorrect", value2.getDate(gc), value2a.getDate(gc));
}

From source file:br.com.atmatech.sac.webService.WebServiceFinanceiro.java

public List<FinanceiroBeans> getFinanceiro(String url, String user, String password) throws IOException {
    String chave = "";
    HttpPost post = new HttpPost(url);
    boolean result = false;
    /* Configura os parmetros do POST */
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("login", user));
    nameValuePairs.add(new BasicNameValuePair("senha", password));
    nameValuePairs.add(new BasicNameValuePair("x", "26"));
    nameValuePairs.add(new BasicNameValuePair("y", "26"));
    post.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8));
    // post.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0");
    HttpResponse response = client.execute(post);
    // System.out.println("Login form get: " + response.getStatusLine());
    EntityUtils.consume(response.getEntity());
    HttpPost get = new HttpPost("http://atma.serveftp.com/atma/view/index.php?page=BAIXAR&mostrar=1");
    get.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8));
    response = client.execute(get);//from  w w w.j a v  a 2s . co  m
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String line;
    //        // Grava pagina no arquivo
    FileWriter out = new FileWriter("./logfin.txt");
    PrintWriter gravarArq = new PrintWriter(out);
    int indexant = 11;
    boolean doc = true;
    boolean cliente = true;
    boolean valor = true;
    boolean vencimento = true;
    boolean contato = true;
    boolean tel = true;
    String tdoc = "";
    String tcliente = "";
    float tvalor = 0;
    Date tvencimento = null;
    String tcontato = "";
    String ttel = "";
    List<FinanceiroBeans> lfb = new ArrayList<>();
    while ((line = rd.readLine()) != null) {
        if (line.contains("<tr><td>")) {
            //gravarArq.print(line+"\n");
            line = line.replace("<tr><td>", "\n").replace("</td></tr>", "\n");
            line = line.replace("</td><td>", ";")
                    .replace("</td><td align='center'><a class='btn default' target='_blank'", ";")
                    .replace("</i></a>", ":");
            gravarArq.print(line + "\n");
            for (int i = 0; i < line.length(); i++) {
                if (doc && (indexant != i)) {
                    if (line.charAt(i) == ';') {
                        tdoc = line.substring(indexant + 1, i);
                        indexant = i;
                        doc = false;
                    }
                } else {
                    if ((!doc) && (cliente) && (indexant != i)) {
                        if (line.charAt(i) == ';') {
                            tcliente = line.substring(indexant + 1, i);
                            indexant = i;
                            cliente = false;
                        }
                    } else {
                        if ((!doc) && (!cliente) && (valor) && (indexant != i)) {
                            if (line.charAt(i) == ';') {
                                tvalor = Float.valueOf(line.substring(indexant + 1, i));
                                indexant = i;
                                valor = false;
                            }
                        } else {
                            if ((!doc) && (!cliente) && (!valor) && (vencimento) && (indexant != i)) {
                                if (line.charAt(i) == ';') {
                                    String data = line.substring(indexant + 1, i).replace("/", ".");
                                    int ind1 = data.indexOf(".");
                                    int ind2 = data.indexOf(".", ind1 + 1);
                                    String dd = data.substring(0, ind1);
                                    String mm = data.substring(ind1 + 1, ind2);
                                    String yyyy = data.substring(ind2 + 1);
                                    tvencimento = new Date(Integer.parseInt(yyyy) - 1900,
                                            Integer.parseInt(mm) - 1, Integer.parseInt(dd));
                                    indexant = i;
                                    vencimento = false;
                                }
                            } else {
                                if ((!doc) && (!cliente) && (!valor) && (!vencimento) && (contato)
                                        && (indexant != i)) {
                                    if (line.charAt(i) == ';') {
                                        tcontato = line.substring(indexant + 1, i);
                                        indexant = i;
                                        contato = false;
                                    }
                                } else {
                                    if ((!doc) && (!cliente) && (!valor) && (!vencimento) && (!contato) && (tel)
                                            && (indexant != i)) {
                                        if (line.charAt(i) == ';') {
                                            ttel = line.substring(indexant + 1, i);
                                            indexant = i;
                                            tel = false;
                                        }
                                    } else {
                                        if ((!doc) && (!cliente) && (!valor) && (!vencimento) && (!contato)
                                                && (!tel) && (line.charAt(i) == ':')) {
                                            indexant = i + 2;
                                            FinanceiroBeans fb = new FinanceiroBeans();
                                            fb.setCliente(tcliente);
                                            fb.setContato(tcontato);
                                            fb.setDoc(tdoc);
                                            fb.setTelcel(ttel);
                                            fb.setValor(tvalor);
                                            fb.setVencimento(tvencimento);
                                            lfb.add(fb);
                                            doc = true;
                                            cliente = true;
                                            valor = true;
                                            vencimento = true;
                                            contato = true;
                                            tel = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

    }
    out.close();
    return lfb;
}

From source file:org.apache.sqoop.hcat.HCatalogExportTest.java

public void testDateTypes() throws Exception {
    final int TOTAL_RECORDS = 1 * 10;
    String table = getTableName().toUpperCase();
    ColumnGenerator[] cols = new ColumnGenerator[] {
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(0), "date", Types.DATE,
                    HCatFieldSchema.Type.STRING, 0, 0, "2013-12-31", new Date(113, 11, 31), KeyType.NOT_A_KEY),
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(1), "date", Types.DATE,
                    HCatFieldSchema.Type.DATE, 0, 0, new Date(113, 11, 31), new Date(113, 11, 31),
                    KeyType.NOT_A_KEY),//  ww  w .  ja  va 2s  .  co m
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(2), "time", Types.TIME,
                    HCatFieldSchema.Type.STRING, 0, 0, "10:11:12", new Time(10, 11, 12), KeyType.NOT_A_KEY),
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(3), "timestamp", Types.TIMESTAMP,
                    HCatFieldSchema.Type.STRING, 0, 0, "2013-12-31 10:11:12",
                    new Timestamp(113, 11, 31, 10, 11, 12, 0), KeyType.NOT_A_KEY),
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(4), "timestamp", Types.TIMESTAMP,
                    HCatFieldSchema.Type.TIMESTAMP, 0, 0, new Timestamp(113, 11, 31, 10, 11, 12, 0),
                    new Timestamp(113, 11, 31, 10, 11, 12, 0), KeyType.NOT_A_KEY), };
    List<String> addlArgsArray = new ArrayList<String>();
    runHCatExport(addlArgsArray, TOTAL_RECORDS, table, cols);
}

From source file:org.apache.sqoop.hcat.HCatalogExportTest.java

public void testDateTypesToBigInt() throws Exception {
    final int TOTAL_RECORDS = 1 * 10;
    long offset = TimeZone.getDefault().getRawOffset();
    String table = getTableName().toUpperCase();
    ColumnGenerator[] cols = new ColumnGenerator[] {
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(0), "date", Types.DATE,
                    HCatFieldSchema.Type.BIGINT, 0, 0, 0 - offset, new Date(70, 0, 1), KeyType.NOT_A_KEY),
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(1), "time", Types.TIME,
                    HCatFieldSchema.Type.BIGINT, 0, 0, 36672000L - offset, new Time(10, 11, 12),
                    KeyType.NOT_A_KEY),/*  w  ww .ja  v  a 2s.  c  o  m*/
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(2), "timestamp", Types.TIMESTAMP,
                    HCatFieldSchema.Type.BIGINT, 0, 0, 36672000L - offset,
                    new Timestamp(70, 0, 1, 10, 11, 12, 0), KeyType.NOT_A_KEY), };
    List<String> addlArgsArray = new ArrayList<String>();
    addlArgsArray.add("--map-column-hive");
    addlArgsArray.add("COL0=bigint,COL1=bigint,COL2=bigint");
    runHCatExport(addlArgsArray, TOTAL_RECORDS, table, cols);
}