Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi steven Thank you for the scrip

Status
Not open for further replies.

ktsrikanth

Programmer
Feb 6, 2001
22
0
0
US
Hi steven
Thank you for the script. I have a another problem now.
I am using Apache, Jserv for the servlets to run.
I get an exception IO Exception: Broken Pipe, randomly, whenever i run the servlets.
I do not know the cause for this exception.
Could any one help me with this.
Please help me with what might be the cause for the Exception.

Thank you



 
Hi,

I guess it would be better if possible, if you could copy and paste some portions of your codes into the forum.

It would be quite hard know what is causing the error without any codes.

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Hi LeonTang,
the code is pasted below. Please give me the solution as soon as possible.

package com.vip.portal.systemlevelservices.reporting;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.text.*;

//******************************************************************************
// ClassFile
//******************************************************************************
/**
* <STRONG>
* Description:
* </STRONG><BR>

This class generates a report on portal users

* @version <PRE>
* $History: UsersReport.java $
*
* ***************** Version 1 *****************
* User: Andrew Linton Date: 10-26-2000 Time: 14:00
* User: Srikanth K. changes are made in the code
* *
* </PRE>
**/
//********************************************************************************/

public class UsersReport extends HttpServlet
{
//*****************************************************************************
// Variables
//*****************************************************************************

/**
* Description of stmt: the JDBC statement
**/
Statement stmt=null;
/**
* Description of driver: the JDBC driver
**/
Driver driver;
/**
* Description of conn: the JDBC connection
**/
Connection conn=null;
/**
* Description of results: the JDBC result set
**/
ResultSet results;
/**
* Description of tempString: a temporary String variable
**/
String tempString;
/**
* Description of tempInt: a temporary int variable
**/
int tempInt;
/**
* Description of tempDate: a temporary Date variable
**/
java.sql.Date tempDate;
/**
* Description of sql: the SQL SELECT statement run against the database
**/
String sql;
/**
* Description of driverName: the name of the database driver
**/
String driverName;
/**
* Description of connectionString: the database server IP address and port number
**/
String connectionString;
/**
* Description of username: the username to connect to the database
**/
String username;
/**
* Description of password: the password to connect to the database
**/
String password;
/**
* Description of formatter: used to format and parse dates
**/
SimpleDateFormat formatter;
/**
* Description of formatter1: used to format and parse dates
**/
SimpleDateFormat formatter1;
/**
* Description of outWriter: used to write to the export file
**/
BufferedWriter outWriter;
/**
* Description of tempString1: a temporary String variable
**/
String tempString1;
/**
* Description of filename: the name of the file to be exported to
**/
String filename;
/**
* Description of summary: determines whether to out each individual message
**/
String summary;
/**
* Description of calendar: used to calculate the current date
**/
GregorianCalendar calendar;
/**
* Description of date1: a temporary date value
**/
java.util.Date date1;
/**
* Description of localDate: the local date
*/
java.util.Date localDate;
/**
* Description of months: an array of Strings containing the names of the months
**/
String months[];
/**
* Description of currentMonth: today's month
**/
int currentMonth;
/**
* Description of currentDay: today's day
**/
int currentDay;
/**
* Description of currentYear: today's year
**/
int currentYear;
/**
* Description of startMonth: the month to start reporting on
**/
int startMonth;
/**
* Description of startDay: the day to start reporting on
**/
int startDay;
/**
* Description of startYear: the year to start reporting on
**/
int startYear;
/**
* Description of endMonth: the month to end reporting on
**/
int endMonth;
/**
* Description of endDay: the day to end reporting on
**/
int endDay;
/**
* Description of endYear: the year to end reporting on
**/
int endYear;
/**
* Description of createDate: the date that the current user account
**/
java.sql.Date createDate;
/**
* Description of startDate: the start of the reporting period
**/
java.util.Date startDate;
/**
* Description of endDate: the end of the reporting period
**/
java.util.Date endDate;
/**
* Description of all: indicates whether to filter user accounts based on creation date
**/
String all;
/**
* Description of timeZone: used to calculated NZ time
**/
TimeZone timeZone;
/**
* Description of sortColumn: column to sort by
*/
String sortColumn;
/**
* Description of columnVector: vector of column names
*/
Vector columnVector;
/**
* Description of orginalStartMonth: the original month the report is to start
*/
int originalStartMonth;
/**
* Description of reportDirectory: the directory to export files are to be put
*/
String reportsDirectory;
/**
* Description of userType: the type of the current user
*/
String userType;
/**
* Description of MSISDN : the type of mobile user
*/
String minnumber;
String minnumber1=&quot;&quot;;
/**
* Description of non_mobileusers: the category of the users
*/
String nonmobusers;
String text;
/**
* init
*
* @param config: the server configuration
*/
public void init(ServletConfig config) throws ServletException
{
super.init(config);
// calculate the current time in NZ
formatter= new SimpleDateFormat(&quot;MM/dd/yyyy&quot;);
formatter1= new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
timeZone=TimeZone.getTimeZone(&quot;Pacific/Auckland&quot;);
calendar=new GregorianCalendar();
calendar.setTimeZone(timeZone);
date1=new java.util.Date();
calendar.setTime(date1);
formatter.setCalendar(calendar);
localDate=new java.util.Date();

months=new String[12];
months[0]=&quot;January&quot;;
months[1]=&quot;February&quot;;
months[2]=&quot;March&quot;;
months[3]=&quot;April&quot;;
months[4]=&quot;May&quot;;
months[5]=&quot;June&quot;;
months[6]=&quot;July&quot;;
months[7]=&quot;August&quot;;
months[8]=&quot;September&quot;;
months[9]=&quot;October&quot;;
months[10]=&quot;November&quot;;
months[11]=&quot;December&quot;;

//columnVector=new Vector(5,5);

// get database parameters from zone.properties file
driverName=getInitParameter(&quot;driverName&quot;);
connectionString=getInitParameter(&quot;connectionString1&quot;);
username=getInitParameter(&quot;username1&quot;);
password=getInitParameter(&quot;password1&quot;);
filename=getInitParameter(&quot;filename&quot;);
if (filename==null)
filename=&quot;&quot;;
//text=getInitParameter(&quot;details&quot;);
//if (text==null)
//text=&quot;&quot;;
sortColumn=getInitParameter(&quot;sortColumn&quot;);
if (sortColumn==null)
sortColumn=&quot;&quot;;
reportsDirectory=getInitParameter(&quot;reportsDirectory&quot;);
if (reportsDirectory==null)
reportsDirectory=&quot;&quot;;

// connect to database
try
{
driver=(Driver)Class.forName(driverName).newInstance();
}
catch (Exception e1)
{
log(e1.getMessage());
}
try
{
conn=DriverManager.getConnection(connectionString,username,password);
}
catch (Exception e2)
{
log(e2.getMessage());
}
try
{
stmt=conn.createStatement();
}
catch (Exception e3)
{
log(e3.getMessage());
}
}

/**
* Responds to a Get request from the user
*
* @param request: the request received from the user
* @param response: the response returned to the user
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
/**
* Description of x: a temporary variable
**/
int x;
/**
* Description of columnName: name of the current column
**/
String columnName;
/**
* Description of columnType: data type of current column
**/
String columnType;
/**
* Description of returnString: temporary String variable
**/
String returnString;
/**
* Description of totalUsers: counter for total users
**/
int totalUsers=0;
/**
* Description of out: used to write html to response page
**/
PrintWriter out;
/**
* Description of monthTo: the ending month for the report passed in via HTTP request
**/
String monthTo;
/**
* Description of dayTo: the ending day for the report passed in via HTTP request
**/
String dayTo;
/**
* Description of yearTo: the ending year for the report passed in via HTTP request
**/
String yearTo;
/**
* Description of monthFrom: the starting month for the report passed in via HTTP request
**/
String monthFrom;
/**
* Description of dayFrom: the starting day for the report passed in via HTTP request
**/
String dayFrom;
/**
* Description of yearFrom: the starting year for the report passed in via HTTP request
**/
String yearFrom;
/**
* Description of metaData: data about the data retrieved from the database
**/
ResultSetMetaData metaData;
/**
* Description of columnCount: number of columns in the result set
**/

columnVector=new Vector(5,5);

int columnCount;

int count021=0;
//int countNon021=0;
int count029=0;
//int countWAP=0;
int countNonMobile=0;
out = new PrintWriter (response.getOutputStream());

sql=getInitParameter(&quot;sql&quot;);

// if filename passed in as a HTTP request parameter, override existing value
tempString=request.getParameter(&quot;filename&quot;);
if ((tempString!=null) && (tempString.length()>0))
filename=tempString;

// if details passed in as a HTTP request parameter display details of each user
summary=request.getParameter(&quot;summary&quot;);
if (summary==null)
summary=&quot;&quot;;

// if filterCreate passed in as a HTTP request parameter filter users by account creation date
all=request.getParameter(&quot;all&quot;);
if (all==null)
all=&quot;&quot;;

// get the report date range from the HTTP request
monthFrom=request.getParameter(&quot;MONTH_FROM&quot;);
if (monthFrom!=null)
startMonth=new Integer(monthFrom).intValue();
else
startMonth=-1;
dayFrom=request.getParameter(&quot;DAY_FROM&quot;);
if (dayFrom!=null)
startDay=new Integer(dayFrom).intValue();
else
startDay=-1;
yearFrom=request.getParameter(&quot;YEAR_FROM&quot;);
if (yearFrom!=null)
startYear=new Integer(yearFrom).intValue();
else
startYear=-1;
monthTo=request.getParameter(&quot;MONTH_TO&quot;);
if (monthTo!=null)
endMonth=new Integer(monthTo).intValue();
else
endMonth=-1;
dayTo=request.getParameter(&quot;DAY_TO&quot;);
if (dayTo!=null)
endDay=new Integer(dayTo).intValue();
else
endDay=-1;
yearTo=request.getParameter(&quot;YEAR_TO&quot;);
if (yearTo!=null)
endYear=new Integer(yearTo).intValue();
else
endYear=-1;

// get into about the current time
currentYear=calendar.get(Calendar.YEAR);
currentMonth=calendar.get(Calendar.MONTH);
currentDay=calendar.get(Calendar.DATE);

// if no request parameters passed in set the report period to today
originalStartMonth=startMonth;
if (startMonth==-1)
{
startDay=currentDay;
endDay=currentDay;
startMonth=currentMonth;
endMonth=currentMonth;
startYear=currentYear;
endYear=currentYear;
}

calendar.set(startYear,startMonth,startDay);
if (originalStartMonth==-1)
calendar.add(Calendar.DATE,-7);
startDate=calendar.getTime();
//out.println(&quot;StartDate: &quot;+startDate+&quot;<p>&quot;);
startDay=calendar.get(Calendar.DATE);
startMonth=calendar.get(Calendar.MONTH);
startYear=calendar.get(Calendar.YEAR);

calendar.set(endYear,endMonth,endDay);
endDate=calendar.getTime();
//out.println(endDate);

// create export file

try
{
if ((filename!=null) && (filename.length()>0))
{
outWriter= new BufferedWriter(new FileWriter(filename, false));
}
else
{
outWriter=null;
}
}
catch (IOException e)
{
outWriter=null;
}

response.setContentType(&quot;text/html&quot;);
// response.setDateHeader();
out.println(&quot;<HEAD>&quot;);
out.println(&quot;<TITLE>Registrations Report</TITLE>&quot;);
out.println(&quot;</HEAD>&quot;);
out.println(&quot;<BODY BGCOLOR='#FFFFFF'>&quot;);
out.println(&quot;<FONT FACE='Arial,Helvetica'>&quot;);
out.println(&quot;<IMG SRC='/vodafone_logo.gif' ><BR>&quot;);
out.println(&quot;<B>Registrations Report</B><P>&quot;);
if (outWriter!=null)
outWriter.write(&quot;Registrations Report\n&quot;);
if (outWriter!=null)
outWriter.write(&quot;Report Run: &quot;+localDate+&quot;\n\n&quot;);

// if filtering users by account creation date
if (all==&quot;&quot;)
{
tempString=&quot;Users created from &quot;+formatter.format(startDate);
tempString=tempString+&quot; to &quot;+formatter.format(endDate)+&quot; (New Zealand time)<br>&quot;;
out.println(tempString+&quot;<br>&quot;);
out.println(&quot;This report includes all users who completed the registration process during a period. This includes all users who are registered on the site including system 'active', 'barred', 'locked', 'inactive' and 'deleted TBC users.<br>&quot;);
//out.println(text+&quot;<br>&quot;);
if (outWriter!=null)
outWriter.write(tempString+&quot;\n&quot;);
//outWriter.write(text+&quot;<br>&quot;);

//tempString=&quot; AND ((UP_REGISTRATION_DATE > TO_DATE('&quot;+formatter1.format(startDate)+&quot;','YYYY-MM-DD')) AND (UP_REGISTRATION_DATE < TO_DATE('&quot;+formatter1.format(endDate)+&quot;','YYYY-MM-DD')))&quot;;
tempString=&quot; AND (TRUNC(UP_REGISTRATION_DATE) BETWEEN (TO_DATE('&quot;+formatter1.format(startDate)+&quot;','YYYY-MM-DD')) AND (TO_DATE('&quot;+formatter1.format(endDate)+&quot;','YYYY-MM-DD')))&quot;;
//tempString=&quot; WHERE FNAME= 'TOM' &quot;;
sql=sql+tempString;
//out.println(&quot;SQL: &quot;+sql+&quot;<br>&quot;);
}

// if sortColumn passed in as a HTTP request parameter override existing value
tempString=request.getParameter(&quot;SORT_COLUMN&quot;);
if ((tempString!=null) && (tempString.length()>0))
sortColumn=tempString;
//sql=sql+&quot; ORDER BY &quot;+sortColumn;

try
{
//out.println(sql);
results=stmt.executeQuery(sql);
metaData=results.getMetaData();
columnCount=metaData.getColumnCount();
tempString1=&quot;&quot;;
// output column headings
tempString=&quot;<TABLE BORDER WIDTH='100%'><TR>&quot;;
for (x=1;x<=columnCount;x++)
{
columnName=metaData.getColumnName(x);
//out.println(&quot;columnnames&quot;+columnName);
tempString1=tempString1+columnName+&quot;,&quot;;
columnVector.addElement(columnName);
tempString=tempString+&quot;<TD>&quot;+columnName+&quot;</TD>&quot;;
}
tempString=tempString+&quot;</TR>&quot;;
if (summary==&quot;&quot;)
out.println(tempString);
tempString1=tempString1+&quot;\n&quot;;
if (outWriter!=null)
outWriter.write(tempString1);

// loop through records in resultset
while (results.next())
{
returnString=&quot;<TR>&quot;;
try
{
// OLD CODE
//userType=results.getString(&quot;LO_USER_TYPE&quot;);
//if (userType.indexOf(&quot;1&quot;)>-1)
//count021++;
// END OF OLD CODE
minnumber=results.getString(4);
totalUsers++;
minnumber=minnumber.substring(1,5);
//minnumber=minnumber.substring(1,4);
if(minnumber.equals(new String(&quot;6421&quot;)))
//if(minnumber.equals(new String(&quot;614&quot;)))
count021++;
else if(minnumber.equals(new String(&quot;6429&quot;)))
count029++;
}
catch (Exception e)
{
//count021++;
}


//out.println(count021++);
//count029++;
//countNonMobile++;

tempString1=&quot;&quot;;
countNonMobile=totalUsers-count021-count029;
//countNonMobile=totalUsers-count021;
// loop through columns displaying each according to its datatype
for (x=1;x<=columnCount;x++)
{
columnType=metaData.getColumnTypeName(x);
columnName=metaData.getColumnName(x);
if (columnType.indexOf(&quot;NUMBER&quot;)>-1)
{
tempInt=results.getInt(x);
tempString1=tempString1+tempInt+&quot;,&quot;;
returnString=returnString+&quot;<TD>&quot;+tempInt+&quot;</TD>&quot;;
}
else if (columnType.indexOf(&quot;CHAR&quot;)>-1)
{
tempString=results.getString(x);
if (tempString==null)
tempString=&quot;&quot;;
tempString1=tempString1+'&quot;'+tempString+'&quot;'+',';
returnString=returnString+&quot;<TD>&quot;+tempString+&quot;</TD>&quot;;
}
else if (columnType.indexOf(&quot;DATE&quot;)>-1)
{
tempDate=results.getDate(x);
if (tempDate!=null)
{
tempString=tempDate.toString();
if ((tempString!=null) && (tempString.length()>0))
{
tempString1=tempString1+ReportMenu.formatDateString(tempDate)+&quot;,&quot;;
returnString=returnString+&quot;<TD>&quot;+formatter.format(tempDate)+&quot;</TD>&quot;;
}
else
{
tempString1=tempString1+&quot;,&quot;;
returnString=returnString+&quot;<TD></TD>&quot;;
}
}
}
}
tempString1=tempString1+&quot;\n&quot;;
returnString=returnString+&quot;</TR>&quot;;
if (summary==&quot;&quot;)
out.println(returnString);
if (outWriter!=null)
outWriter.write(tempString1);
}
returnString=&quot;</TABLE>&quot;;
if (summary==&quot;&quot;)
out.println(returnString);
out.println(&quot;<P>&quot;);
out.println(&quot;<TABLE>&quot;);
tempString=&quot;Total Users: &quot;+totalUsers+&quot;<br>&quot;;
out.println(&quot;<TR><TD>Total Users:</TD><TD>&quot;+totalUsers+&quot;</TD></TR>&quot;);
if (outWriter!=null)
outWriter.write(&quot;\n&quot;+tempString);
tempString=&quot;Total 021 Users: &quot;+count021+&quot;<br>&quot;;
tempString=&quot;Total 641 Users: &quot;+count021+&quot;<br>&quot;;;
out.println(&quot;<TR><TD>Total 641 Users:</TD><TD>&quot;+count021+&quot;</TD></TR>&quot;);
//out.println(&quot;<TR><TD>Total 021 Users:</TD><TD>&quot;+count021+&quot;</TD></TR>&quot;);
// out.println(tempString);
if (outWriter!=null)
outWriter.write(&quot;\n&quot;+tempString);
//tempString=&quot;Total non-021 Users: &quot;+countNon021+&quot;<br>&quot;;
//tempString=&quot;Total 029 Users: &quot;+count029+&quot;<br>&quot;;
//out.println(&quot;<TR><TD>Total 029 Users:</TD><TD>&quot;+count029+&quot;</TD></TR>&quot;);
// out.println(tempString);
if (outWriter!=null)
outWriter.write(&quot;\n&quot;+tempString);
tempString=&quot;Total Non-Mobile Users: &quot;+countNonMobile+&quot;<br>&quot;;;
out.println(&quot;<TR><TD>Total Non-Mobile Users:</TD><TD>&quot;+countNonMobile+&quot;</TD></TR>&quot;);
// out.println(tempString);
if (outWriter!=null)
outWriter.write(&quot;\n&quot;+tempString);
out.println(&quot;<TABLE>&quot;);

// output a form on which the users may change the report parameters
out.println(&quot;<HR>&quot;);
out.println(&quot;<B>Parameters</B><br>&quot;);
out.println(&quot;Change the parameters below and press Submit in order to regenerate this report<br>&quot;);
out.println(&quot;<FORM method=GET action='/servlet/RegistrationsReport'>&quot;);
out.println(&quot;<TABLE>&quot;);
//out.println(&quot;<TR><TD>Export Filename:</TD><TD> <INPUT required value='&quot;+filename+&quot;' name='filename'></TD></TR>&quot;);
out.println(&quot;<TR><TD>Display Summary Only</TD><TD><input type=CHECKBOX value='CHECKED' name='summary' &quot;+summary+&quot;></TD></TR>&quot;);
out.println(&quot;<TR><TD>Display All Records</TD><TD><input type=CHECKBOX value='CHECKED' name='all' &quot;+all+&quot;></TD></TR>&quot;);
out.println(&quot;<TR><TD>From Date</TD>&quot;);
out.println(&quot;<TD><SELECT NAME=MONTH_FROM>&quot;);
for (x=0;x<12;x++)
{
if (x==(startMonth))
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot; SELECTED>&quot;+months[x]);
}
else
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot;>&quot;+months[x]);
}
}
out.println(&quot;</SELECT>&quot;);
out.println(&quot;<SELECT NAME=DAY_FROM>&quot;);
for (x=1;x<=31;x++)
{
if (x==startDay)
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot; SELECTED>&quot;+x);
}
else
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot;>&quot;+x);
}
}
out.println(&quot;</SELECT>&quot;);
out.println(&quot;<INPUT TYPE=TEXT NAME=YEAR_FROM SIZE=5 VALUE=&quot;+startYear+&quot;></TD></TR>&quot;);
out.println(&quot;<TR><TD>To Date</TD>&quot;);
out.println(&quot;<TD><SELECT NAME=MONTH_TO>&quot;);
for (x=0;x<12;x++)
{
if (x==(endMonth))
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot; SELECTED>&quot;+months[x]);
}
else
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot;>&quot;+months[x]);
}
}
out.println(&quot;</SELECT>&quot;);
out.println(&quot;<SELECT NAME=DAY_TO>&quot;);
for (x=1;x<=31;x++)
{
if (x==endDay)
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot; SELECTED>&quot;+x);
}
else
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot;>&quot;+x);
}
}
out.println(&quot;</SELECT>&quot;);
out.println(&quot;<INPUT TYPE=TEXT SIZE=5 NAME=YEAR_TO VALUE=&quot;+endYear+&quot;>&quot;);
out.println(&quot;<TR><TD>Order By:</TD><TD><SELECT NAME=SORT_COLUMN>&quot;);
for (x=0;x<columnVector.size();x++)
{
tempString=(String)columnVector.elementAt(x);
if (tempString.indexOf(sortColumn)>-1)
out.println(&quot;<OPTION VALUE=&quot;+tempString+&quot; SELECTED>&quot;+tempString);
else
out.println(&quot;<OPTION VALUE=&quot;+tempString+&quot;>&quot;+tempString);
}
out.println(&quot;</SELECT></TD></TR>&quot;);
out.println(&quot;<TR><TD><input type=SUBMIT value='Submit'></TD></TR>&quot;);
out.println(&quot;</TABLE>&quot;);
out.println(&quot;</FORM>&quot;);

