import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class GetColumnNumber extends HttpServlet
{
	public void doGet(HttpServletRequest req, HttpServletResponse res)
		throws IOException, ServletException
		{
		res.setContentType("text/html");
		PrintWriter pw = res.getWriter();
		Connection con;
		PreparedStatement ps;
		ResultSet rs;
		ResultSetMetaData rsmd;
		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			con= DriverManager.getConnection("jdbc:odbc:formRecord");
			ps= con.prepareStatement("SELECT * FROM dataformat");
			rs= ps.executeQuery();
			rsmd = rs.getMetaData();
			int i = rsmd.getColumnCount();
			pw.println("There are "+i+" columns in table '"+rsmd.getTableName(i)+"'");
		}
		catch(Exception e)
		{
			pw.println(e);
		}
	}
}
