Example usage for java.sql Timestamp toString

List of usage examples for java.sql Timestamp toString

Introduction

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

Prototype

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

Source Link

Document

Formats a timestamp in JDBC timestamp escape format.

Usage

From source file:Main.java

public static long[] getEntryExit(Double id, Calendar date, Connection con, PreparedStatement stmt)
        throws Exception {
    stmt.setDate(1, new java.sql.Date(date.getTimeInMillis()));
    // stmt.setDate(2, new java.sql.Date(date.getTimeInMillis()+1000000));
    stmt.execute();//from  w  w w.j ava2s .  co  m
    ResultSet rs = stmt.getResultSet();
    if (rs != null) {

        if (rs.next()) {
            Timestamp d1 = rs.getTimestamp(1);
            Timestamp d2 = rs.getTimestamp(2);
            if (d1 != null && d2 != null) {
                System.out.println(id + ":" + new SimpleDateFormat("dd/MM/yyyy").format(date.getTime()) + ":"
                        + d1.toString());
                long[] res = new long[] { d1.getTime(), d2.getTime() };
                return res;
            }
        }
        rs.close();
    }
    return null;
}

From source file:org.jamwiki.utils.XMLUtil.java

/**
 * Utiltiy method for building an XML tag of the form <tagName>value</tagName>.
 *
 * @param tagName The name of the XML tag, such as <tagName>value</tagName>.
 * @param tagValue The value of the XML tag, such as <tagName>value</tagName>.
 * @return An XML representations of the tagName and tagValue parameters.
 */// w w w . ja v a2  s . com
public static String buildTag(String tagName, Timestamp tagValue) {
    return (tagValue == null) ? "" : XMLUtil.buildTag(tagName, tagValue.toString(), false);
}

From source file:org.apache.ode.dao.jpa.bpel.BpelDAOConnectionImpl.java

