Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


monica suresh patil
Displaying files on selection of date.
1 Answer(s)      2 years and 3 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.


Advertisement
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 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
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 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
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
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
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
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
displaying data
displaying data   how to display data from database on jsp using struts2
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
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
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
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
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
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
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
Image Selection - Swing AWT
Image Selection  Hi, I need to provide the image selection facility...; JButton saveButton; public DisplayImage() { super("Image Selection program... { String selection = (String)comboBox.getSelectedItem(); String
changing selection color of <button>
changing selection color of   dear all, i have loaded image in border less button tag when button is selected with tab key i get brown color rectangle around image. how do i change color of that rectangle from brown to white
selection box linked with textarea
selection box linked with textarea    function get_val(tot_val1) { document.getElementById('TextBox1').value = tot_val1; alert(tot_val1... detals i have in db with all fields .. like wise i have names in selection box sham
Selection With Ajax and JSP
Selection With Ajax and JSP  I am working at a jsp page using ajax for country , state, city selection. so if he select country it will populate the state and city selection (both). After selecting country if he select city
date
date   how to insert date in database? i need coding
date
date  i want difference between the date entered in a jtextfield 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  can u tell me how to calculate difference between a user provided date and the system date in java
else if (selection = * 'M'); - Java Beginners
else if (selection = * 'M');  I am trying to get 2 numbers 2... if (selection = * 'M'); ^ this is my program - what am i...; System.out.print("Enter A(dd), S(ubtract), M(ultiply):"); selection = (char
date
date  how to insert date using html through the combobox
 

 

 

DMCA.com