
Jdbc connectivity in java to MS Access for retrieving data between two dates

Here is an example that fetches data between two dates from MS access database.
import java.sql.*;
class FetchDataBetweenTwoDates
{
public static void main(String[] args)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:roseindia");
Statement st=con.createStatement();
String d1 = "2/22/2006";
String d2 = "3/20/2007";
String query = "Select * from employee where dateOfJoining >=to_date(d1,'dd/mm/yyyy') and dateOfJoining <=to_date(d2,'mm/dd/yyyy')";
ResultSet rs=st.executeQuery(query);
while(rs.next()){
System.out.println(rs.getString("name")+"\t "+rs.getString("address"));
}
}
catch(Exception e){
System.out.println(e);
e.printStackTrace();
}
}
}
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.