€uro Spice Filiale pea09

Werbung
Filiale pea09
Die Einbindung der
MySQL-Datenbank
in das Servlet
Geschäftsführung: David Christmann, Mustafa Günlü, Kilian Weihrauch
Filiale pea09
Das Servlet
import
import
import
import
import
import
java.io.IOException;
java.sql.*;
javax.servlet.ServletException;
javax.servlet.http.HttpServlet;
javax.servlet.http.HttpServletRequest;
javax.servlet.http.HttpServletResponse;
public class StorageDB extends HttpServlet {
protected void doGet(HttpServletRequest request ,HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
java.io.PrintWriter out = response.getWriter();
[...]
out.close();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}
Geschäftsführung: David Christmann, Mustafa Günlü, Kilian Weihrauch
Filiale pea09
Die Einbindung der MySQL-Datenbank in das Servlet
protected void doGet(HttpServletRequest request ,HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
java.io.PrintWriter out = response.getWriter();
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection con = java.sql.DriverManager.getConnection(
"jdbc:mysql://salvator.ibr.cs.tu-bs.de/pea09","pea09","jiiab12");
Statement s = con.createStatement();
ResultSet rs=s.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();
}
Geschäftsführung: David Christmann, Mustafa Günlü, Kilian Weihrauch
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
Geschäftsführung: David Christmann, Mustafa Günlü, Kilian Weihrauch
Herunterladen