0

`

      Class.forName(driver);
      con = DriverManager.getConnection(url+db, user, pass);
      Statement st = con.createStatement();
      ResultSet rs=st.executeQuery("select date from profile");
      ResultSetMetaData metadata = rs.getMetaData();
      int columnCount = metadata.getColumnCount();
      Date str[] = new Date[columnCount];
      int a=0;

getting dates to an array

      while(rs.next()){

      str[a++]=rs.getDate("date");
       }

setting the color

  Calendar cal = Calendar.getInstance();
  cal.setTime(jCalendar1.getDate());
  int day = cal.get(Calendar.DAY_OF_MONTH);
  int month = cal.get(Calendar.MONTH);
  int year = cal.get(Calendar.YEAR);

  JPanel jpanel = jCalendar1.getDayChooser().getDayPanel();
  Component component[] = jpanel.getComponents();


for(int i = 0; i < columnCount; i++)
{

     if(month == str.get(i).getMonth() && year == str.get(i).getYear())
     {

          component[ str.get(i).getDay()].setBackground(Color.blue);
     }
}

     `

I want to display some dates which is stored in mysql database in a different color in jcalendar. I searched but couldn't find a solution. Im new to java so im not sure whether this is correct.I added a code which i have tried upto now.it gives an error in str.get(i) as cannot find symbol

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Im new to java.if you can give a small example where you can color a date stored in mysql database it'll be much appreciated – user2700115 Mar 08 '14 at 05:25

1 Answers1

1

Combining the answer here with pseudocode (as you haven't posted your code).

  1. Import the dates from MySQL into a list of MySQLDataBeans or whatever.
  2. Set the colour per the above answer for those dates.

That's all you need, but let me know if you're still lost.

Community
  • 1
  • 1
hd1
  • 33,938
  • 5
  • 80
  • 91
  • I edited my question,posted the code which i have done up to now.it gives errors in str.get(i) and im not sure whether this is correct since im new to java – user2700115 Mar 08 '14 at 05:48
  • Why don't you try to add print statements to show what, e.g., the str array, has in it? – hd1 Mar 08 '14 at 06:56