0

I have populated a combo box with months from my database on MySQL. The problem is that the months are displayed as numbers (because of the default format). I want to display it as the full names of the months and in order. I have tried using DATENAME, TO_CHAR and DATE_FORMATfunctions but my MySQL displays this error for each:

Error Code: 1305. FUNCTION sales.DATENAME does not exist

How can I change the following Java code so that the month names are displayed and in the correct order?

Java code for calling the months from MySQL:

String sql = "SELECT DISTINCT EXTRACT(MONTH FROM syear) AS monthSales from dbsales";
Osiris93
  • 189
  • 1
  • 15
  • http://stackoverflow.com/questions/7027129/mysql-monthname-from-numbers – Dhruv Kapatel Oct 11 '15 at 09:30
  • That post helped a bit but it is conflicting with the statement I am using in my Java code. How would I incorporate the `MONTHNAME()` in my Java code? – Osiris93 Oct 11 '15 at 09:39

1 Answers1

0

After playing around with the coding, I found that this solution can be used in the Java coding:

int month = rs.getInt("monthSales");

  if (month == 01)
  {
     String jan = "Jan";
     cboMonth.addItem(jan);
  }

This still allows me to call the months from the database but display the months as a text in the combo box.

Osiris93
  • 189
  • 1
  • 15