private static String dateFilter(String filter) {
    String date = Filter.getDateWithoutOp(filter);
    String op = filter.substring(0, filter.indexOf(date));
    Date dt = null;/*w  ww .j av  a  2s.c  o  m*/
    try {
        dt = ISO8601DateParser.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Timestamp ts = new Timestamp(dt.getTime());
    return op + " '" + ts.toString() + "'";
}

From source file:org.projectforge.common.StringHelper.java

public static String timestampToSearchString(final Timestamp timestamp) {
    if (timestamp == null) {
        return "";
    }/* w w w  .  j  a  v  a 2  s .co m*/
    return timestamp.toString();
}

From source file:flow.visibility.pcap.FlowProcess.java

/** function to create internal frame contain flow sequence */

public static JInternalFrame FlowSequence() {

    final StringBuilder errbuf = new StringBuilder(); // For any error msgs  
    final String file = "tmp-capture-file.pcap";

    //System.out.printf("Opening file for reading: %s%n", file);  

    /*************************************************************************** 
     * Second we open up the selected file using openOffline call 
     **************************************************************************/
    Pcap pcap = Pcap.openOffline(file, errbuf);

    if (pcap == null) {
        System.err.printf("Error while opening device for capture: " + errbuf.toString());
    }/*from  w  ww.j a  va  2  s. co  m*/

    /** create blank internal frame */

    JInternalFrame FlowSequence = new JInternalFrame("Flow Sequence", true, true, true, true);
    FlowSequence.setBounds(601, 0, 600, 660);
    JTextArea textArea3 = new JTextArea(50, 10);
    PrintStream printStream3 = new PrintStream(new CustomOutputStream(textArea3));
    System.setOut(printStream3);
    System.setErr(printStream3);
    JScrollPane scrollPane3 = new JScrollPane(textArea3);
    FlowSequence.add(scrollPane3);

    /** Process to print the packet one by one */

    JPacketHandler<String> jpacketHandler = new JPacketHandler<String>() {

        public void nextPacket(JPacket packet, String user) {
            final JCaptureHeader header = packet.getCaptureHeader();
            Timestamp timestamp = new Timestamp(header.timestampInMillis());
            Tcp tcp = new Tcp();
            Udp udp = new Udp();
            Icmp icmp = new Icmp();
            Ip4 ip4 = new Ip4();
            Ethernet ethernet = new Ethernet();

            /** For IP Packet */

            if (packet.hasHeader(ip4)) {

                if (packet.hasHeader(tcp)) {
                    System.out.println(timestamp.toString() + " :  [TCP]  :  " + FormatUtils.ip(ip4.source())
                            + ":" + tcp.source() + "->" + FormatUtils.ip(ip4.destination()) + ":"
                            + tcp.destination());
                }
                if (packet.hasHeader(udp)) {
                    System.out.println(timestamp.toString() + " :  [UDP]  :  " + FormatUtils.ip(ip4.source())
                            + ":" + udp.source() + "->" + FormatUtils.ip(ip4.destination()) + ":"
                            + udp.destination());
                }
                if (packet.hasHeader(icmp)) {
                    System.out.println(timestamp.toString() + " : [ICMP]  :  " + FormatUtils.ip(ip4.source())
                            + "->" + FormatUtils.ip(ip4.destination()) + ":" + icmp.type());
                }

            }

            /** For Ethernet Packet */

            else if (packet.hasHeader(ethernet)) {
                System.out.println(timestamp.toString() + " :  [ETH]  :  " + FormatUtils.mac(ethernet.source())
                        + "->" + FormatUtils.mac(ethernet.destination()) + ":" + ethernet.type());

            }
        }
    };

    Pcap pcap4 = Pcap.openOffline(file, errbuf);

    /** Redirect the Output into Frame Text Area */

    FlowSequence.setVisible(true);
    pcap4.loop(Pcap.LOOP_INFINITE, jpacketHandler, null);
    FlowSequence.revalidate();
    pcap4.close();

    return FlowSequence;

}

From source file:org.apache.hadoop.hive.ql.exec.vector.VectorizedBatchUtil.java

public static StringBuilder debugFormatOneRow(VectorizedRowBatch batch, int index, String prefix,
        StringBuilder sb) {//from  w  ww .  j  av  a  2  s . co  m
    sb.append(prefix + " row " + index + " ");
    for (int p = 0; p < batch.projectionSize; p++) {
        int column = batch.projectedColumns[p];
        sb.append("(" + p + "," + column + ") ");
        ColumnVector colVector = batch.cols[column];
        if (colVector == null) {
            sb.append("(null ColumnVector)");
        } else {
            boolean isRepeating = colVector.isRepeating;
            if (isRepeating) {
                sb.append("(repeating)");
            }
            index = (isRepeating ? 0 : index);
            if (colVector.noNulls || !colVector.isNull[index]) {
                if (colVector instanceof LongColumnVector) {
                    sb.append(((LongColumnVector) colVector).vector[index]);
                } else if (colVector instanceof DoubleColumnVector) {
                    sb.append(((DoubleColumnVector) colVector).vector[index]);
                } else if (colVector instanceof BytesColumnVector) {
                    BytesColumnVector bytesColumnVector = (BytesColumnVector) colVector;
                    byte[] bytes = bytesColumnVector.vector[index];
                    int start = bytesColumnVector.start[index];
                    int length = bytesColumnVector.length[index];
                    if (bytes == null) {
                        sb.append("(Unexpected null bytes with start " + start + " length " + length + ")");
                    } else {
                        sb.append("bytes: '" + displayBytes(bytes, start, length) + "'");
                    }
                } else if (colVector instanceof DecimalColumnVector) {
                    sb.append(((DecimalColumnVector) colVector).vector[index].toString());
                } else if (colVector instanceof TimestampColumnVector) {
                    Timestamp timestamp = new Timestamp(0);
                    ((TimestampColumnVector) colVector).timestampUpdate(timestamp, index);
                    sb.append(timestamp.toString());
                } else if (colVector instanceof IntervalDayTimeColumnVector) {
                    HiveIntervalDayTime intervalDayTime = ((IntervalDayTimeColumnVector) colVector)
                            .asScratchIntervalDayTime(index);
                    sb.append(intervalDayTime.toString());
                } else {
                    sb.append("Unknown");
                }
            } else {
                sb.append("NULL");
            }
        }
        sb.append(" ");
    }
    return sb;
}

From source file:uk.ac.kcl.partitioners.RealtimePKRangePartitioner.java

private Map<String, ExecutionContext> handleNoNewRecords(Timestamp startTimeStamp) {
    if (firstRun) {
        logger.info("No new data found from configured start time " + startTimeStamp.toString());
        informJobCompleteListenerOfLastDate(startTimeStamp);
    } else {//  ww w .  j a va  2s .co m
        logger.info("Database appears to be synched as far as " + startTimeStamp.toString() + ". "
                + "Checking again on next run");
        informJobCompleteListenerOfLastDate(startTimeStamp);
    }
    return new HashMap<>();
}

From source file:bookUtilities.PopulateReservedBooksServlet.java

private JSONArray getReservedBooks(String email) {
    String query;//  www.j  ava 2 s .  c o m
    JSONArray jsons = new JSONArray();
    try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw");
        Statement st = con.createStatement();
        query = "SELECT Book.*, reservedBooks.ReserveDate "
                + "FROM [HardCover].[dbo].[Book] Book, [HardCover].[dbo].[RegisteredUser] RegisteredUser, [HardCover].[dbo].[ReservedBook] reservedBooks, [HardCover].[dbo].[Person] P "
                + "WHERE Book.BookUuid = reservedBooks.BookId AND reservedBooks.RegisteredUserId = RegisteredUser.RegisteredUserId AND P.PersonUuid = RegisteredUser.RegisteredUserId "
                + " AND P.Email = '" + email + "'";

        ResultSet rs = st.executeQuery(query);
        while (rs.next()) {
            JSONObject bookToAdd = new JSONObject();
            Statement st2 = con.createStatement();
            Timestamp timeStamp = rs.getTimestamp("ReserveDate");
            String timeString = timeStamp.toString();
            String bookId = rs.getString("BookUuid");

            query = "SELECT AuthorName " + "FROM [HardCover].[dbo].[Author] " + "WHERE BookId = '" + bookId
                    + "';";
            ResultSet rs2 = st2.executeQuery(query);
            rs2.next();
            bookToAdd.put("reserveDate", timeString);
            bookToAdd.put("author", rs2.getString("AuthorName"));
            bookToAdd.put("title", rs.getString("Title"));
            bookToAdd.put("cover", rs.getString("Cover"));
            bookToAdd.put("dateAdded", rs.getString("DateAdded"));
            bookToAdd.put("numCopies", rs.getString("NumCopies"));
            bookToAdd.put("bookId", rs.getString("BookUuid"));
            jsons.add(bookToAdd);
        }

    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    return jsons;
}

From source file:com.microsoft.sqlserver.testframework.sqlType.SqlDateTime2.java

public Object createdata() {
    Timestamp temp = new Timestamp(ThreadLocalRandom.current().nextLong(((Timestamp) minvalue).getTime(),
            ((Timestamp) maxvalue).getTime()));
    temp.setNanos(0);/*from  w w w .  ja  va  2s .c  om*/
    String timeNano = temp.toString().substring(0, temp.toString().length() - 1)
            + RandomStringUtils.randomNumeric(this.precision);
    // can pass string rather than converting to LocalDateTime, but leaving
    // it unchanged for now to handle prepared statements
    return LocalDateTime.parse(timeNano, formatter);
}

From source file:isl.FIMS.servlet.export.ExportSchema.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w  w w .  jav a 2s.  c om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    this.initVars(request);
    String username = getUsername(request);

    boolean isGuest = this.getRights(username).equals("guest");
    if (!isGuest) {
        try {
            String filePath = this.export_import_Folder;
            java.util.Date date = new java.util.Date();
            Timestamp t = new Timestamp(date.getTime());
            String currentDir = filePath + t.toString().replaceAll(":", "").replaceAll("\\s", "");
            File saveDir = new File(currentDir);
            saveDir.mkdir();
            Config conf = new Config("ExportSchema");
            String type = request.getParameter("type");
            request.setCharacterEncoding("UTF-8");

            ServletOutputStream outStream = response.getOutputStream();
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=\"" + "Schema_" + type + ".zip\"");
            File schemaFile = new File(this.schemaFolder + type + ".xsd");
            FileUtils.copyFile(schemaFile,
                    new File(currentDir + System.getProperty("file.separator") + type + ".xsd"));
            Utils.copySchemaReferences(this.schemaFolder + type + ".xsd", currentDir);

            File f = new File(currentDir + System.getProperty("file.separator") + "zip");
            f.mkdir();
            String zip = f.getAbsolutePath() + System.getProperty("file.separator") + "Schema_" + type + ".zip";

            Utils.createZip(zip, currentDir);
            Utils.downloadZip(outStream, new File(zip));

            Utils.deleteDir(currentDir);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}