import javax.servlet.*; import javax.servlet.http.*; import com.sun.image.codec.jpeg.*; //kuulub SUNi JDK-sse import java.awt.image.*; import java.awt.*; import java.io.*; import java.sql.*; public class LaulDiagramm extends HttpServlet{ public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus) throws IOException, ServletException{ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn=DriverManager.getConnection("jdbc:odbc:Baas1", "lohe", "ActiSolFor"); Statement st=cn.createStatement(); Statement st2=cn.createStatement(); String tabel_nimi="SELECT * FROM Tabelite_Info;"; ResultSet tn=st.executeQuery(tabel_nimi); BufferedImage pilt =new BufferedImage(800, 500, BufferedImage.TYPE_INT_RGB); Graphics2D piltg=pilt.createGraphics(); int x=5; while(tn.next()){ String tabeli_nimi=tn.getString("Nimi"); String laul_arv="SELECT count(*) FROM "+tabeli_nimi+";"; ResultSet la=st2.executeQuery(laul_arv); la.next(); int laulude_arv=la.getInt(1); piltg.setColor(new Color((int)(100+(155*Math.random())),(int)(100+(155*Math.random())), (int)(100+(155*Math.random())))); piltg.fillRect(x, 420-(laulude_arv*10), 10, laulude_arv*10); piltg.drawString(laulude_arv+"", x, 420-((laulude_arv*10)+5)); piltg.rotate(-(Math.PI/2), x+10, 480); piltg.drawString(tabeli_nimi, x, 480); piltg.rotate((Math.PI/2), x+10, 480); x=x+15; } vastus.setContentType("image/jpeg"); JPEGCodec.createJPEGEncoder(vastus.getOutputStream()).encode(pilt); } catch (Exception viga){ System.out.println(viga); viga.printStackTrace(); } } }