- /*
- Pensez à télécharger le pilote JDBC sur le site de MySql
- */
-
- import java.io.*;
- import java.sql.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
-
- public class DBServlet extends HttpServlet
- {
- private Connection con;
- private PrintWriter out;
-
- public void init(ServletConfig conf) throws ServletException
- {
- super.init(conf);
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- con =DriverManager.getConnection ("jdbc:mysql://localhost:3306/NomDeVotreBase", "VotreIdMySql", "VotreMdpMySql");
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- }
-
- public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
- {
- res.setContentType("text/html");
- try
- {
- out = res.getWriter();
- out.println("<html><head><title>");
- out.println("JDBC Servlet");
- out.println("</title></head><body>");
-
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT * FROM essai");
- out.println("<UL>");
-
- while(rs.next())
- {
- out.println("<LI>" + rs.getString("nom"));
- }
- out.println("</UL>");
- rs.close();
- stmt.close();
- }
- catch(SQLException e)
- {
- out.println("Exception SQL");
- }
- catch(IOException e)
- {
- }
-
- out.println("</body></html>");
- out.close();
- }
-
- public void destroy()
- {
- try
- {
- con.close();
- }
- catch(SQLException e)
- {
- ;
- }
- }
- }
-
-
/*
Pensez à télécharger le pilote JDBC sur le site de MySql
*/
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DBServlet extends HttpServlet
{
private Connection con;
private PrintWriter out;
public void init(ServletConfig conf) throws ServletException
{
super.init(conf);
try
{
Class.forName("com.mysql.jdbc.Driver");
con =DriverManager.getConnection ("jdbc:mysql://localhost:3306/NomDeVotreBase", "VotreIdMySql", "VotreMdpMySql");
}
catch(Exception e)
{
System.out.println(e);
}
}
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
try
{
out = res.getWriter();
out.println("<html><head><title>");
out.println("JDBC Servlet");
out.println("</title></head><body>");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM essai");
out.println("<UL>");
while(rs.next())
{
out.println("<LI>" + rs.getString("nom"));
}
out.println("</UL>");
rs.close();
stmt.close();
}
catch(SQLException e)
{
out.println("Exception SQL");
}
catch(IOException e)
{
}
out.println("</body></html>");
out.close();
}
public void destroy()
{
try
{
con.close();
}
catch(SQLException e)
{
;
}
}
}