I am making a program on library management but in my program I am getting the error when I am extracting the date from MySQl(my database).
Below is the short piece of code where I am getting the error.
Calendar c1=Calendar.getInstance();
ResultSet rs=stm.executeQuery("Select AccessionNumber,Name,Fine,DueDate from issuer natural join classinfo;");
java.sql.Date d1;
d1=rs.getDate("DueDate");
//I am getting error here in executing above line as verified by the below message. I am not seeing the below message means above line is not compiled successfully.
JOptionPane.showMessageDialog(null,"CHECK 1");
java.util.Date d1j=(java.util.Date)d1;
c1.setTime(d1j);
I am having the following type of data in the column "DueDate" :
2010-02-15
2009-05-20
and the datatype of the above data is also date in MYSQL server.
Below is the complete code of my program.
int accno=Integer.parseInt(accnoTF.getText());
float finePERDAY=0;
double TotalFine=0;
int DueMonth=0;
int DueYear;
int DayofYear=0;
int daysInYear=0;
try{
Class.forName("java.sql.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3307/library","root","124");
Statement stm=conn.createStatement();
String dispName="";
String dispBooktitle="";
String dispClass="";
Date dispDuedate;
Date dispIssuedate;
int check=0;
Calendar c1=Calendar.getInstance();
ResultSet rs=stm.executeQuery("Select AccessionNumber,Name,Fine,DueDate from issuer natural join classinfo;");
java.sql.Date d1;
d1=rs.getDate("DueDate");
//I am getting error here in executing above line as verified by the below message. I am not seeing the below message means above line is not compiled successfully.
JOptionPane.showMessageDialog(null,"CHECK 1");
java.util.Date d1j=(java.util.Date)d1;
c1.setTime(d1j);
DueYear=c1.get(Calendar.YEAR);
DueMonth=c1.get(Calendar.MONTH);
DayofYear=c1.get(Calendar.DAY_OF_YEAR);
int tempaccno=0;
while(rs.next()){
tempaccno=rs.getInt("AccessionNumber");
if(accno==tempaccno){
dispName=rs.getString("Name");
dispClass=rs.getString("Class");
dispIssuedate=rs.getDate("IssuedOn");
dispDuedate=rs.getDate("DueDate");
finePERDAY=rs.getFloat("Fine");
TotalFine=calculateFine(finePERDAY, DueYear,DueMonth,DayofYear);
infoTA.append("FINE INFORMATION\n Name\t"+dispName+"\nClass\t"+dispClass+"\nIssueDate\t"+dispIssuedate+"\nDueDate\t"+dispDuedate+"\nCurrent Date\t"+"\n\nSo, fine till date\t"+TotalFine);
check=1;
}
}
rs.close();
if(check==0)
JOptionPane.showMessageDialog(null,"There was no such book having "+accno+" as an Accession Number. Please check again carefully.");
}catch(Exception e){
JOptionPane.showMessageDialog(null,"Error in connectivity");
}