home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.disi.unige.it
/
2015-02-11.ftp.disi.unige.it.tar
/
ftp.disi.unige.it
/
pub
/
.person
/
CataniaB
/
teach-act
/
DB3
/
servlet-bean-jsp
/
QueryDBMS.java
< prev
next >
Wrap
Text File
|
2001-04-02
|
3KB
|
99 lines
import java.io.*;
import java.util.*;
import java.text.*; // per il DateFormat
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Semplice query con modulo DBMS e utilizzo dei bean
*
* @author Mirko Manea
*/
public class QueryDBMS extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
PrintWriter out = response.getWriter();
String sql;
// formattatore per le date
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ITALY);
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"");
out.println(" \"http://www.w3.org/TR/REC-html40/loose.dtd\">");
out.println("<html>");
out.println("<head>");
out.println("<title>Studente</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Studente</h1>");
String matricola = request.getParameter("matr");
EsameBean esame;
Vector listaEsami;
try {
DBMS dbms = new DBMS();
StudenteBean studente = new StudenteBean();
studente = dbms.extractStudente(matricola);
out.println("<p>");
out.println("<strong>Cognome:</strong> "+studente.getCognome());
out.println("<br>");
out.println("<strong>Nome:</strong> "+studente.getNome());
out.println("<br>");
out.println("<strong>Facoltà:</strong> "+studente.getFacolta());
out.println("<br>");
out.println("<strong>Data di nascita:</strong> "+df.format(studente.getDataNascita()));
out.println("<br>");
if (studente.getCreditiOttenuti() == -1) {
out.println("<strong>Crediti ottenuti:</strong> "+studente.getCreditiOttenuti());
}
out.println("</p>");
out.println("<hr>");
listaEsami = dbms.extractEsamiStudente(studente.getMatricola());
out.println("<h2>Esami sostenuti</h2>");
if (listaEsami.size()!=0) {
out.println("<table border=\"1\">");
out.println("<tr>");
out.print("<td><strong>Corso</strong></td>");
out.print("<td><strong>Data</strong></td>");
out.print("<td><strong>Voto</strong></td>");
out.println("</tr>");
for (int i=0; i<listaEsami.size(); i++) {
esame = (EsameBean)listaEsami.get(i);
String colore = ((i%2)==0)?"#F7F7F7":"#E0E0E0";
out.println("<tr bgcolor=\""+colore+"\">");
out.println("<td>"+esame.getDenominazione()+"</td>");
out.println("<td>"+df.format(esame.getData())+"</td>");
out.println("<td>"+esame.getVoto()+"</td>");
out.println("</tr>");
}
out.println("</table>");
} else {
out.println("Nessuno.");
}
} catch (UnknownKeyDBMSException ukde) {
System.err.println("Matricola "+matricola+" non trovata: "+ukde.getMessage());
} catch (DBMSException dbmse) {
System.err.println("Errore verso il database: "+dbmse.getMessage());
}
out.println("</body>");
out.println("</html>");
}
}