Wednesday, December 17, 2008

Online Banking Project

import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.io.*;public class reports extends HttpServlet { public Connection getConnection() { try { Class.forName("oracle.jdbc.driver.OracleDriver");
return (DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","netbank","netbank")); } catch (Exception exp) { return null;} } public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); String repttype=req.getParameter("table").replace('_',' '); out.println("

"+repttype+"

"); generateReports(req,res); } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{ PrintWriter out=res.getWriter(); String repttype=req.getParameter("table").replace('_',' '); out.println("

"+repttype+"

"); generateReports(req,res); } public void getQueryToParse(String vall,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); try { String ds; int iv; String data="Select * from "+vall; Connection conn=null; Statement st=null; PreparedStatement pst=null; ResultSet rs=null; ResultSetMetaData meta=null; conn=getConnection(); st=(conn!=null)?conn.createStatement():null; rs=(st!=null)?st.executeQuery(data):null; meta=(rs!=null)?rs.getMetaData():null; int ct=0; out.println(""); out.println("Reports Generation"); out.println("
"); for(int mt=1;mt<=meta.getColumnCount();mt+=1) out.println(""); out.println("");} while(rs!=null && rs.next()) { ct++;out.println(""); for(int d=1;d<=meta.getColumnCount();d++) { String metaname=meta.getColumnTypeName(d).toLowerCase(); if(metaname.indexOf("varchar")!=-1) { ds=rs.getString(d); out.println("");} else if(metaname.indexOf("date")!=-1) { ds=rs.getDate(d).toString(); out.println("");} else { iv=rs.getInt(d); out.println("");} } out.println(""); } out.println("
"+meta.getColumnName(mt).replace('_','-')+"
"+ds+" "+ds+" "+iv+"
"); out.println("

Print The Reports



"); } catch (Exception e) { out.println("Error Occured
"+e); } } public void generateReports(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { getQueryToParse(req.getParameter("table"),res); }}

No comments: