Best Projects

Bug Trackingsystem,Books online shopping,college management system,HR management system,Internet banking,Online chat room ,Online exam,Telephone billing system,Banking application,ATM database,airways reservation system,virtual network computing ,calculator,SMTP(simple mail transfer protocol)

Pizza Hut






PIZZA HUT HOMEPAGE









//Billing

import connections.Database;
import java.io.*;
import java.sql.*;

public class Billing {

/**
* Billing: Creates a billing statement from a mediated file,
* which in turn is written to the databse.
*
* jvargas
*/

Billing ( String dir ) throws Exception {
String filesToProcess[] = checkDir( dir );
for ( int ctr = 0; ctr < filesToProcess.length; ctr++ ) {
doBilling ( dir , filesToProcess[ctr] );
}
}
// process a single file
// skips the file if data contained is not valid
private void doBilling ( String srcDir , String fileName ) throws Exception {
BufferedReader br = null;
String inLine = "";
String[] transactions;
String temp[] = new String[200];
int trans_num = 0;
if ( !( srcDir.endsWith("\\") ) ) {
srcDir += "\\";
}

try {
br = new BufferedReader( new FileReader( srcDir + fileName ) );

while ( ( inLine = br.readLine() ) != null ) {
if ( inLine.length() != 59 ) { // check all lines in file
throw new StringIndexOutOfBoundsException();
}
else {
temp[trans_num++] = inLine;
}
}
transactions = new String[trans_num];
for ( int ctr = 0; ctr < trans_num; ctr++ ) {
transactions[ctr] = temp[ctr];
}
updateDatabase ( transactions ); // passes the transactions for database update
} catch ( StringIndexOutOfBoundsException outOfBounds ) {
System.out.println( srcDir + fileName + " ... data format incorrect.\nFile " + fileName + " will not be processed.\n" );
} catch ( Exception e ) {
throw e;
} finally { // close BufferedReader and BufferedWriter and delete the input file
try {
br.close();
} catch (Exception e) {

}
}
}
// connects and updates database
// given an array of transactions ( 1 file )
private void updateDatabase ( String[] transactions ) throws Exception {
double cost = 0.0;
String ACC_NUM = "" , IMSI = "" , TS = "" , UT = "" , TRANS_ID = "" , MO_DATE = "";

for ( int ctr = 0; ctr < transactions.length; ctr++ ) {
IMSI = transactions[ctr].substring( 0 , 20 );
TS = transactions[ctr].substring( 20 , 34 );
MO_DATE = transactions[ctr].substring( 23 , 28 );
UT = transactions[ctr].substring( 34 , 39 );
TRANS_ID = transactions[ctr].substring( 39 , 59 );
cost = computeCost ( UT );
Statement s = null;
ResultSet recordChecker = null;
boolean updateMonthly = false;

Connection connection = (new Database()).getConnection();
if (connection == null) {
throw new Exception("Unable to get connection to database!");
}
else {
//System.out.println("database connection open");
}

try {
s = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);

String recordQuery = "SELECT TR_ID FROM TRANSACTIONS WHERE TR_ID='" + TRANS_ID + "';";
recordChecker = s.executeQuery( recordQuery );
if ( !recordChecker.next() ) {
try {
String insertData = "INSERT INTO TRANSACTIONS VALUES ( '" + IMSI + "','" + TS + "','" + UT + "','" + TRANS_ID +"','" + ( double ) cost + "' );";
s.executeUpdate( insertData );
updateMonthly = true;
//System.out.println( insertData );
} catch ( Exception ee ) {
System.err.println( "Cannot connect to table TRANSACTIONS, either table does not exist or SQL statement is invalid." );
}
}
else {
System.out.println("Transaction: " + transactions[ctr] + " already exist!");
}

String lookForAccNum = "SELECT SI_ACC_NUM FROM SUBSCRIBER_INFO WHERE SI_IMSI='" + IMSI +"';";
recordChecker = s.executeQuery( lookForAccNum );
while ( recordChecker != null && recordChecker.next() ) {
ACC_NUM = recordChecker.getString("SI_ACC_NUM");
//System.out.println( ACC_NUM );
}

if ( updateMonthly ) {
try {
recordQuery = "SELECT MU_TRANS_NUM, MU_COST FROM MONTHLY_USAGES WHERE MU_ACC_NUM='" + ACC_NUM + "' AND MU_TRANS_DATE='" + MO_DATE + "';";
recordChecker = s.executeQuery( recordQuery );
if ( !recordChecker.next() ) {
String insertData = "INSERT INTO MONTHLY_USAGES VALUES ('" + ACC_NUM + "','" + MO_DATE + "','" + 1 +"','" + ( double ) cost + "');";
s.executeUpdate( insertData );
//System.out.println( insertData );
}
else {
double oldTransNum = recordChecker.getDouble( "MU_TRANS_NUM" );
double oldCost = recordChecker.getDouble( "MU_COST" );
String updateData = "UPDATE MONTHLY_USAGES SET MU_TRANS_NUM='" + ( oldTransNum + 1 ) +"', MU_COST='" + ( ( ( double ) cost ) + oldCost ) + "' WHERE MU_ACC_NUM ='" + ACC_NUM + "' AND MU_TRANS_DATE = '" + MO_DATE + "';";
s.executeUpdate( updateData );
//System.out.println( updateData );
//System.out.println( "mu_trans_num = " + ( oldTransNum + 1 ) + " mu_cost = " + ( ( ( double ) cost ) + oldCost ) );
}
updateMonthly = false;
} catch ( Exception ee ) {
System.err.println( "Cannot connect to table MONTHLY_USAGES, either table does not exist or SQL statement is invalid." );
}
}

} catch (SQLException sql_exp) {
sql_exp.printStackTrace();
throw new Exception("Error in creating sql statement!");
} finally {
if ( s!= null )
s.close();
if ( !connection.isClosed() )
connection.close();
//System.out.println("database connection closed!");
}
}
}

