Displaying files on selection of date.

Ads
 

Displaying files on selection of date.

Hi,

I am developing a GUI, where i select from and to date. On selection of from and to date the GUI should show the particular txt files of the selected date. I want the java logic for same.

View Answers

September 6, 2012 at 4:57 PM

Here is a java swing code that accepts two dates and search in the database for files.

import java.awt.*;
import java.sql.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

class FetchDataBetweenTwoDates{
    public static void main(String[] args) {
        final Vector columnNames = new Vector();
        final Vector data = new Vector();

        JLabel lab1=new JLabel("Enter From Date(yyyy-mm-dd):");
        final JTextField t1=new JTextField(20);
        JLabel lab2=new JLabel("Enter To Date(yyyy-mm-dd):");
        final JTextField t2=new JTextField(20);
        JButton b = new JButton("Search File");
        final JTable table=new JTable();
        final JScrollPane pane=new JScrollPane(table);

        JFrame f = new JFrame();
        f.setLayout(null);
        lab1.setBounds(10,10,100,20);
        t1.setBounds(120,10,100,20);
        lab2.setBounds(10,40,100,20);
        t2.setBounds(120,40,100,20);
        b.setBounds(120,70,120,20);
        pane.setBounds(10,100,480,170);
        pane.setVisible(false);
        f.add(lab1);
        f.add(t1);
        f.add(lab2);
        f.add(t2);
        f.add(b);
        f.add(pane);
        pane.setVisible(false);
        f.setSize(500,300);
        f.setVisible(true);


        b.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){
            try{
           Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           String d1 = t1.getText();
           String d2 = t2.getText();
           ResultSet rs=st.executeQuery("Select file_name,dateOfFile from myfile where dateOfFile between '"+d1+"' and '"+d2+"'");
           ResultSetMetaData md = rs.getMetaData();
            int columns = md.getColumnCount();
            for (int i = 1; i <= columns; i++){
            columnNames.addElement(md.getColumnName(i) );
            }
            while(rs.next()){
            Vector row = new Vector(columns);
            for (int i = 1; i <= columns; i++){
            row.addElement( rs.getObject(i) );
            }
            data.addElement(row);
           }
           DefaultTableModel model=new DefaultTableModel(data, columnNames);
           table.setModel(model);
           pane.setVisible(true);
            }
            catch(Exception ex){
            System.out.println(ex);
            }
          }
        });
    }
}

Ads









Related Tutorials/Questions & Answers:
Displaying files on selection of date.
Displaying files on selection of date.  Hi, I am developing a GUI, where i select from and to date. On selection of from and to date the GUI should show the particular txt files of the selected date. I want the java logic
Displaying date in the preciding code
Displaying date in the preciding code  while deploying the Bill date field on this page are empty though it should be displayed String userName = request.getParmeter("userName"); String custId = request.getParameter("customerId
Advertisements
ModuleNotFoundError: No module named 'files-by-date'
ModuleNotFoundError: No module named 'files-by-date'  Hi, My... 'files-by-date' How to remove the ModuleNotFoundError: No module named 'files-by-date' error? Thanks   Hi, In your python
codes for displaying in calendar
codes for displaying in calendar  can i get jsp codes for displaying comments, when the pointer is placed over the particular date in calendar
files
/core/files/storeobjectsinFile.html
displaying image
displaying image  how to upload image and retrieve it form database...; $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size
date
date   how to insert date in database? i need coding
displaying data
displaying data   how to display data from database on jsp using struts2
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  i want difference between the date entered in a jtextfield and the system date in java
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
Image is not displaying
Image is not displaying  Hii i am using spring javamail with html template to send mail,i am facing that image displaying prob when mail have to cm in gmail,in template just i am giving my current location of image which
date
database table name birthday (DOB date); dob with DATE data type in database while...=d.getTime(); java.sql.Date date = new java.sql.Date(t); try { System.out.println(date); Class.forName("oracle.jdbc.OracleDriver"); con
DATE
DATE  I have the following as my known parameter Effective Date... of calcultion starts My question is how to find the date of Thursday This cycle... the date of all the thursdays of the given year. import java.util.*; import
intersection of two files
intersection of two files  hi!could you please provide me with the java program for displaying intersection of two files
Selection based on other selection in jsp
Selection based on other selection in jsp  I am trying to create a jsp page. Where I am having a select list containing category name and for each... selection on same jsp page such that when someone select a category only the products
date picker
date picker  where i have to kept javascript ,css files and images in eclipse... please tell me the location
PHP Displaying URL Content
PHP Displaying URL Content  In my PHP application form, on submitting the form details it always displaying url content. Can anyone tell me what is the reason and how to restrict it from displaying
Java current date - How to get current date in Java
In this section, you will learn about displaying current date and time in Java
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
displaying a physical webpage with frames in iframe
displaying a physical webpage with frames in iframe  i have iframe... files in iframe.each folder has a index.html.now i need to display the index.html..."); } }; File[] files = directory.listFiles(fileFilter); for (int index = 0; index <
Displaying file from database
Displaying file from database  I have list of files in my database. I want to display these files in browser according to the input. My need is like google search result. when i click on the link it should display
ModuleNotFoundError: No module named 'selection'
ModuleNotFoundError: No module named 'selection'  Hi, My Python... 'selection' How to remove the ModuleNotFoundError: No module named 'selection' error? Thanks   Hi, In your python environment you
(Displaying a calendar in GUI
(Displaying a calendar in GUI  (Displaying a calendar) Write a program that displays the calendar for the current month, as Use labels, and set texts on the labels to display the calendar."The Calendar and GregorianCalendar
Javascript get Date And Selected Option Text
Javascript get Date And Selected Option Text In this tutorial we will learn about how to get Date from the textbox and displayed as Date as well as how... explains you that how to display the date and the selected option text in Javascript
autocomplete displaying multiple fields
autocomplete displaying multiple fields  How can I create an autocomplete with three field (name, id, phone). Placing the phone field in the appropriate input field but selecting the name field into the 'calling' input box
Displaying java.util.Calendar using JSP struts tags
Displaying java.util.Calendar using JSP struts tags  My question is in regard to displaying a date whose source is java.util.Calendar... and display it as <s:date name="todayDate" format="yyyy-MM-dd" />

Ads