Displaying files on selection of date.

Ads

 
 

Share on Google+Share on Google+

monica suresh patil
Displaying files on selection of date.
1 Answer(s)      5 years and a month ago
Posted in : Java Beginners

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.

Ads
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 jsp - JDBC
Displaying Date in jsp  I want to insert Date of birth of a person... to interact with database.My JSP code for inserting Date is below: String dateStr... SimpleDateFormat("dd-MM-yyyy "); Date result = formater.parse(dateStr
Advertisements
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
Displaying System Files in JTree
Displaying System Files in JTree     ... that displays system files. The java.util.properties package represents a persistent set of properties for displaying the system files in a tree. Description
Displaying Date in Servlet
Displaying Date in Servlet     ... a current date and time on our browser. It is very easy to display it on our browser by using the Date class of the java.util package.  As we know that the our
How to copy files from one folder to another based on lastmodified date - Java Beginners
Copy files from one folder to another  How to copy files from one folder to another based on lastmodified date
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
files
/core/files/storeobjectsinFile.html
files
files  write a java program to calculate the time taken to read a given number of files. file names should be given at command line.   Hello Friend, Try the following code: import java.io.*; import java.util.*; class
PHP Displaying the date and time in your timezone Tutorial
PHP Date Time Zone       In PHP Date Time Zone class displays the time of different time zone, along with time it is also capable of displaying the longitude, latitude and comment
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
How to copy files from one folder to another based on lastmodified date - Java Beginners
How to copy files from one folder to another based on lastmodified date  I have to make a simple utility to copy files from a folder to another...("Multiple files are not allow."); System.exit(0
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
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
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
Help With Costructing Selection sort?
Help With Costructing Selection sort?  Using a selection sort, for each entry in the array, display the original index of the first dimension... in advance!   Please visit the following link: Java Selection Sort
interrelated two selection box
interrelated two selection box  hi i need two selection box .in 1 box all designation like manager, ceo etc , onclick on manager i should get list of managers names in second selection box.. like wise so on. from database
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
Selection Using JoptionPane
Selection Using JoptionPane  Help, can someone provide me the code using JOptionPane for the following:- Part A 1) Prompt user to make 3 selection... Modify the above application so that if user makes a selection that the user has
highlight uitableviewcell on selection
the UITableViewCell on selection in my application.   UITableViewCell... highlight it or use the default selection for the cell in UITableView. Also you can disable the the stye by setting StyleNone to cell selection. But in case
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
checkbox selection in jsp
checkbox selection in jsp  hey guys i am working on a web based project using jsp. In my project i am having 9 check boxes in 3 rows in the same form. I want to select i check box from each row and also i want to avoid many