// cost generating class
private double computeCost ( String ut ) throws Exception {
double cost = 0.75;
String tc = ut.substring( 1 , 3 ) , sd = ut.substring( 3 , 5 );
int intTC = 0 , intSD = 0;

try {
intTC = Integer.parseInt( tc );
intSD = Integer.parseInt( sd );
} catch ( NumberFormatException nfe ) {
System.err.println( "Unable to parse: " + nfe );
} catch ( Exception e ) {
System.err.println( e );
}

if ( intTC == 20 && intSD == 30 ) {
cost = 2.50;
}
else if ( intTC < 20 && intSD == 67 ) {
cost = 1.50;
}
else if ( intTC > 20 && intSD == 52 ) {
cost = 6.50;
}
return cost;
}

// checks the directory of the input files, this also
// checks all the files (if they are valid).
// This terminates the program if no valid files
// are in the directory or if the directory does not exists.
// Names of valid files will be sent back to the method caller in a String array .
// Mainly used by the Billing constructor method.
private String[] checkDir ( String dir ) throws Exception {
File dirToCheck = new File( dir );
String files[] = dirToCheck.list();
String tempFiles[] = new String[100];
String validFiles[];
int validFileCtr = 0;
boolean emptyDir = true;

if ( !dirToCheck.exists() ) {
System.err.println( dir + " ... does not exist.\n" );
System.exit( 0 );
}
if ( files.length > 0 ) {
for ( int ctr = 0; ctr < files.length; ctr++ ) {
if ( checkFileName( files[ctr] ) ) {
tempFiles[validFileCtr++] = files[ctr];
emptyDir = false;
}
}
}
if ( emptyDir ) {
System.err.println( dir + " ... is empty.\n" );
System.exit( 0 );
}

validFiles = new String[validFileCtr];
for ( int ctr = 0; ctr < tempFiles.length; ctr++ ) { // transfer file names to a new array
if ( tempFiles[ctr] != null ) { // to avoid passing sparse array
validFiles[ctr] = tempFiles[ctr];
}
}

return validFiles;
}

