Hello, I have a simple handler on the button, depending on what number of the month we enter into the textfield, it considers the amount of money for a given month. Here is my code:
public void actionPerformed(ActionEvent e) { try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cursova", "root", "root"); String sql = "SELECT YEAR(endDate) as SalesYear , " + "MONTH(endDate) as SalesMonth, " + "SUM(price) AS TotalSales " + "FROM arend where month(endDate) =? " + "GROUP BY YEAR(endDate), MONTH(endDate) " + "ORDER BY YEAR(endDate), MONTH(endDate)"; PreparedStatement pst = conn.prepareStatement(sql); pst.setString(1, textFieldTest.getText()); ResultSet rs = pst.executeQuery(); if (rs.next()) { String year = rs.getString("SalesYear"); labelMonth.setText(year); String month = rs.getString("SalesMonth"); lblYear.setText(month); String result = rs.getString("TotalSales"); resultLabel.setText(result); } } catch (SQLException ex) { ex.printStackTrace(); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } But the error knocks out:
column 'endDate' not found
endDatein the table in the database - Alexey ShimanskySELECTquery in the enumeration there is no mention of theendDatacolumn andpriceas well - Alexey Shimansky