
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.

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