You are on page 1of 2

import java.io.*; import javax.servlet.

*;
import javax.servlet.http.*; import java.sql.*;
public class MostraLibri extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
try {
String codice= req.getParameter(codice);
Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);
Connection conn = DriverManager.getConnection(jdbc:odbc:DB,user,pwd);
PreparedStatement pstmt=conn.prepareStatement(
SELECT LIBRO.ISBN,TITOLO,EDITORE , PREZZO +
FROM SCRIVE LEFT JOIN LIBRO ON SCRIVE.ISBN= LIBRO.ISBN +
WHERE SCRIVE.CODICEAutore= ?);
pstmt.setString(1,codice);
ResultSet result= pstmt.executeQuery();
res.setContentType(text/html);
PrintWriter out= res.getWriter();
out.println(<HTML>);
out.println(<BODY>);
out.println(<H1> Elenco dei libri dell'autore </H1>);
while (result.next()) {
out.println(<P>);
out.print(ISBN: +result.getString(ISBN));
out.print(TITOLO: +result.getString(TITOLO));
out.print(EDITORE: +result.getString(EDITORE));
out.print(PREZZO: +result.getString(PREZZO));
out.println(</P>));
}
out.println(</BODY>);
out.println(</HTML>);
result.close();
pstmt.close();
conn.close();

}
catch(ClassNotFoundException e){
throw new ServletException(e);
}
catch(SQLException e){
throw new ServletException(e);
}
}
}