Title: Filiale pea09
1 Filiale pea09
- Die Einbindung der
- MySQL-Datenbank
- in das Servlet
2 Filiale pea09
import java.io.IOException import
java.sql. import javax.servlet.ServletException
import javax.servlet.http.HttpServlet import
javax.servlet.http.HttpServletRequest import
javax.servlet.http.HttpServletResponse public
class StorageDB extends HttpServlet protected
void doGet(HttpServletRequest request
,HttpServletResponse response) throws
ServletException, IOException
response.setContentType("text/html
charsetUTF-8") java.io.PrintWriter out
response.getWriter() ...
out.close() protected void doPost(HttpServletR
equest request, HttpServletResponse response)
throws ServletException, IOException
doGet(request,response)
3 Filiale pea09
- Die Einbindung der MySQL-Datenbank in das Servlet
protected void doGet(HttpServletRequest request
,HttpServletResponse response) throws
ServletException, IOException
response.setContentType("text/html
charsetUTF-8") java.io.PrintWriter out
response.getWriter() try
Class.forName("org.gjt.mm.mysql.Driver").newInstan
ce() Connection con java.sql.DriverManager.
getConnection( "jdbcmysql//salvator.ibr.cs
.tu-bs.de/pea09","pea09","jiiab12")
Statement s con.createStatement()
ResultSet rss.executeQuery("select from
storage") ... while (rs.next())
out.println(rs.getString("name"))
... catch (SQLException ex)
out.println("Error1 "ex) catch
(ClassNotFoundException ex)
out.println("Error2 "ex) catch
(InstantiationException ex)
out.println("Error3 "ex) catch
(IllegalAccessException ex)
out.println("Error4 "ex) out.close()
4 Filiale pea09
- Die Darstellung des Servlets
Name Preis Gelagerte Menge
Anis 2.9 EUR/kg 2.7 kg
Basilikum 2.8 EUR/kg 5.7 kg