1 / 4

Filiale pea09

Filiale pea09. Die Einbindung der MySQL-Datenbank in das Servlet. Filiale pea09. Das Servlet. import java.io.IOException; import java.sql.*; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest;

field
Download Presentation

Filiale pea09

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Filiale pea09 Die Einbindung der MySQL-Datenbank in das Servlet

  2. Filiale pea09 Das Servlet 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; charset=UTF-8"); java.io.PrintWriter out = response.getWriter(); [...] out.close(); } protected void doPost(HttpServletRequest 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; 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(); }

  4. Filiale pea09 Die Darstellung des Servlets

More Related