Download - Lezione Jsp Pdatabase Mysql
![Page 1: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/1.jpg)
Apr 13, 2023
Tutorial JSP database
Silvano Natalizi
![Page 2: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/2.jpg)
Scaricare il driver jdbc Mysql
http://dev.mysql.com/downloads/connector/j/
Con il precedente link fare il Download del file MySQL Connector/JDBC
Mysql connector/j/ is a native Java driver that converts JDBC (Java Database Connectivity) calls into the network protocol used by the MySQL database
![Page 3: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/3.jpg)
Installa il driver jdbc connector
mysql-connector-java-5.1.12.zip Estrai tutti i files La cartella così creata mysql-connector-java-5.1.12
contiene il file jar: mysql-connector-java-5.1.12-bin.jar Nel tuo applicativo-web ipc, crea sotto WEB-INF la
cartella lib e copia mysql-connector-java-5.1.12-bin.jar
![Page 4: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/4.jpg)
Crea il database per provare il collegamento con java
In mysql crea il database libri In esso ci sono la tabella Autore, Titolo, la tabella
associativa Autore_Titolo (perché la relazione tra autore e titolo è molti a molti).
Autore(id, nome) Titolo(id, titolo, prezzo) Autore_Titolo(autore_id,titolo_id)
![Page 5: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/5.jpg)
Crea le tabelle relazionali
create database libri; use libri; create table autore(id integer, nome varchar(30),
primary key(id)); create table titolo(id integer, titolo varchar(50), primary
key(id)); create table autore_titolo(autore_id integer, titolo_id
integer, primary key(autore_id, titolo_id));
![Page 6: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/6.jpg)
Inserisci alcuni dati di prova
insert into autore values (1, “Mario Il Novelliere”); insert into autore values (2, “Silvano da Perugia”); insert into autore values (3, “Vel, lo Scriba del
Computer”); insert into titolo values (1,”Tutti zitti davanti a
internet”); insert into titolo values (2, “Nell’abisso di Java”); insert into titolo values (3, “L’ho scolpito nel papiro del
Computer”);
![Page 7: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/7.jpg)
Associamo i titoli agli autori
insert into autore_titolo values (3,3); insert into autore_titolo values (1,1); insert into autore_titolo values (2,1); insert into autore_titolo values (2,2);
![Page 8: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/8.jpg)
Crea il programma BooksList.jsp
Facciamo un programma che si collega al database libri Che elenca gli autori e i titoli di tutti i libri presenti nelle
tabelle.
![Page 9: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/9.jpg)
BooksList.jsp –il collegamento con il database
![Page 10: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/10.jpg)
La query con la join
![Page 11: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/11.jpg)
Salviamo la BooksList1.jsp
Salviamo la booskList.jsp nella cartella ipc Quindi apriamo la pagina web
all’indirizzo/ipc/booklist1.jsp
![Page 12: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/12.jpg)
Il risultato
![Page 13: Lezione Jsp Pdatabase Mysql](https://reader038.vdocument.in/reader038/viewer/2022100601/557bec29d8b42a2b348b486e/html5/thumbnails/13.jpg)
The End