if (outWriter!=null)
outWriter.close();
}
catch (Exception e4)
{
out.println(e4.getMessage());
}
//out.println(&quot;<A HREF='&quot;+reportsDirectory+&quot;'>Exported csv files </A><BR>&quot;);
// out.println(&quot;<BR><IMG SRC='/poweredby_vgp.gif' ><BR>&quot;);
out.flush();
out.close();
}

/**
* Close database connection when unloaded from memory
*/
public void destroy()
{
try
{
conn.close();
}
catch (SQLException e)
{
}
}
}


Thank you
 
Hi LeonTang,
the code is pasted below. Please give me the solution as soon as possible.

package com.vip.portal.systemlevelservices.reporting;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.text.*;

//******************************************************************************
// ClassFile
//******************************************************************************
/**
* <STRONG>
* Description:
* </STRONG><BR>

This class generates a report on portal users

* @version <PRE>
* $History: UsersReport.java $
*
* ***************** Version 1 *****************
* User: Andrew Linton Date: 10-26-2000 Time: 14:00
* User: Srikanth K. changes are made in the code
* *
* </PRE>
**/
//********************************************************************************/

public class UsersReport extends HttpServlet
{
//*****************************************************************************
// Variables
//*****************************************************************************

/**
* Description of stmt: the JDBC statement
**/
Statement stmt=null;
/**
* Description of driver: the JDBC driver
**/
Driver driver;
/**
* Description of conn: the JDBC connection
**/
Connection conn=null;
/**
* Description of results: the JDBC result set
**/
ResultSet results;
/**
* Description of tempString: a temporary String variable
**/
String tempString;
/**
* Description of tempInt: a temporary int variable
**/
int tempInt;
/**
* Description of tempDate: a temporary Date variable
**/
java.sql.Date tempDate;
/**
* Description of sql: the SQL SELECT statement run against the database
**/
String sql;
/**
* Description of driverName: the name of the database driver
**/
String driverName;
/**
* Description of connectionString: the database server IP address and port number
**/
String connectionString;
/**
* Description of username: the username to connect to the database
**/
String username;
/**
* Description of password: the password to connect to the database
**/
String password;
/**
* Description of formatter: used to format and parse dates
**/
SimpleDateFormat formatter;
/**
* Description of formatter1: used to format and parse dates
**/
SimpleDateFormat formatter1;
/**
* Description of outWriter: used to write to the export file
**/
BufferedWriter outWriter;
/**
* Description of tempString1: a temporary String variable
**/
String tempString1;
/**
* Description of filename: the name of the file to be exported to
**/
String filename;
/**
* Description of summary: determines whether to out each individual message
**/
String summary;
/**
* Description of calendar: used to calculate the current date
**/
GregorianCalendar calendar;
/**
* Description of date1: a temporary date value
**/
java.util.Date date1;
/**
* Description of localDate: the local date
*/
java.util.Date localDate;
/**
* Description of months: an array of Strings containing the names of the months
**/
String months[];
/**
* Description of currentMonth: today's month
**/
int currentMonth;
/**
* Description of currentDay: today's day
**/
int currentDay;
/**
* Description of currentYear: today's year
**/
int currentYear;
/**
* Description of startMonth: the month to start reporting on
**/
int startMonth;
/**
* Description of startDay: the day to start reporting on
**/
int startDay;
/**
* Description of startYear: the year to start reporting on
**/
int startYear;
/**
* Description of endMonth: the month to end reporting on
**/
int endMonth;
/**
* Description of endDay: the day to end reporting on
**/
int endDay;
/**
* Description of endYear: the year to end reporting on
**/
int endYear;
/**
* Description of createDate: the date that the current user account
**/
java.sql.Date createDate;
/**
* Description of startDate: the start of the reporting period
**/
java.util.Date startDate;
/**
* Description of endDate: the end of the reporting period
**/
java.util.Date endDate;
/**
* Description of all: indicates whether to filter user accounts based on creation date
**/
String all;
/**
* Description of timeZone: used to calculated NZ time
**/
TimeZone timeZone;
/**
* Description of sortColumn: column to sort by
*/
String sortColumn;
/**
* Description of columnVector: vector of column names
*/
Vector columnVector;
/**
* Description of orginalStartMonth: the original month the report is to start
*/
int originalStartMonth;
/**
* Description of reportDirectory: the directory to export files are to be put
*/
String reportsDirectory;
/**
* Description of userType: the type of the current user
*/
String userType;
/**
* Description of MSISDN : the type of mobile user
*/
String minnumber;
String minnumber1=&quot;&quot;;
/**
* Description of non_mobileusers: the category of the users
*/
String nonmobusers;
String text;
/**
* init
*
* @param config: the server configuration
*/
public void init(ServletConfig config) throws ServletException
{
super.init(config);
// calculate the current time in NZ
formatter= new SimpleDateFormat(&quot;MM/dd/yyyy&quot;);
formatter1= new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
timeZone=TimeZone.getTimeZone(&quot;Pacific/Auckland&quot;);
calendar=new GregorianCalendar();
calendar.setTimeZone(timeZone);
date1=new java.util.Date();
calendar.setTime(date1);
formatter.setCalendar(calendar);
localDate=new java.util.Date();

months=new String[12];
months[0]=&quot;January&quot;;
months[1]=&quot;February&quot;;
months[2]=&quot;March&quot;;
months[3]=&quot;April&quot;;
months[4]=&quot;May&quot;;
months[5]=&quot;June&quot;;
months[6]=&quot;July&quot;;
months[7]=&quot;August&quot;;
months[8]=&quot;September&quot;;
months[9]=&quot;October&quot;;
months[10]=&quot;November&quot;;
months[11]=&quot;December&quot;;

//columnVector=new Vector(5,5);

// get database parameters from zone.properties file
driverName=getInitParameter(&quot;driverName&quot;);
connectionString=getInitParameter(&quot;connectionString1&quot;);
username=getInitParameter(&quot;username1&quot;);
password=getInitParameter(&quot;password1&quot;);
filename=getInitParameter(&quot;filename&quot;);
if (filename==null)
filename=&quot;&quot;;
//text=getInitParameter(&quot;details&quot;);
//if (text==null)
//text=&quot;&quot;;
sortColumn=getInitParameter(&quot;sortColumn&quot;);
if (sortColumn==null)
sortColumn=&quot;&quot;;
reportsDirectory=getInitParameter(&quot;reportsDirectory&quot;);
if (reportsDirectory==null)
reportsDirectory=&quot;&quot;;

// connect to database
try
{
driver=(Driver)Class.forName(driverName).newInstance();
}
catch (Exception e1)
{
log(e1.getMessage());
}
try
{
conn=DriverManager.getConnection(connectionString,username,password);
}
catch (Exception e2)
{
log(e2.getMessage());
}
try
{
stmt=conn.createStatement();
}
catch (Exception e3)
{
log(e3.getMessage());
}
}

/**
* Responds to a Get request from the user
*
* @param request: the request received from the user
* @param response: the response returned to the user
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
/**
* Description of x: a temporary variable
**/
int x;
/**
* Description of columnName: name of the current column
**/
String columnName;
/**
* Description of columnType: data type of current column
**/
String columnType;
/**
* Description of returnString: temporary String variable
**/
String returnString;
/**
* Description of totalUsers: counter for total users
**/
int totalUsers=0;
/**
* Description of out: used to write html to response page
**/
PrintWriter out;
/**
* Description of monthTo: the ending month for the report passed in via HTTP request
**/
String monthTo;
/**
* Description of dayTo: the ending day for the report passed in via HTTP request
**/
String dayTo;
/**
* Description of yearTo: the ending year for the report passed in via HTTP request
**/
String yearTo;
/**
* Description of monthFrom: the starting month for the report passed in via HTTP request
**/
String monthFrom;
/**
* Description of dayFrom: the starting day for the report passed in via HTTP request
**/
String dayFrom;
/**
* Description of yearFrom: the starting year for the report passed in via HTTP request
**/
String yearFrom;
/**
* Description of metaData: data about the data retrieved from the database
**/
ResultSetMetaData metaData;
/**
* Description of columnCount: number of columns in the result set
**/

columnVector=new Vector(5,5);

int columnCount;

int count021=0;
//int countNon021=0;
int count029=0;
//int countWAP=0;
int countNonMobile=0;
out = new PrintWriter (response.getOutputStream());

sql=getInitParameter(&quot;sql&quot;);

// if filename passed in as a HTTP request parameter, override existing value
tempString=request.getParameter(&quot;filename&quot;);
if ((tempString!=null) && (tempString.length()>0))
filename=tempString;

// if details passed in as a HTTP request parameter display details of each user
summary=request.getParameter(&quot;summary&quot;);
if (summary==null)
summary=&quot;&quot;;

// if filterCreate passed in as a HTTP request parameter filter users by account creation date
all=request.getParameter(&quot;all&quot;);
if (all==null)
all=&quot;&quot;;

// get the report date range from the HTTP request
monthFrom=request.getParameter(&quot;MONTH_FROM&quot;);
if (monthFrom!=null)
startMonth=new Integer(monthFrom).intValue();
else
startMonth=-1;
dayFrom=request.getParameter(&quot;DAY_FROM&quot;);
if (dayFrom!=null)
startDay=new Integer(dayFrom).intValue();
else
startDay=-1;
yearFrom=request.getParameter(&quot;YEAR_FROM&quot;);
if (yearFrom!=null)
startYear=new Integer(yearFrom).intValue();
else
startYear=-1;
monthTo=request.getParameter(&quot;MONTH_TO&quot;);
if (monthTo!=null)
endMonth=new Integer(monthTo).intValue();
else
endMonth=-1;
dayTo=request.getParameter(&quot;DAY_TO&quot;);
if (dayTo!=null)
endDay=new Integer(dayTo).intValue();
else
endDay=-1;
yearTo=request.getParameter(&quot;YEAR_TO&quot;);
if (yearTo!=null)
endYear=new Integer(yearTo).intValue();
else
endYear=-1;

// get into about the current time
currentYear=calendar.get(Calendar.YEAR);
currentMonth=calendar.get(Calendar.MONTH);
currentDay=calendar.get(Calendar.DATE);

// if no request parameters passed in set the report period to today
originalStartMonth=startMonth;
if (startMonth==-1)
{
startDay=currentDay;
endDay=currentDay;
startMonth=currentMonth;
endMonth=currentMonth;
startYear=currentYear;
endYear=currentYear;
}

calendar.set(startYear,startMonth,startDay);
if (originalStartMonth==-1)
calendar.add(Calendar.DATE,-7);
startDate=calendar.getTime();
//out.println(&quot;StartDate: &quot;+startDate+&quot;<p>&quot;);
startDay=calendar.get(Calendar.DATE);
startMonth=calendar.get(Calendar.MONTH);
startYear=calendar.get(Calendar.YEAR);

calendar.set(endYear,endMonth,endDay);
endDate=calendar.getTime();
//out.println(endDate);

// create export file

try
{
if ((filename!=null) && (filename.length()>0))
{
outWriter= new BufferedWriter(new FileWriter(filename, false));
}
else
{
outWriter=null;
}
}
catch (IOException e)
{
outWriter=null;
}

response.setContentType(&quot;text/html&quot;);
// response.setDateHeader();
out.println(&quot;<HEAD>&quot;);
out.println(&quot;<TITLE>Registrations Report</TITLE>&quot;);
out.println(&quot;</HEAD>&quot;);
out.println(&quot;<BODY BGCOLOR='#FFFFFF'>&quot;);
out.println(&quot;<FONT FACE='Arial,Helvetica'>&quot;);
out.println(&quot;<IMG SRC='/vodafone_logo.gif' ><BR>&quot;);
out.println(&quot;<B>Registrations Report</B><P>&quot;);
if (outWriter!=null)
outWriter.write(&quot;Registrations Report\n&quot;);
if (outWriter!=null)
outWriter.write(&quot;Report Run: &quot;+localDate+&quot;\n\n&quot;);

// if filtering users by account creation date
if (all==&quot;&quot;)
{
tempString=&quot;Users created from &quot;+formatter.format(startDate);
tempString=tempString+&quot; to &quot;+formatter.format(endDate)+&quot; (New Zealand time)<br>&quot;;
out.println(tempString+&quot;<br>&quot;);
out.println(&quot;This report includes all users who completed the registration process during a period. This includes all users who are registered on the site including system 'active', 'barred', 'locked', 'inactive' and 'deleted TBC users.<br>&quot;);
//out.println(text+&quot;<br>&quot;);
if (outWriter!=null)
outWriter.write(tempString+&quot;\n&quot;);
//outWriter.write(text+&quot;<br>&quot;);

//tempString=&quot; AND ((UP_REGISTRATION_DATE > TO_DATE('&quot;+formatter1.format(startDate)+&quot;','YYYY-MM-DD')) AND (UP_REGISTRATION_DATE < TO_DATE('&quot;+formatter1.format(endDate)+&quot;','YYYY-MM-DD')))&quot;;
tempString=&quot; AND (TRUNC(UP_REGISTRATION_DATE) BETWEEN (TO_DATE('&quot;+formatter1.format(startDate)+&quot;','YYYY-MM-DD')) AND (TO_DATE('&quot;+formatter1.format(endDate)+&quot;','YYYY-MM-DD')))&quot;;
//tempString=&quot; WHERE FNAME= 'TOM' &quot;;
sql=sql+tempString;
//out.println(&quot;SQL: &quot;+sql+&quot;<br>&quot;);
}

// if sortColumn passed in as a HTTP request parameter override existing value
tempString=request.getParameter(&quot;SORT_COLUMN&quot;);
if ((tempString!=null) && (tempString.length()>0))
sortColumn=tempString;
//sql=sql+&quot; ORDER BY &quot;+sortColumn;

try
{
//out.println(sql);
results=stmt.executeQuery(sql);
metaData=results.getMetaData();
columnCount=metaData.getColumnCount();
tempString1=&quot;&quot;;
// output column headings
tempString=&quot;<TABLE BORDER WIDTH='100%'><TR>&quot;;
for (x=1;x<=columnCount;x++)
{
columnName=metaData.getColumnName(x);
//out.println(&quot;columnnames&quot;+columnName);
tempString1=tempString1+columnName+&quot;,&quot;;
columnVector.addElement(columnName);
tempString=tempString+&quot;<TD>&quot;+columnName+&quot;</TD>&quot;;
}
tempString=tempString+&quot;</TR>&quot;;
if (summary==&quot;&quot;)
out.println(tempString);
tempString1=tempString1+&quot;\n&quot;;
if (outWriter!=null)
outWriter.write(tempString1);

// loop through records in resultset
while (results.next())
{
returnString=&quot;<TR>&quot;;
try
{
// OLD CODE
//userType=results.getString(&quot;LO_USER_TYPE&quot;);
//if (userType.indexOf(&quot;1&quot;)>-1)
//count021++;
// END OF OLD CODE
minnumber=results.getString(4);
totalUsers++;
minnumber=minnumber.substring(1,5);
//minnumber=minnumber.substring(1,4);
if(minnumber.equals(new String(&quot;6421&quot;)))
//if(minnumber.equals(new String(&quot;614&quot;)))
count021++;
else if(minnumber.equals(new String(&quot;6429&quot;)))
count029++;
}
catch (Exception e)
{
//count021++;
}


//out.println(count021++);
//count029++;
//countNonMobile++;

tempString1=&quot;&quot;;
countNonMobile=totalUsers-count021-count029;
//countNonMobile=totalUsers-count021;
// loop through columns displaying each according to its datatype
for (x=1;x<=columnCount;x++)
{
columnType=metaData.getColumnTypeName(x);
columnName=metaData.getColumnName(x);
if (columnType.indexOf(&quot;NUMBER&quot;)>-1)
{
tempInt=results.getInt(x);
tempString1=tempString1+tempInt+&quot;,&quot;;
returnString=returnString+&quot;<TD>&quot;+tempInt+&quot;</TD>&quot;;
}
else if (columnType.indexOf(&quot;CHAR&quot;)>-1)
{
tempString=results.getString(x);
if (tempString==null)
tempString=&quot;&quot;;
tempString1=tempString1+'&quot;'+tempString+'&quot;'+',';
returnString=returnString+&quot;<TD>&quot;+tempString+&quot;</TD>&quot;;
}
else if (columnType.indexOf(&quot;DATE&quot;)>-1)
{
tempDate=results.getDate(x);
if (tempDate!=null)
{
tempString=tempDate.toString();
if ((tempString!=null) && (tempString.length()>0))
{
tempString1=tempString1+ReportMenu.formatDateString(tempDate)+&quot;,&quot;;
returnString=returnString+&quot;<TD>&quot;+formatter.format(tempDate)+&quot;</TD>&quot;;
}
else
{
tempString1=tempString1+&quot;,&quot;;
returnString=returnString+&quot;<TD></TD>&quot;;
}
}
}
}
tempString1=tempString1+&quot;\n&quot;;
returnString=returnString+&quot;</TR>&quot;;
if (summary==&quot;&quot;)
out.println(returnString);
if (outWriter!=null)
outWriter.write(tempString1);
}
returnString=&quot;</TABLE>&quot;;
if (summary==&quot;&quot;)
out.println(returnString);
out.println(&quot;<P>&quot;);
out.println(&quot;<TABLE>&quot;);
tempString=&quot;Total Users: &quot;+totalUsers+&quot;<br>&quot;;
out.println(&quot;<TR><TD>Total Users:</TD><TD>&quot;+totalUsers+&quot;</TD></TR>&quot;);
if (outWriter!=null)
outWriter.write(&quot;\n&quot;+tempString);
tempString=&quot;Total 021 Users: &quot;+count021+&quot;<br>&quot;;
tempString=&quot;Total 641 Users: &quot;+count021+&quot;<br>&quot;;;
out.println(&quot;<TR><TD>Total 641 Users:</TD><TD>&quot;+count021+&quot;</TD></TR>&quot;);
//out.println(&quot;<TR><TD>Total 021 Users:</TD><TD>&quot;+count021+&quot;</TD></TR>&quot;);
// out.println(tempString);
if (outWriter!=null)
outWriter.write(&quot;\n&quot;+tempString);
//tempString=&quot;Total non-021 Users: &quot;+countNon021+&quot;<br>&quot;;
//tempString=&quot;Total 029 Users: &quot;+count029+&quot;<br>&quot;;
//out.println(&quot;<TR><TD>Total 029 Users:</TD><TD>&quot;+count029+&quot;</TD></TR>&quot;);
// out.println(tempString);
if (outWriter!=null)
outWriter.write(&quot;\n&quot;+tempString);
tempString=&quot;Total Non-Mobile Users: &quot;+countNonMobile+&quot;<br>&quot;;;
out.println(&quot;<TR><TD>Total Non-Mobile Users:</TD><TD>&quot;+countNonMobile+&quot;</TD></TR>&quot;);
// out.println(tempString);
if (outWriter!=null)
outWriter.write(&quot;\n&quot;+tempString);
out.println(&quot;<TABLE>&quot;);

// output a form on which the users may change the report parameters
out.println(&quot;<HR>&quot;);
out.println(&quot;<B>Parameters</B><br>&quot;);
out.println(&quot;Change the parameters below and press Submit in order to regenerate this report<br>&quot;);
out.println(&quot;<FORM method=GET action='/servlet/RegistrationsReport'>&quot;);
out.println(&quot;<TABLE>&quot;);
//out.println(&quot;<TR><TD>Export Filename:</TD><TD> <INPUT required value='&quot;+filename+&quot;' name='filename'></TD></TR>&quot;);
out.println(&quot;<TR><TD>Display Summary Only</TD><TD><input type=CHECKBOX value='CHECKED' name='summary' &quot;+summary+&quot;></TD></TR>&quot;);
out.println(&quot;<TR><TD>Display All Records</TD><TD><input type=CHECKBOX value='CHECKED' name='all' &quot;+all+&quot;></TD></TR>&quot;);
out.println(&quot;<TR><TD>From Date</TD>&quot;);
out.println(&quot;<TD><SELECT NAME=MONTH_FROM>&quot;);
for (x=0;x<12;x++)
{
if (x==(startMonth))
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot; SELECTED>&quot;+months[x]);
}
else
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot;>&quot;+months[x]);
}
}
out.println(&quot;</SELECT>&quot;);
out.println(&quot;<SELECT NAME=DAY_FROM>&quot;);
for (x=1;x<=31;x++)
{
if (x==startDay)
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot; SELECTED>&quot;+x);
}
else
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot;>&quot;+x);
}
}
out.println(&quot;</SELECT>&quot;);
out.println(&quot;<INPUT TYPE=TEXT NAME=YEAR_FROM SIZE=5 VALUE=&quot;+startYear+&quot;></TD></TR>&quot;);
out.println(&quot;<TR><TD>To Date</TD>&quot;);
out.println(&quot;<TD><SELECT NAME=MONTH_TO>&quot;);
for (x=0;x<12;x++)
{
if (x==(endMonth))
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot; SELECTED>&quot;+months[x]);
}
else
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot;>&quot;+months[x]);
}
}
out.println(&quot;</SELECT>&quot;);
out.println(&quot;<SELECT NAME=DAY_TO>&quot;);
for (x=1;x<=31;x++)
{
if (x==endDay)
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot; SELECTED>&quot;+x);
}
else
{
out.println(&quot;<OPTION VALUE=&quot;+x+&quot;>&quot;+x);
}
}
out.println(&quot;</SELECT>&quot;);
out.println(&quot;<INPUT TYPE=TEXT SIZE=5 NAME=YEAR_TO VALUE=&quot;+endYear+&quot;>&quot;);
out.println(&quot;<TR><TD>Order By:</TD><TD><SELECT NAME=SORT_COLUMN>&quot;);
for (x=0;x<columnVector.size();x++)
{
tempString=(String)columnVector.elementAt(x);
if (tempString.indexOf(sortColumn)>-1)
out.println(&quot;<OPTION VALUE=&quot;+tempString+&quot; SELECTED>&quot;+tempString);
else
out.println(&quot;<OPTION VALUE=&quot;+tempString+&quot;>&quot;+tempString);
}
out.println(&quot;</SELECT></TD></TR>&quot;);
out.println(&quot;<TR><TD><input type=SUBMIT value='Submit'></TD></TR>&quot;);
out.println(&quot;</TABLE>&quot;);
out.println(&quot;</FORM>&quot;);

