|
|
|
|
Strumenti |
17-03-2019, 16:24 | #1 |
Junior Member
Iscritto dal: Mar 2019
Messaggi: 14
|
java.sql.SQLSyntaxErrorException con query select
Ciao a tutti.
Sto creando una java web application per la gestione delle fatture. L'applicazione prevede, oltre all'inserimento, anche la visualizzazione della lista delle fatture inserite da un determinato utente. Nel richiedere la lista delle fatture ottengo il seguente messaggio di errore: "java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.fattura where fkutente = 2' at line 1" e la lista che voglio visualizzare in una pagina jsp è ovviamente vuota. Di seguito il codice: Servlet Codice:
import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import it.techwin.bean.Fattura; import it.techwin.dao.ManipolazioneDao; /** * Servlet implementation class ListaFatture */ @WebServlet("/ListaFattureCb") public class ListaFattureCb extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public ListaFattureCb() { super(); } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); String username = (String)session.getAttribute("username"); String password = (String)session.getAttribute("password"); Integer fkUtente = (Integer) session.getAttribute("idUtente"); System.out.println(fkUtente); List<Fattura> fatture = new ArrayList<Fattura>(); if(username == null || password == null){ RequestDispatcher rd = request.getRequestDispatcher("/jsp/errorcb.jsp"); rd.forward(request, response); }else{ try { fatture = ManipolazioneDao.listaFatture(fkUtente); } catch (SQLException e) { e.printStackTrace(); } request.setAttribute("fatture", fatture); RequestDispatcher rd = request.getRequestDispatcher("/jsp/listafatturecb.jsp"); rd.forward(request, response); } } } Codice:
public static List<Fattura> listaFatture(int fkUtente) throws SQLException{ Connection conn = ConnessioneDb.getConnection(); PreparedStatement ps = null; ResultSet rs = null; List<Fattura> fatture = new ArrayList<Fattura>(); String queryList = "select idfattura, dataemissione, numeroemissione, nomeditta, nomecliente" + "from fattura_tw.fattura where fkutente = ?"; try{ ps = conn.prepareStatement(queryList); ps.setInt(1, fkUtente); System.out.println(fkUtente); rs = ps.executeQuery(); while(rs.next()){ Fattura fattura = new Fattura(); fattura.setIdFattura(rs.getInt(1)); fattura.setDataEmissione(rs.getDate(2)); fattura.setNumeroEmissione(rs.getInt(3)); fattura.setNomeDitta(rs.getString(4)); fattura.setNomeCliente(rs.getString(5)); fatture.add(fattura); } }catch(SQLException e){ e.printStackTrace(); }finally{ if(ps != null){ ps.close(); } if(conn != null){ conn.close(); } } return fatture; } |
17-03-2019, 16:41 | #2 |
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Codice:
String queryList = "select idfattura, dataemissione, numeroemissione, nomeditta, nomecliente" + "from fattura_tw.fattura where fkutente = ?"; Codice:
select idfattura, dataemissione, numeroemissione, nomeditta, nomeclientefrom fattura_tw.fattura where fkutente = ?
__________________
In God we trust; all others bring data |
17-03-2019, 17:38 | #3 | |
Junior Member
Iscritto dal: Mar 2019
Messaggi: 14
|
Quote:
Grazie mille! Ultima modifica di Andreawave : 17-03-2019 alle 17:45. |
|
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 04:47.