Home Answers Viewqa Java-Beginners Displaying files on selection of date.

 
 


monica suresh patil
Displaying files on selection of date.
1 Answer(s)      8 months 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.

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);
            }
          }
        });
    }
}









Related Pages:
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
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
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 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
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
displaying in ajax - Ajax
displaying in ajax  hi.. I have an Ajax page ,request gone to server... the current date and time from server and shows on the form. To view the current date and time click on the following button
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
Modifying a single row of database based on selection in jsp
Modifying a single row of database based on selection in jsp  Hi guys, i have a problem, I am Fetching the results from database and displaying in a row with s3everal columns, each row having a radio button and a value
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
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 <
JSP - Problem of displaying result at webpage
JSP - Problem of displaying result at webpage  Can anyone please help to solve my problem below. My webpage has problem in displaying result position...'><div class='divCellDT'>DATE/TIME</div>
intersection of two files
intersection of two files  hi!could you please provide me with the java program for displaying intersection of two files
displaying image in awt - Java Beginners
displaying image in awt  Hi All, I have downloaded the code to display image using awt from here and when I execute the code I am getting...(); if(fd.getFile() == null){ Label1.setText("You have not chosen any image files
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" />
Displaying different portions of a page subsequently on the basis of action
Displaying different portions of a page subsequently on the basis of action  Suppose in Report.jsp there are two text fields From Date: and To Date: with js calender beside these and a SEARCH Button(When the page initially loads
date picker
date picker  where i have to kept javascript ,css files and images in eclipse... please tell me the location
displaying data retrieved from a database in a jsp page
displaying data retrieved from a database in a jsp page  the page...()) { Date date = rs.getDate(3); dateStr = DateFormat.getDateInstance(DateFormat.MEDIUM).format(date); } conn.close(); } catch (SQLException e
Displaying Hello World using GWT
Displaying Hello World using GWT       This example describes the process for displaying... involved in displaying the Hello World message using Net Beans IDE 6.1
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
Java Script Code of Calendar and Date Picker or Popup Calendar
.... In the appeared calendar we can select month, year and date. After date selection... Java Script Code of Calendar and Date Picker or Popup Calendar...; This is detailed java script code that can use for Calendar or date picker or popup
my table should be reseted to new value upon the selection of the combo box..
my table should be reseted to new value upon the selection of the combo box..  import java.awt.Container; import java.awt.FlowLayout; import... "); //1 model.addColumn(" INV DATE "); //2 model.addColumn("DESCRIPTION
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
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
supplying values to in parameters of stored procedure in ms sql and displaying out parameters
supplying values to in parameters of stored procedure in ms sql and displaying... PROCEDURE [dbo].[get_date] @codeId int, @vardate as datetime OUTPUT AS SELECT Date FROM Tbl_CustData WHERE codeId = @codeId
files
/core/files/storeobjectsinFile.html
Mutliple files upload
Mutliple files upload  <%@page contentType="text/html...)"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date">...="Pick a date"></a> </td>
Mutliple files upload
Mutliple files upload  <%@page contentType="text/html...)"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date">...="Pick a date"></a> </td>
Mutliple files upload
Mutliple files upload  <%@page contentType="text/html...)"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date">...="Pick a date"></a> </td>
Mutliple files upload
Mutliple files upload  <%@page contentType="text/html...)"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date">...="Pick a date"></a> </td>
Mutliple files upload
Mutliple files upload   <%@page contentType="text/html...)"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date">..." height="16" border="0" alt="Pick a date"></a>
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
datetimepicker - Date Calendar
datetimepicker  Hi, Iam using date time picker for the selection of the date in the input field but i want to disable the past dates i.e from yesterday date. can any one help in disabling the past dates from
Using Log Files
Using Log Files          Log files keeps a records of internet protocol addresses (IP), Http status, date, time, bytes sent, bytes recieved, number of clicks etc
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
Java current date - How to get current date in Java
In this section, you will learn about displaying current date and time in Java
displaying data
displaying data   how to display data from database on jsp using struts2
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
Date Example
contained in the Date object before and after it has change and displaying... Date Example       In this section we are discussing about the specific date using the Date
Date and Time Format Example
Date and Time Format Example       This Example shows you date and time format according to the locale. In the code given below we are displaying data and time
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
displaying List of records from database in a jsp using ajax
displaying List of records from database in a jsp using ajax  Sir, I...; In between the <div></div> I have to display the records. I am displaying... stmt; ResultSet rset; Date start=null,end=null; DateFormat df=new

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.