if (outWriter!=null)
outWriter.close();
}
catch (Exception e4)
{
out.println(e4.getMessage());
}
//out.println(&quot;<A HREF='&quot;+reportsDirectory+&quot;'>Exported csv files </A><BR>&quot;);
// out.println(&quot;<BR><IMG SRC='/poweredby_vgp.gif' ><BR>&quot;);
out.flush();
out.close();
}

/**
* Close database connection when unloaded from memory
*/
public void destroy()
{
try
{
conn.close();
}
catch (SQLException e)
{
}
}
}

This servlet takes the values from the zone.properties file in the jserv.


Thank you
 
Hi,

I can't really find the error because I lack of the packages that you are using and the database, which I think it would also be inconvenient for you to pass to me as well.

But since it is an IOException, I guess it will have to do with your out and outWriter variables. I can't see what is wrong in your codes that might cause this problem so I guess I can't help much.

But I have some ways, which you can use to solve this yourself:-

1) take note of when the exception happens. For example, is there any resemblence between the situations when the same exception is caught?

2) when the exception is caught, try to print it out to the response html page. Meaning catch(Exception e) { out.println(e); } this way, you will be able to see the previous few lines that you have printed out to the html page as well. This will help you to know roughly where the error had occur.

3) if you still didn't manage to get the exact location using point 2 method, try to print as much lines as possible to the response html page. Like having out.println(123); (where 123 is the line number of your codes) after each line of codes. Although this is very troublesome, it will help you find the location where the error had occur. And remember to delete them away after you have managed to solve your problem :)

Hope this helps,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top