Reputation: 1815
I have a database field of Date type in Derby. I need to get the years in all that are in the date. The program is in java swing. I tried the following code:
SELECT year(DATE) FROM BILLING
Then i try to populate the years in a jCombobox by the following code:
jComboBox1.addItem(resultSet.getString("DATE"));
But it shows an error:
java.sql.SQLException: There is no column named: DATE.
What could be wrong?
Upvotes: 1
Views: 104
Reputation: 15664
Try giving an alias to your result and it should work fine :
SELECT year(DATE) as y FROM BILLING
and fetch it :
jComboBox1.addItem(resultSet.getString("y"));
or try this way:
jComboBox1.addItem(resultSet.getString("year(DATE)"));
Upvotes: 2
Reputation: 1208
SELECT year(DATE) AS DATE FROM BILLING
If you want to call it DATE in your code you have to alias it to the name DATE.
year(DATE) has no column name.
Upvotes: 3