good morning everyone i have the following code which accesses as database of customer reccords, i need some help in caculating the difference in days between dates and then display the answer under the database. for example the difference between 11/06/2004 and 14/6/2004. iam thinking that it would be some type of IF statement but i have never been good at that so any help would be greatly appreciated... also if someone could tell me where to actually put the code that would also be
alot of help...
there are two classes for this
---------------------------------------------------------------------------
CLASS ONE
import java.sql.*;
import java.util.*;
import javax.swing.table.*;
public class ResultSetTableModel extends AbstractTableModel {
private Connection connection;
private Statement statement;
private ResultSet resultSet;
private ResultSetMetaData metaData;
private int numberOfRows;
public ResultSetTableModel(
String query) throws SQLException, ClassNotFoundException
{
String url = "jdbc

dbc:customers";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(url);
statement = connection.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
setQuery(query);
}
public Class getColumnClass(int column)
{
try{
String className =
metaData.getColumnClassName(column + 1);
return Class.forName(className);
}
catch(Exception exception){
exception.printStackTrace();
}
return Object.class;
}
public int getColumnCount()
{
try{
return metaData.getColumnCount();
}
catch(SQLException sqlException){
sqlException.printStackTrace();
}
return 0;
}
public String getColumnName(int column)
{
try{
return metaData.getColumnName(column + 1);
}
catch (SQLException sqlException){
sqlException.printStackTrace();
}
return "";
}
public int getRowCount()
{
return numberOfRows;
}
public Object getValueAt(int row, int column)
{
try{
resultSet.absolute(row + 1);
return resultSet.getObject(column + 1);
}
catch ( SQLException sqlException){
sqlException.printStackTrace();
}
return "";
}
protected void finalize()
{
try{
statement.close();
connection.close();
}
catch (SQLException sqlException){
sqlException.printStackTrace();
}
}
public void setQuery (String query) throws SQLException
{
resultSet = statement.executeQuery(query);
metaData = resultSet.getMetaData();
resultSet.last();
numberOfRows = resultSet.getRow();
fireTableStructureChanged();
}
}
---------------------------------------------------------------------------
CLASS TWO
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
public class DisplayQueryResults extends JFrame {
private ResultSetTableModel tableModel;
private JTextArea queryArea;
public DisplayQueryResults()
{
super("Displaying Query results");
String url = "jdbc.odbc:customers";
String query = "SELECT * FROM custDetails";
try{
tableModel = new ResultSetTableModel(query);
queryArea = new JTextArea(query,3,100);
queryArea.setWrapStyleWord(true);
queryArea.setLineWrap(true);
JScrollPane scrollPane = new JScrollPane(queryArea,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
JButton submitButton = new JButton("Submit Query");
Box box = Box.createHorizontalBox();
box.add(scrollPane);
box.add(submitButton);
JTable resultTable = new JTable(tableModel);
Container c = getContentPane();
c.add(box, BorderLayout.NORTH);
c.add(new JScrollPane(resultTable),
BorderLayout.CENTER);
submitButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try{
tableModel.setQuery(queryArea.getText());
}
catch (SQLException sqlException){
JOptionPane.showMessageDialog(null,
sqlException.toString(),
"Database error",
JOptionPane.ERROR_MESSAGE);
}
}
}
);
setSize(500,250);
setVisible(true);
}
catch (ClassNotFoundException classNotFound){
JOptionPane.showMessageDialog(null,
"Cloudscape driver not found","Driver not found",
JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
catch (SQLException sqlException){
JOptionPane.showMessageDialog(null,
sqlException.toString(),
"Database error",JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}
public static void main(String args[])
{
DisplayQueryResults app = new DisplayQueryResults();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}