15.06.2013 Views

Dispensa in PDF - Dipartimento di Scienze Ambientali, Informatica e ...

Dispensa in PDF - Dipartimento di Scienze Ambientali, Informatica e ...

Dispensa in PDF - Dipartimento di Scienze Ambientali, Informatica e ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PreparedStatement PreparedStatement <strong>in</strong>terrogazione <strong>in</strong>terrogazione =<br />

=<br />

unaConnessioneDiEsempio.preparedStatement();<br />

unaConnessioneDiEsempio.preparedStatement();<br />

Carnielli Efrem: Programmazione a componenti<br />

Applicazioni Client-Server e database<br />

Bisogna fare attenzione a non scrivere l’<strong>in</strong>terrogazione <strong>di</strong>rettamente <strong>in</strong> questa riga<br />

<strong>di</strong> co<strong>di</strong>ce, bensì mettervi una costante <strong>di</strong>chiarata <strong>in</strong> precedenza con<br />

l’<strong>in</strong>terrogazione. Per esempio:<br />

QDammiIGiocatoriMigliori = = “select “select nome, nome, cognome cognome from from giocatori<br />

giocatori<br />

where where punti punti > > ? ? and and and categoria categoria = = ?”;<br />

?”;<br />

Si devono def<strong>in</strong>ire anche i marker dell’<strong>in</strong>terrogazione:<br />

MPDammiIGiocatoriMigliori_Punti MPDammiIGiocatoriMigliori_Punti = = 1;<br />

1;<br />

MPDammiIGiocatoriMigliori_Categoria MPDammiIGiocatoriMigliori_Categoria = = 2;<br />

2;<br />

Dopo aver creato il prepared statement si esegue l’<strong>in</strong>terrogazione:<br />

for(<strong>in</strong>t for(<strong>in</strong>t <strong>in</strong>dex; <strong>in</strong>dex; <strong>in</strong>dex <strong>in</strong>dex <strong>in</strong>dex < < < qualcosa; qualcosa; <strong>in</strong>dex++){<br />

<strong>in</strong>dex++){<br />

<strong>in</strong>terrogazione.setInt(MPDammiIGiocatoriMigliori_Punti,<br />

<strong>in</strong>terrogazione.setInt(MPDammiIGiocatoriMigliori_Punti,<br />

pun punti[<strong>in</strong>dex]);<br />

pun<br />

ti[<strong>in</strong>dex]);<br />

<strong>in</strong>terrogazione.setStr<strong>in</strong>g(MPDammiIGiocatoriMigliori_Categoria,<br />

<strong>in</strong>terrogazione.setStr<strong>in</strong>g(MPDammiIGiocatoriMigliori_Categoria,<br />

<strong>in</strong>terrogazione.setStr<strong>in</strong>g(MPDammiIGiocatoriMigliori_Categoria,<br />

categoria[<strong>in</strong>dex]);<br />

categoria[<strong>in</strong>dex]);<br />

<strong>in</strong>terrogazione.execute();<br />

<strong>in</strong>terrogazione.execute();<br />

}<br />

Il settaggio dei tipi (setInt e setStr<strong>in</strong>g) potrebbe avvenire d<strong>in</strong>amicamente chiedendo<br />

<strong>di</strong> quale tipo sia il marker e, a seconda del suo tipo, chiamare il metodo set adatto.<br />

6.11 Gestione degli utenti e LDAP<br />

Com<strong>in</strong>ciamo col <strong>di</strong>fferenziare gli utenti applicativi con quelli del db.<br />

Gli utenti dell’applicazione si <strong>di</strong>vidono a seconda del livello a cui appartengono,<br />

livello basso , me<strong>di</strong>o, alto.<br />

Gli utenti del db sono quelli che stanno <strong>di</strong>etro agli applicativi e sono registrati nel<br />

DB.<br />

Consideriamo la tabella degli utenti <strong>di</strong> un db. Non è corretto mettere tutte le<br />

risorse nel db, <strong>in</strong>fatti ci sono degli standard che mi consentono <strong>di</strong> non farlo, e mi<br />

consentono <strong>di</strong> accedere a varie applicazioni nell’ottica enterprice.<br />

Consideriamo <strong>di</strong> nuovo l’esempio del me<strong>di</strong>co visto <strong>in</strong> precedenza. Il paziente e le<br />

<strong>in</strong>formazioni sanitarie sono <strong>in</strong>formazioni organizzative (persone rappresentate nel<br />

db) l’utente paziente è altra cosa. Supponiamo <strong>di</strong> trovarci nel caso <strong>in</strong><strong>di</strong>cato nella<br />

figura sotto:<br />

158

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!