ho provato così ma non funziona:
codice:public String cerca_libro_titolo(String titolo, String autore, String editore) { String ris=""; try { String SQL=""; Class.forName("xxx"); String url = "xxx"; String usr = "xxx"; String pass = "xxx"; Connection con = (Connection) DriverManager.getConnection(url, usr, pass); Statement statement = (Statement) con.createStatement(); if(titolo!=null){ SQL = "SELECT titolo,autore,editore FROM Libro WHERE titolo = '" + titolo + "'";} else if (autore != null) { SQL="SELECT titolo,autore,editore FROM Libro WHERE autore = '" + autore + "'";} else if (editore != null) { SQL="SELECT titolo,autore,editore FROM Libro WHERE editore = '" + editore + "'";} ResultSet risultato = statement.executeQuery(SQL); while (risultato.next()) { ris=ris + risultato.getString(1) + " " + risultato.getString(2)+ " " + risultato.getString(3); } con.close(); statement.close(); risultato.close(); } catch (Exception exception) { System.out.println("erroreeeeeeeee " + exception.getMessage()); } return ris; } }

Rispondi quotando