Example usage for java.sql Date toString

List of usage examples for java.sql Date toString

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public String toString() 

Source Link

Document

Formats a date in the date escape format yyyy-mm-dd.

Usage

From source file:Main.java

public static void main(String[] args) {
    java.util.Date javaDate = new java.util.Date();
    long javaTime = javaDate.getTime();
    System.out.println("The Java Date is: " + javaDate.toString());

    java.sql.Date sqlDate = new java.sql.Date(javaTime);
    System.out.println("The SQL DATE is: " + sqlDate.toString());

    java.sql.Time sqlTime = new java.sql.Time(javaTime);
    System.out.println("The SQL TIME is: " + sqlTime.toString());

    java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(javaTime);
    System.out.println("The SQL TIMESTAMP is: " + sqlTimestamp.toString());
}

From source file:Main.java

public static void main(String[] args) {
    java.util.Date javaDate = new java.util.Date();
    long javaTime = javaDate.getTime();
    System.out.println("The Java Date is:" + javaDate.toString());

    // SQL DATE/* ww  w.j  a v a 2  s.c  om*/
    java.sql.Date sqlDate = new java.sql.Date(javaTime);
    System.out.println("The SQL DATE is: " + sqlDate.toString());

    // SQL TIME
    java.sql.Time sqlTime = new java.sql.Time(javaTime);
    System.out.println("The SQL TIME is: " + sqlTime.toString());

    // SQL TIMESTAMP
    java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(javaTime);
    System.out.println("The SQL TIMESTAMP is: " + sqlTimestamp.toString());
}

From source file:Main.java

public static String getYearMonthDay2() {

    java.util.Date date1 = new java.util.Date();
    java.sql.Date date3 = new java.sql.Date(date1.getTime());
    return date3.toString();
}

From source file:Main.java

public static String getYearMonthDay1() {

    java.sql.Date date2 = new java.sql.Date(System.currentTimeMillis());
    return date2.toString();
}

From source file:Main.java

public static String getDateDes(Date date) {
    if (date == null) {
        return null;
    }/*w w  w .  j  a  v a2s. co  m*/
    return date.toString();
}

From source file:Main.java