// check if file name is valid, returns true if valid.
// Mainly used by checkDir method.
private boolean checkFileName ( String fileName ) throws Exception {
boolean correctFormat = true;
int year = 0, month = 0, day = 0, nnnn = 0;

try {
if ( !( fileName.substring( 0 , 4 ).equals( "MED_" ) ) ) {
throw new Exception();
}
nnnn = Integer.parseInt( fileName.substring( 4 , 8 ) );
if ( !( fileName.substring( 8 , 9 ).equals( "_" ) ) ) {
throw new Exception();
}
year = Integer.parseInt( fileName.substring( 9 , 13 ) );
month = Integer.parseInt( fileName.substring( 13 , 15 ) );
if ( month < 1 || month > 12 ) {
throw new Exception();
}
day = Integer.parseInt( fileName.substring( 15 , 17 ) );
if ( day < 1 || day > 31 ) {
throw new Exception();
}
if ( !fileName.endsWith( ".DAT" ) ) {
throw new Exception();
}
} catch (Exception e) {
correctFormat = false;
}

return correctFormat;
}

public static void main(String[] args) throws Exception{

new Billing ( args[0] );

System.exit( 0 );
}
}



//MED
import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Med extends Remote {
public double calculatePayment(double principal, double annualRate, int terms) throws RemoteException;
}





//meditation.java
import java.io.*;

/**
* Created by: jaguilar
* Date Created: Aug. 15, 2007
* Description: A mediation system that would read
* input files of a transaction and write it in a text file.
*/

public class Mediation {

public static void main(String args[]) {
File dir = new File(args[0]);
String[] files = dir.list();
if(files.length==0){
System.err.println("The directory is empty!");
System.exit(0);
}

else{

if(checkInputFile(args[1])){

try {
doParse(args[0],args[1]);
} catch (Exception e) {
e.printStackTrace();
}
}
else{
System.err.println("Incorrect file format!");
System.exit(0);
}

}

}

public static boolean checkInputFile(String file){
if(((file.substring(0,4)).equals("CDR_"))&&
(isDate(file.substring(4,12)))&&
(file.substring(12,13).equals("_"))&&
(isNumber(file.substring(13,17)))&&
(file.substring(17,21).equals(".DAT"))){
return true;
}
else{
return false;
}

}

public static boolean isDate(String date){
boolean returnValue=true;
if(date.length()==8){
returnValue=true;
}

returnValue=isNumber(date);
return returnValue;
}

public static boolean isNumber(String number){
boolean returnValue=true;
for(int i=0; i char c=number.charAt(i);
if(c=='1' || c=='2'|| c=='3'||c=='4'|| c=='5'||
c=='6'||c=='7' || c=='8'|| c=='9'|| c=='0'){
continue;
}
else{
returnValue=false;
break;
}
}
return returnValue;
}


/**Generates an output format based on the input filename**/
public static String generateOutputFile(String f){
String nnnn=f.substring(13,17);
String date =f.substring(4,12);

return "MED_"+ nnnn+ "_"+date+".DAT";
}

/**Parses the record of the CDR file and writes parsed record to MED file**/
public static void doParse(String directory, String file) throws Exception{
try{

String buf;
String filePath=directory+"\\"+ file;
String destDirectory=directory+"\\OUTPUT\\";
String outputFile="";
new File(destDirectory).mkdir();
FileReader fr = new FileReader (filePath);
BufferedReader br = new BufferedReader(fr);

while ((buf = br.readLine()) != null) {
if(buf.length()>60){
throw new Exception();
}
else{
String RN=buf.substring(0,6);
String IMSI=buf.substring(22,42);
String TC=buf.substring(42,44);
String SD=buf.substring(44,46);
String TS=buf.substring(46,60);
String UT="G"+TC+SD;
String TRANS_ID="NS-"+RN+" ";
String parsedFile=IMSI+TS+UT+TRANS_ID;
outputFile+=parsedFile+"\n";

}

}

FileWriter fw = new FileWriter(destDirectory+generateOutputFile(file));
BufferedWriter bw = new BufferedWriter(fw);
bw.write(outputFile);
bw.close();

br.close();
new File(filePath).delete();

}catch(FileNotFoundException fileNotFoundException){
System.err.println("File not found!");
}
catch(StringIndexOutOfBoundsException indexOutOfBoundsException){
System.err.println("File has incorrect format and cant be processed!");
}
catch(Exception e){
System.err.println("File has incorrect format and cant be processed!");
}

}

}




















