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
| import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SyBase extends HttpServlet
{
private static final long serialVersionUID = 0;
private Connection con;
private PrintWriter out;
public void init(ServletConfig conf) throws ServletException
{
super.init(conf);
try
{
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
con = DriverManager.getConnection ("jdbc:sybase:Tds:localhost:2638", "dba", "sql");
}
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 CLIENTS;");
out.println("<UL>");
while(rs.next())
{
out.println("<LI>" + rs.getString("TCLIRAISON"));
}
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