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 statMarv extends HttpServlet{
  public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus)throws IOException, ServletException{
    BufferedImage pilt=new BufferedImage(600, 400, BufferedImage.TYPE_INT_RGB);
    Graphics2D  piltg=pilt.createGraphics();
    Connection cn=null;
    ResultSet rs;
    ResultSetMetaData rsmd=null;
    Statement st;
    //int[] kordi=new int[4];
    int[] kordi={0,0,0,0};
    
    try{
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		cn=DriverManager.getConnection("jdbc:odbc:andmed", "", "");
		st=cn.createStatement();
		String lause="SELECT * FROM vaatlusandmed;";
		rs=st.executeQuery(lause);
		rsmd=rs.getMetaData();
		
		while(rs.next()){
			int a=rs.getInt("punkti_ID");
			if(a==1){
				kordi[0]=kordi[0]+1;
			}
			if(a==2){
				kordi[1]=kordi[1]+1;
			}
			if(a==3){
				kordi[2]=kordi[2]+1;
			}
			if(a==4){
				kordi[3]=kordi[3]+1;
			}
			System.out.println("kordus");
		}
    }catch(Exception e){System.out.println(e);}
    System.out.println(kordi[0]+";"+kordi[1]+";"+kordi[2]+";"+kordi[3]);
    for(int i=0; i<=3; i++){
    	piltg.setColor(Color.red);
    	piltg.fillRect(50+(i*100),400-kordi[i]*50,90,400);
    	piltg.setColor(Color.blue);
    	try{piltg.drawString("Punkt ID="+(i+1),60+i*100,390);}catch(Exception e){System.out.println(e+"");}
    }
    vastus.setContentType("image/jpeg");
    JPEGCodec.createJPEGEncoder(vastus.getOutputStream()).encode(pilt);
    try{cn.close();}catch(Exception e){}
    }
}