§





§








Brief History of Pizza Hut



         
Pizza Hut was founded as a pizzeria in 1958 by the Carney brothers - Dan and Frank. Borrowing $600 from their mother, the University of Wichita college students took a family pizza recipe and opened the first restaurant at a busy intersection in Wichita, Kansas. Additional restaurants were opened, with the first franchise unit opening in 1959 in Topeka, Kansas.

         
By 1964 a unique standardized building appearance and layout was established for franchised and company-owned stores, in order to have a universal and familiar look for customers to recognize. By 1970, with 310 stores nationwide, Pizza Hut went public on the New York Stock Exchange under the stock ticker symbol PIZ.

         
In 1977, Pizza Hut was acquired by Pepsico, along with KFC and Taco Bell, and in 1997, the three restaurant chains were spun off and joined with Long John Silver's and A&W Restaurants to become YUM! Brands.











§

Page Authors

§












PIZZA HUT ORDER PAGE

























Value Meals















ItemQuantity
Value Meal 1 - P150

(Ham and Cheese Thin Crust, Large drinks)
Value Meal 2 - P200

(Personal Pan Pizza, Large drinks)
Value Meal 3 - P300

(Supreme Pizza, Large drinks)


Additionals






















ItemQuantity
Burger - P30

(Ham and Cheese Thin Crust, Large drinks)
Fries - P25

(Personal Pan Pizza, Large drinks)
Desserts - P30

(Supreme Pizza, Large drinks)
Rice - P10

(Supreme Pizza, Large drinks)









Amount Paid   



Change    











§

Page Authors

§










PIZZA HUT HOMEPAGE

















§ Page Authors §




Oscar Garcia Jr.


Bryan Gabriel


Joseph Eugene Palma


Sarah Jane Sonza




BSCS 4 - 4
















§

Back to HOMEPAGE

§









Format:
body
{background-color: maroon
}

p
{
color: white;
font-family: arial
}

.link
{color: #FFFACD;
text-align: "center";
font-family: arial
}

.title
{color: yellow;
text-align: "center"
}

b.linkPage
{color: #FFFACD;
font-family:arial;
font-size: 30
}

td.pageLinks
{width: "100";
font-family: arial;
text-align: "center"
}

td.menu
{width: "450";
font-family: arial;
text-align: "center"
}

td.ingredient
{width: "250"
}

td
{color: white
}

img.frontPic
{height:"300";
width:"300"
}

img.slide
{height:"100";
width:"100"
}


div
{
height: 300px;
width: 480px;
overflow: auto;
background-color: #FF4500;
border: 1px solid #555555
}



//meditation 2
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.io.*;

