1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
package servlet_jsp;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.WebRowSet;
import com.sun.rowset.CachedRowSetImpl;
import com.sun.rowset.WebRowSetImpl;
public class servlet_oracle_connexion extends HttpServlet
{
private Connection con;
private PrintWriter out;
public void init(ServletConfig conf) throws ServletException
{
super.init(conf);
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con =DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:xe", "bda", "faycal");
}
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 produit");
WebRowSet crset = new WebRowSetImpl();
crset.populate(rs);
crset.execute();
out.println("<UL>");
rs.close();
stmt.close();
while(crset.next())
{
out.println("<LI>" + crset.getString("des_prod"));
}
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)
{
;
}
}
} |
Partager