public static String changeStringToDate2(String str) {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.util.Date date6 = null;/*from www .j av  a 2 s.co  m*/
    try {
        date6 = sdf.parse(str);
        java.sql.Date date7 = new java.sql.Date(date6.getTime());
        return date7.toString();
    } catch (ParseException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:RSMetaData.java

public static void getData(ResultSet rs, int type, int colIdx) throws SQLException {
    switch (type) {
    case java.sql.Types.CHAR:
    case java.sql.Types.VARCHAR:
        System.out.println(rs.getString(colIdx));
        break;//from w  w w.j  a  va2 s .  co m

    case java.sql.Types.INTEGER:
        int i = rs.getInt(colIdx);
        System.out.println(i);
        break;

    case java.sql.Types.NUMERIC:
        BigDecimal bd = rs.getBigDecimal(colIdx);
        System.out.println(bd.toString());
        break;

    case java.sql.Types.TIMESTAMP:
    case java.sql.Types.DATE:
        java.sql.Date d = rs.getDate(colIdx);
        System.out.println(d.toString());
        break;

    }
}

From source file:com.trackplus.ddl.DataReader.java

public static void writeDataToSql(DatabaseInfo databaseInfo, String dirName) throws DDLException {
    LOGGER.info("Exporting SQL data from \"" + databaseInfo.getUrl() + "\" ...");
    Map<String, String> info = new TreeMap<String, String>();
    java.util.Date d1 = new java.util.Date();
    info.put("start", d1.toString());
    info.put("driver", databaseInfo.getDriver());
    info.put("url", databaseInfo.getUrl());
    info.put("user", databaseInfo.getUser());
    info.put("user", databaseInfo.getUser());
    info.put("usePassword", Boolean.toString(databaseInfo.getPassword() != null));
    String databaseType = MetaDataBL.getDatabaseType(databaseInfo.getUrl());
    info.put(DATABASE_TYPE, databaseType);

    Connection connection = getConnection(databaseInfo);
    //log the database meta data information's
    logDatabaseMetaDataInfo(databaseInfo, connection);

    String[] versions = MetaDataBL.getVersions(connection);
    info.put(SYSTEM_VERSION, versions[0]);
    info.put(DB_VERSION, versions[1]);//from w  w  w .  java 2s . c o  m

    StringValueConverter stringValueConverter = new GenericStringValueConverter();

    BufferedWriter writer = createBufferedWriter(dirName + File.separator + FILE_NAME_DATA);
    BufferedWriter writerUpdate = createBufferedWriter(dirName + File.separator + FILE_NAME_DATA_UPDATE);
    BufferedWriter writerClean = createBufferedWriter(dirName + File.separator + FILE_NAME_DATA_CLEAN);
    BufferedWriter writerUpdateClean = createBufferedWriter(
            dirName + File.separator + FILE_NAME_DATA_UPDATE_CLEAN);
    BufferedWriter writerBlob = createBufferedWriter(dirName + File.separator + FILE_NAME_BLOB);

    int idx = 0;
    String[] tableNames = MetaDataBL.getTableNames();
    for (String tableName : tableNames) {
        LOGGER.debug("Processing table: " + tableName + "....");
        int count = getTableData(writer, writerClean, writerUpdate, writerUpdateClean, connection, tableName,
                stringValueConverter);
        info.put("_" + tableName, count + "");
        LOGGER.debug("Records exported:" + count + "\n");
        idx = idx + count;
    }
    LOGGER.debug("Processing blob data ....");
    int count = getBlobTableData(writerBlob, connection);
    LOGGER.debug(" Blob record exported:" + count + "\n");
    info.put("table_BLOB", count + "");
    idx = idx + count;

    try {
        char dataSeparator = (char) ASCII_DATA_SEPARATOR;
        writerBlob.write(dataSeparator);
        writerBlob.newLine();
        writerBlob.newLine();
        writerBlob.write("--TMSPROJECTEXCHANGE");
        writerBlob.newLine();
    } catch (IOException e) {
        LOGGER.error("Error on close blob stream file :" + e.getMessage());
        throw new DDLException(e.getMessage(), e);
    }

    LOGGER.debug("Processing clob data ....");
    count = getClobTableData(writerBlob, connection);
    LOGGER.debug(" Clob record exported:" + count + "\n");
    info.put("table_TMSPROJECTEXCHANGE", count + "");
    idx = idx + count;
    info.put("allData", idx + "");

    try {
        writer.flush();
        writer.close();

        writerClean.flush();
        writerClean.close();

        writerUpdate.flush();
        writerUpdate.close();

        writerUpdateClean.flush();
        writerUpdateClean.close();

        writerBlob.flush();
        writerBlob.close();
    } catch (IOException e) {
        LOGGER.error("Error on close stream file: " + e.getMessage());
        throw new DDLException(e.getMessage(), e);
    }

    try {
        connection.close();
    } catch (SQLException e) {
        throw new DDLException(e.getMessage(), e);
    }

    java.util.Date d2 = new java.util.Date();
    long timeSpend = d2.getTime() - d1.getTime();
    info.put("timeSpend", Long.toString(timeSpend));

    writeInfoToFile(info, dirName + File.separator + FILE_NAME_INFO);
    LOGGER.info("Data generated. All records found: " + idx + ". Time spend: " + timeSpend + " ms!");
}

From source file:org.kuali.kfs.module.purap.util.ElectronicInvoiceUtils.java

public static String getDateDisplayText(java.util.Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);/*from  www. j  av  a  2  s  .  c  o m*/
    // we add one to the month below because January = 0, February = 1, March = 2, and so on
    String monthPart = (c.get(Calendar.MONTH) + 1) + "";
    String dayPart = c.get(Calendar.DATE) + "";
    if (monthPart.length() == 1) {
        monthPart = "0" + monthPart;
    }

    if (dayPart.length() == 1) {
        dayPart = "0" + dayPart;
    }

    String useDate = monthPart + "/" + dayPart + "/" + c.get(Calendar.YEAR);
    String actualDate = (date != null) ? date.toString() : "empty given date";
    return useDate;
}

From source file:org.apache.hadoop.hive.ql.udf.UDFToString.java

public String evaluate(java.sql.Date i) {
    if (i == null) {
        return null;
    } else {//from   www .j a  va 2s  . c  o  m
        return i.toString();
    }
}