public class Mediation2 implements Med {

/**
* RMI Mediation2: creates a new data file from a given input record file
* after creation of the mediated file, input file is deleted.
* All outputs ( med and rej files ) goes to OUTPUT subdirectory.
* Implements RMI.
* Input format: Directory
* or in the format: Directory file1 file2 file3 ...
* jvargas
*/

static StringBuffer log = new StringBuffer();
static int input = 0 , filtered = 0 , rejected = 0 , processed = 0;

public double calculatePayment(double principal, double annRate, int years) throws RemoteException {
return 1;
}

Mediation2() { }

Mediation2 ( String dir ) throws RemoteException {
if ( !( dir.endsWith("\\") ) ) {
dir += "\\";
}
String filesToProcess[] = checkDirFiles( dir );
for ( int ctr = 0; ctr < filesToProcess.length; ctr++ ) {
new Mediation2 ( dir , filesToProcess[ctr] );
}
}

Mediation2 ( String srcDir , String fileName ) throws RemoteException {
BufferedReader br = null;
BufferedWriter bwM = null , bwR = null;
String inLine = "";
StringBuffer medWrite = new StringBuffer();
StringBuffer rejWrite = new StringBuffer();
if ( !( srcDir.endsWith("\\") ) ) {
srcDir += "\\";
}
String destDir = srcDir + "OUTPUT\\" , rejDir = srcDir + "REJECT\\";
String medFileName = "" , rejFileName = "";
boolean deleteFile = false;
String RN = "" , RT = "" , MSISDN = "" , IMSI = "" , TC = "" , SD = "" , TS = "" , UT = "" , TRANS_ID = "";
int intTC = 0 , intSD = 0;

try {
checkDir( srcDir ); // check if source directory exists, terminates program if no such directory exists
if ( !checkFileName( fileName ) ) { // skip this file if the filename is invalid
log.append( fileName + " ... is not a valid filename.\n" );
return;
}
if ( !( new File( destDir ).exists() ) ) { // if no OUTPUT subdirectory exist, create one
new File( destDir ).mkdir();
}
if ( !( new File( rejDir ).exists() ) ) { // if no REJECT subdirectory exist, create one
new File( rejDir ).mkdir();
}
medFileName = makeMedFileName( fileName );
rejFileName = makeRejFileName( fileName );
br = new BufferedReader( new FileReader( srcDir + fileName ) );

while ( ( inLine = br.readLine() ) != null ) { // check all lines in file and create corresponding data to write
if ( inLine.length() != 60 ) {
throw new StringIndexOutOfBoundsException();
}
RN = inLine.substring( 0 , 6 );
RT = inLine.substring( 6 , 7 );
MSISDN = inLine.substring( 7 , 22 );
IMSI = inLine.substring( 22 , 42 );
TC = inLine.substring( 42 , 44 );
SD = inLine.substring( 44 , 46 );
TS = inLine.substring( 46 , 60 );
UT = "G" +TC + SD;
TRANS_ID = "NS-" + RN + " ";
intTC = Integer.parseInt( TC );
intSD = Integer.parseInt( SD );
input++;
if ( intTC == 2 && intSD == 20 ) {
filtered++;
}
else if ( intTC >= 50 ) {
rejWrite.append( IMSI + TS + UT + TRANS_ID + "\n" );
rejected++;
}
else {
medWrite.append( IMSI + TS + UT + TRANS_ID + "\n" );
processed++;
}
}

bwM = new BufferedWriter( new FileWriter( destDir + medFileName ) );
bwM.write( medWrite.toString() ); // write med data to the output med file
if ( rejected > 0 ) {
bwR = new BufferedWriter( new FileWriter( rejDir + rejFileName ) );
bwR.write( rejWrite.toString() ); // write rej data to the output rej file
}
log.append( "File: " + fileName + " ... processed.\n");

deleteFile = true;

} catch ( FileNotFoundException fnfe ) {
log.append( srcDir + fileName + " ... not found.\n" );
return;
} catch ( StringIndexOutOfBoundsException outOfBounds ) {
log.append( srcDir + fileName + " ... data format incorrect.\nFile " + fileName + " will not be processed.\n" );
} catch ( Exception e ) {

} finally { // close BufferedReader and BufferedWriter and delete the input file
try {
br.close();
bwM.close();
if ( rejected > 0 ) {
bwR.close();
}
if ( deleteFile ) {
new File( srcDir + fileName ).delete();
}
} catch (Exception e) {

}
}
}

// returns a corresponding MED name for the input file
private String makeMedFileName ( String oldName ) {
return "MED_" + oldName.substring( 13 , 17 ) + "_" + oldName.substring( 4 , 12 ) + ".DAT";
}

// returns a corresponding REJ name for the input file
private String makeRejFileName ( String oldName ) {
return "REJ_" + oldName.substring( 13 , 17 ) + "_" + oldName.substring( 4 , 12 ) + ".DAT";
}

// checks the directory of the input files, this also
// checks all the files (if they are valid).
// Terminates the program if conditions are not met
private void checkDir ( String dir ) throws Exception {
File dirToCheck = new File( dir );
String files[] = dirToCheck.list();
int ctr = 0;

if ( !dirToCheck.exists() ) {
System.err.println( dir + " ... does not exist.\n" );
System.exit( 0 );
}
if ( files.length == 0 ) {
System.err.println( dir + " ... is empty.\n" );
System.exit( 0 );
}
}

// checks the directory of the input files, this also
// checks all the files (if they are valid).
// This terminates the program if no valid files
// are in the directory or if the directory does not exists.
// Names of valid files will be sent back to the method caller in a String array .
// Mainly used by the Mediation2 constructor method.
private String[] checkDirFiles ( String dir ) throws RemoteException {
File dirToCheck = new File( dir );
String files[] = dirToCheck.list();
String tempFiles[] = new String[100];
String validFiles[];
int validFileCtr = 0;
boolean emptyDir = true;

if ( !dirToCheck.exists() ) {
System.err.println( dir + " ... does not exist.\n" );
System.exit( 0 );
}
if ( files.length > 0 ) {
for ( int ctr = 0; ctr < files.length; ctr++ ) {
if ( checkFileName( files[ctr] ) ) {
tempFiles[validFileCtr++] = files[ctr];
emptyDir = false;
}
}
}
if ( emptyDir ) {
System.err.println( dir + " ... is empty.\n" );
System.exit( 0 );
}

validFiles = new String[validFileCtr];
for ( int ctr = 0; ctr < tempFiles.length; ctr++ ) { // transfer file names to a new array
if ( tempFiles[ctr] != null ) { // to avoid passing sparse array
validFiles[ctr] = tempFiles[ctr];
}
}

return validFiles;
}

// check if file name is valid, returns true if valid
private boolean checkFileName( String fileName ) throws RemoteException {
boolean correctFormat = true;
String part1 = "" , part2a = "" , part2b = "" , part2c = "" , part3 = "";
int year = 0, month = 0, day = 0, nnnn = 0;

try {
part1 = fileName.substring( 0 , 4 );
part2a = fileName.substring( 4 , 8 );
part2b = fileName.substring( 8 , 10 );
part2c = fileName.substring( 10 , 12 );
part3 = fileName.substring( 13 , 17 );
if ( !part1.equals( "CDR_" ) ) {
throw new Exception();
}
year = Integer.parseInt( part2a );
month = Integer.parseInt( part2b );
if ( month < 1 || month > 12 ) {
throw new Exception();
}
day = Integer.parseInt( part2c );
if ( day < 1 || day > 31 ) {
throw new Exception();
}
if ( !( ( fileName.substring( 12 , 13 ) ).equals( "_" ) ) ) {
throw new Exception();
}
nnnn = Integer.parseInt( part3 );
if ( !fileName.endsWith( ".DAT" ) ) {
throw new Exception();
}
} catch (Exception e) {
correctFormat = false;
}

return correctFormat;
}
// Pass a report in String
public String printMe () {
return "Num of input files: " + input + "\nNum of filtered files: " + filtered + "\nNum of rejected files: " + rejected + "\nNum of processed files: " + processed + "\n";
}
}





