|
|
|
|
Strumenti |
11-02-2020, 13:35 | #1 |
Junior Member
Iscritto dal: Feb 2020
Messaggi: 1
|
Java
Buon pomeriggio devo gestire le recensioni (tipo tripadvisor)con la classe dao è giusto scrivere così:
import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import DaoTripInTravel.DBconnection; public class DaoRecensioni { ArrayList <Recensioni> elenco = new ArrayList<Recensione>(); { Connection conn = DBconnection.getConnection(); String url ="(SELECT * " + "from recensione " + "where id_Hotel = id_Hotel))"; //interrogazione per il rilevamento di tutte le recensioni relative ad un hotel try { PreparedStatement stm = conn.prepareStatement(url); Statement stmt = conn.createStatement(); ResultSet sr=stm.executeQuery(url); ResultSet sr=stm.executeQuery(url); } catch(SQLException e) { System.err.println("sql exception"); return null; } } public ArrayList <Recensioni> elenco1 = new ArrayList<Recensioni>();//interrogazione per eliminare recensioni relative ad un hotel { Connection conn2= DBconnection.getConnection(); String url ="(SELECT* " + " delete from recensione R " + "where R.id_hotel =R.id_hotel))"; try { PreparedStatement stm = conn2.prepareStatement(url); Statement stmt = conn2.createStatement(); ResultSet sr=stm.executeQuery(url); int i = stm.executeUpdate(); if(i == 1) { return true; } } catch (SQLException ex) { ex.printStackTrace(); } return false; } ArrayList <Recensioni> elenco2 = new ArrayList<Recensioni>();//interrogazione per inserire recensioni { Connection conn1 = DBconnection.getConnection(); String url1 = ("INSERT INTO recensione VALUES (NULL, ?, ?, ?,?)"); try { PreparedStatement stm = conn1.prepareStatement(url1); stm.setString(1, Nome); stm.setString(2, descrizione); stm.setInt(3, prezzo); stm.setDate(4, datarecensione); int j = stm.executeUpdate(); if(j == 1) { return true; } } catch (SQLException ex1) { ex1.printStackTrace(); } return false; } } |
13-02-2020, 07:28 | #2 |
Senior Member
Iscritto dal: Apr 2001
Città: Milano
Messaggi: 3594
|
funziona il codice?
|
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 14:48.