jTextField15KeyReleased in Netbeans getMonth name and difference between two date with mysql
private void jTextField15KeyReleased(java.awt.event.KeyEvent evt) {
try
{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/commity","root","root");
String sql="select i.MemberName as Name,g.Group_Number as GroupName,g.Starting_Date,g.Ending_Date,g.Cost as Amount,i.Payment as Installment,i.date,i.Withdraw from insatllment i inner join group1 g on i.Group_Number=g.Group_Number\n" +
"where i.MemberName='"+jTextField15.getText()+"'";
java.sql.PreparedStatement pst=con.prepareStatement(sql);
DefaultTableModel tm33 = (DefaultTableModel)sark.getModel();
// System.out.println("Naveen");
tm33.setRowCount(0);
ResultSet rs = pst.executeQuery(sql);
int i=0;
while(rs.next())
{
Vector v2 = new Vector();
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(rs.getDate(3));
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(rs.getDate(4));
int diffYear = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
int diffMonth = diffYear * 12 + endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);
//System.out.println(""+diffMonth);
v2.addElement(rs.getString(1));
v2.addElement(rs.getString(2));
Calendar cal = Calendar.getInstance();
cal.setTime(rs.getDate(7));
java.util.Date d = new java.util.Date(cal.getTimeInMillis());
System.out.println("Month Name :"+new SimpleDateFormat("MMMM").format(d));
v2.addElement(rs.getDouble(5));
v2.addElement(rs.getDouble(6));
v2.addElement(new SimpleDateFormat("MMMM").format(d));
v2.addElement(rs.getString(8));
v2.addElement(diffMonth);
tm33.addRow(v2);
}
con.close();
pst.close();
}
catch (ArrayIndexOutOfBoundsException e) {
JOptionPane.showMessageDialog(this, "Press OK!!", "Error!", JOptionPane.ERROR_MESSAGE);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println(e);
JOptionPane.showMessageDialog(null, e);
}
}