//RMI client
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class RMIClient {
private static Med stub = null;
private RMIClient() {}

public static void main( String[] args ) throws Exception {

try {
Registry reg = LocateRegistry.getRegistry( "localhost" );
stub = ( Med ) reg.lookup( "Mediation" );

} catch (Exception e) {
System.err.println("Client exception thrown: " + e.toString());
e.printStackTrace();
}

if ( args.length > 1 ) {
for ( int ctr = 1; ctr < args.length; ctr++ ) {
Mediation2 m = new Mediation2 ( args[0], args[ctr] );
System.out.println( m.printMe() );
}
}
else {
Mediation2 m = new Mediation2 ( args[0] );
System.out.println( m.printMe() );
}

System.exit( 0 );
}
}






//Server
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class Server {

public Server() {}

public static void main(String args[]) {

try {
Mediation2 robj = new Mediation2();
Med stub = ( Med ) UnicastRemoteObject.exportObject( robj , 0 );

Registry registry = LocateRegistry.getRegistry();
registry.bind( "Mediation" , stub );
System.out.println( "Mediation Server is ready to listen..." );

} catch (Exception e) {
System.err.println( "Server exception thrown: " + e.toString() );
e.printStackTrace();
}
}
}








//Subscriber user manager
package managers;

import dataObjects.SubscriberUsage;

import java.util.Vector;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;

import connections.Database;

/**
* Contains Subscriber usage data extraction procedures
* User: agbillones
* Corporate Support Systems
* Smart Communications, Inc.
* Date: May 27, 2005 - 6:17:20 PM
*/
public class SubscriberUsageManager {

public Vector getSubscriberUsage(String imsi) throws Exception {
Vector subscriberUsages = new Vector();
SubscriberUsage subscriberUsage = null;

if (imsi==null) {
throw new Exception("Invalid input parameter!");
}


Connection connection = (new Database()).getConnection();
String sql = "SELECT TR_IMSI, TR_TRANS_DATE, TR_USAGE_TYPE, TR_ID, TR_COST FROM TRANSACTIONS WHERE TR_IMSI = '" + imsi + "'";

if (connection == null) {
throw new Exception("Unable to get connection to database!");
} else {
System.out.println("database connection open");
}

Statement s = null;
ResultSet rs = null;
boolean isEmpty = true;
try {
s = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
rs = s.executeQuery(sql);

while (rs!=null && rs.next()) {
isEmpty = false;
subscriberUsage = new SubscriberUsage();
subscriberUsage.setImsi(rs.getString("TR_IMSI"));
subscriberUsage.setTs(rs.getString("TR_TRANS_DATE"));
subscriberUsage.setUt(rs.getString("TR_USAGE_TYPE"));
subscriberUsage.setTrans_id(rs.getString("TR_ID"));
subscriberUsage.setCost(Float.parseFloat(rs.getString("TR_COST")));
subscriberUsages.add(subscriberUsage);
}

if (isEmpty) {
System.out.println("No data returned!");
throw new Exception("No data returned!");
}

} catch (SQLException sql_exp) {
sql_exp.printStackTrace();
throw new Exception("Error in creating sql statement!");
} finally {
if (rs!=null)
rs.close();
if (s!=null)
s.close();
if (!connection.isClosed())
connection.close();

System.out.println("database connection closed!");
}
System.out.println("subscriber usage/s:\n"+subscriberUsages.toString());

return subscriberUsages;
}

public Vector getSubscriberUsagePerMonth(String account_number) throws Exception {
Vector subscriberUsages = new Vector();
SubscriberUsage subscriberUsage = null;

if (account_number==null) {
throw new Exception("Invalid input parameter!");
}


Connection connection = (new Database()).getConnection();
String sql = "SELECT MU_ACC_NUM, MU_TRANS_DATE, MU_TRANS_NUM, MU_COST FROM MONTHLY_USAGES WHERE MU_ACC_NUM = '" + account_number + "'";

if (connection == null) {
throw new Exception("Unable to get connection to database!");
} else {
System.out.println("database connection open");
}

Statement s = null;
ResultSet rs = null;
boolean isEmpty = true;
try {
s = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
rs = s.executeQuery(sql);

while (rs!=null && rs.next()) {
isEmpty = false;
subscriberUsage = new SubscriberUsage();
subscriberUsage.setAcc_num(rs.getString("MU_ACC_NUM"));
subscriberUsage.setTs(rs.getString("MU_TRANS_DATE"));
subscriberUsage.setTrans_num(Integer.parseInt(rs.getString("MU_TRANS_NUM")));
subscriberUsage.setCost(Float.parseFloat(rs.getString("MU_COST")));
subscriberUsages.add(subscriberUsage);
}

if (isEmpty) {
System.out.println("No data returned!");
throw new Exception("No data returned!");
}

} catch (SQLException sql_exp) {
sql_exp.printStackTrace();
throw new Exception("Error in creating sql statement!");
} finally {
if (rs!=null)
rs.close();
if (s!=null)
s.close();
if (!connection.isClosed())
connection.close();

System.out.println("database connection closed!");
}
System.out.println("subscriber monthly usage/s:\n"+subscriberUsages.toString());

return subscriberUsages;
}
}






















No comments: