AN APPROACH TO ACCESS THE REMOTE DATABASE FROM MOBILE CLIENTS

BAKTAVATCHALAM.G (08MW03)

MASTER OF ENGINEERING Branch: SOFTWARE ENGINEERING
of Anna University

November 2008

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
PSG COLLEGE OF TECHNOLOGY
(Autonomous Institution)

COIMBATORE – 641 004

Faculty Signature

Acknowledgement

ACKNOWLEDGEMENT
We wish to express our sincere gratitude to our respected Principal Dr. R. Rudramoorthy for having given us the opportunity to undertake our project.

We also wish to express our sincere thanks to Dr. S. N. Sivanandam, Professor and Head of the Department of Computer Science and Engineering, for his encouragement and support that he extends towards our project work. We extend our sincere thanks to our internal guide, Mrs. R. Bhavani, Lecturer, Department of Computer Science and Engineering, for his guidance and help rendered for the successful completion of our project.

i

Contents

CONTENTS

CHAPTER

Page No.

Synopsis………………….………………………………………………..…………….. .(i) List of Figures.………….………………………………………………...…………….. .(ii) List of Tables.…………………………………………………………………………….(iii) 1. INTRODUCTION.……...…………………………………………………………... .1 1.1. 1.2. 1.3. 1.4. 2. 3. 2.1. 3.1 3.2 4. 4.1 4.2 4.3 4.4 4.5 4.6 5. 5.1 5.2 6. 6.1 6.2 6.3 7. 7.1 Problem Definition Objective of the Project Significance of the Project Outline of the Project Proposed System Requirement Analysis Feasibility Study Use case Diagram Class Diagram Sequence Diagram Collaboration Diagram Activity Diagram Table Design Server Module Mobile Client Module Unit Testing Integration Testing Sample Test Cases Server 1 1 1 1 3 4 4 6 7 7 8 8 9 10 11 12 14 15 16

SYSTEM STUDY..…….……………………..……………………………………...3 SYSTEM ANALYSIS..…….……………………..………………………………….4

SYSTEM DESIGN…...…….……………………..………………………………….6

SYSTEM IMPLEMENTATION.………………..…………………………………...10

TESTING……………………….………………..……………………………………12

SNAPSHOT.…..……………….………………..…………………………………. 16

iii

Contents

7.2

Mobile Client

16

CONCLUSIONS………………..………………………………………….……….……..17 FUTURE ENHANCEMENTS..…………………………………………………….……. .18 BIBLIOGRAPHY...…………………………………………………………….………….19 APPENDIX…….....…………………………………………………………….………….20

iv

Synopsis

SYNOPSIS
In this project, we view the Database remotely from Mobile Terminal considered as Clients. The Mobile Client sends request to server to view the Database. Then the Server gets the request and finding out the corresponding Database request (Query) and processes it. After retrieving results from Database server optimize the results for Mobile compatibility and then it will send the result to Mobile Terminal using GPRS. After mobile got the result it will be displayed to User. This project is very helpful when anyone need to access some important information when they out of server site. So the mobile is good device for this type information access. Also here Server address is specified each and every time for load balancing. If one server address may fails then user enter another server address for Database access. The default Server address always displayed to avoid specifying manually.

i

List of Figures

LIST OF FIGURES

FIGURE NO Fig: 2.1

LIST OF FIGURES System Architecture

PAGE NO. 3

ii

List of Tables

LIST OF TABLES
TABLE NO Table 4.1 NAME Use case Diagram Elements PAGE NO. 6

Table 6.1

Sample Test Cases

15

iii

Introduction

Chapter 1

CHAPTER 1
INTRODUCTION
This chapter provides a brief overview of the problem definition, objectives and significance of the project and an outline of the report.

1.1 PROBLEM DEFINITION
Accessing the remote database using Mobile Client, the database is accessed through the Server. The Server handles multiple clients by getting the request from the clients and process it and reply’s back with the result of the query.

1.2 OBJECTIVE OF THE PROJECT
Most of the users are interested in viewing the contents of database using Mobile Clients. Also users want the information that should be optimized. So this project gives a solution for user that user can view the required info from anywhere using his Mobile Terminal.

1.3 SIGNIFICANCE OF THE PROJECT
With the enormous growth in information on the database, there is a corresponding need for tools that enable fast and efficient view of user data.

1.4 OUTLINE OF THE PROJECT
The rest of the report is structures as follows. Chapter 2 provides a detailed study of the existing system and the basic ideas of the proposed system. Chapter 3 discusses the requirements for the development of the system and an analysis on the feasibility of

1

Introduction

Chapter 1

the system. Chapter 4 presents the overall design of the system. Chapter 5 discusses the implementation details. Chapter 6 explains various testing procedures conducted on the system. Chapter 7 contains the snapshot of various forms in our system. The last section summarizes the project.

2

System Study

Chapter 2

CHAPTER 2
SYSTEM STUDY
This chapter elucidates the existing system and a brief description of the proposed system.

2.1 PROPOSED SYSTEM
In our project, we view the Database remotely from Mobile Terminal considered as Clients. The Mobile Client sends request to server to view the Database. Then the Server gets the request and finds out the corresponding Database request (Query). After retrieving results from Database server optimize the results for Mobile compatible then it will send the result to Mobile Terminal using GPRS. After mobile got the result it will be displayed to User. This project is very helpful when anyone need to access some important information when they are out of server site. So the mobile is good device for this type information access. Also here Server address is specified each and every time for load balancing. If one server address may fails then user enter another server address for Database access. The default Server address always displayed to avoid specifying manually.

Figure 2.1 Client - 1 Database Server Client - 2 Display Optimized Output

Client - n

3

System Analysis

Chapter 3

CHAPTER 3
SYSTEM ANALYSIS
This section describes the hardware and software specifications for the development of the system and an analysis on the feasibility of the system.

3.1 REQUIREMENT ANALYSIS 3.1.1 Software Requirements
After experimenting with various commercial software available and analyzing the Pros and Cons of the software, the following are chosen.
• • •

Operating System – Platform Independent Programming Languages – Java 1.6+ Front End – J2ME

3.1.2 Hardware Requirements
The Hardware requirements of the proposed system are as follows:
• • •

Pentium-III machine & above RAM-256 MB Hard Disk with a Capacity of 10 GB

3.2 FEASIBILITY ANALYSIS
Feasibility deals with step-by-step analysis of the system. Analysis showed that this project was feasible in all respects. Three kinds of feasibility factors are considered:
• • •

Economic Feasibility Technical Feasibility Operational Feasibility

4

System Analysis

Chapter 3

3.2.1 Economic Feasibility
The system is developed only using those softwares that are very well used in the market, so there is no need for installation of new softwares. Hence, the cost incurred towards this project is negligible

3.2.2 Technical Feasibility 3.2.2.1 Searching
The main aim of our project is to search a specific set of keywords in a specific set of websites only.

3.2.2.2 Distributed Searching
Next important thing that must be done in our project is to process the searching in distributed manner. So the searching is run concurrently in all client systems and server combine this result and produce final result.

3.2.3 Operational Feasibility
The functions needed to be performed by the system are all valid and without any conflicts. All functions and constraints specified in the requirements are completely operational. The requirements stated are realistically testable. The requirements are adaptable to changes with out any large-scale effects on other system requirements. The system is capable of accommodating future requirements if they arise.

5

System Design

Chapter 4

CHAPTER 4
SYSTEM DESIGN
This chapter describes the functional decomposition of the system and illustrates the movement of data between external entities, the processes and the data stores within the system, with the help of data flow diagrams.

4.1 USE CASE DIAGRAM

Actors Usecases

DB,Mobile Client, Server Required Info,Res Info,Quering, Query Results

Required Information Mobile Client Server Querying

Info

Results

DB

6

System Design

Chapter 4

4.2 CLASS DIAGRAM
MClient
IP : String ServerAddr : String reqInfo : String makeConn(seraddr : String) sendReq(req : String) getResults() : String disp()

Server_
port : int max_con : int getReq(req : String) sendQry(q : String) sendRes(res : String) getRes()

DB_
getQry(q : String) sendRes(res : String)

4.3 SEQUENCE DIAGRAM
Mclient Server DB

1: Req Info 2: Find Query

3: ReqQuery 4: Process

5: Query Result 6: Format 7: Send Info 8: Display

7

System Design

Chapter 4

4.4 COLLABORATION DIAGRAM
8: Display 2: Find Query 6: Format 4: Process

1: Req Info Mclient 7: Send Info Server

3: ReqQuery DB 5: Query Result

4.5 STATE CHART / ACTIVITY DIAGRAM
MClient Serv er DB

send Req

Process Req & get corresponding Query

Send Query

Process Query & Send Results

Result Refining

Get Info & Display

Formatted Info

8

System Design

Chapter 4

4.6 TABLE DESIGN
E-R Diagram:

PID
CID
CNAME CADDR

PNAME

UCOST

PRODUCT CUSTOMER

INVENTORY

VID SUPPLIES ORDER

VADDR

OID

ODATE

QTY

VENDOR

PID

VID

VNAME

TABLES:
Customer Product Vendor Order PID VID OID CID CID CNAME PNAME UCOST VNAME ODATE CADDR INVENTORY VADDR PID VID PID QTY

9

Implementation

Chapter 5

CHAPTER 5
IMPLEMENTATION
This phase is broken up into two phases: Development and Implementation. The individual system components are built during the development period. Programs are written and tried by users. During Implementation, the components built during development are put into operational use. In the development phase of our system, the following system components were built.
• •

Server module Mobile Client module

The Server & Client module is developed using Java & Java Swings.

5.1 Server Module
This module contains following sub-modules, • • • Client Listening Module DB Connectivity Module Result Formatter Module

5.1.1 Client Listening Module In this module we create separate threads for each clients and the corresponding client will communicate only through that Thread. 5.1.2 DB Connectivity Module In this module we make/select appropriate DB Query according to the Mobile Client Request and make DB connection and run the Query then retrieve the Query Results. 5.1.3 Result Formatter Module In this module we display format the result into mobile client acceptable format.

10

Implementation

Chapter 5

5.2 Mobile Client Module
This module contains following sub-modules, • • • Load Module Connection Management Module Display Module

5.2.1 Load Module In this module we get the appropriate request option from the user. 5.2.1 Connection Management Module Whenever user request for info we make socket connections to the server. Also this do the sending/receiving data to/from server. 5.2.1 Display Module After info is gathered from server it is then displayed to the user.

11

Testing

Chapter 6

CHAPTER 6
TESTING
This chapter explains the various testing procedures conducted on the system. Testing is a process of executing a program with the intent of finding an error. A successful test is one that uncovers an as yet undiscovered error. A testing process cannot show the absence of defects but can only show that software errors are present. It ensures that defined input will produce actual results that agree with the required results. A good testing methodology should include
• • • • • • • • •

Clearly define testing roles, responsibilities and procedures Establish consistent testing process Streamline testing requirements Overcome “requirements slow me down” mentality Common sense process approach Use some elements of existing Process Not an attempt to replace, rewrite or redefine Process To find defects early and to give good time to developers for bug fixes Independent perspective in testing

Some of the testing principles used in this project are:
• •

Unit Testing Integration Testing

6.1 UNIT TESTING
Unit testing is a strategy by which individual components, which make up the system, are tested first to ensure that system works up to the desired extent. It focuses on the verification effort on the smallest unit of the software design i.e. module. Various modules of the system are tested to see whether they perform their intended functions. Using procedural design description, important control paths are tested to uncover the

12

Testing

Chapter 6

errors with in the boundary of the module. While accepting a connection using specified functions we go for unit testing in their respective modules. The unit test is normally a white box test (a testing method in which the control structure of the procedural design is used to derive test cases).

6.1.1 Process Objectives
To test every unit of the software in isolation before integrating it with other units.

6.1.2 Definition of Unit
A unit is a module as identified during size estimation process with a size estimate that does not exceed 1000LOC. For GUI applications each screen will be a unit. If the size estimate for a unit exceeds 1000 LOC and it is not feasible to break it into smaller logically independent units that can be tested in isolation, the project lead in concurrence with the SQA can decide to define this as a unit.

6.1.3 Entry Criteria
The entry criteria for this process are the following:
• •

Unit completed Unit peer reviewed

6.1.4 Exit Criteria
The exit criteria for this process are the following:
• •

Unit test cases executed Any defects that are identified during unit testing and that are not fixed before the unit enters component testing is listed in the test report and verified 100% statement coverage If unit will be tested before code review of unit, this must be identified in the

project plan. In these projects the developer will self-review (desk check) the code before unit testing. In cases of exception handling of error conditions that are difficult to generate, thereby making it impossible to achieve 100% statement coverage, the code should be formally reviewed with this additional criteria

13

Testing

Chapter 6

6.2 INTEGRATION TESTING
The integration testing is a systematic technique for constructing the program structure while conducting tests to uncover errors associated with interfacing. It is a type of testing by which the individual modules of the system are combined and tested whether they work properly as a whole. The objective is to take unit test modules and build a program that has been dictated by the design. Integration testing can be either ‘Incremental’ or ‘Non-Incremental’. The objective of the integration testing is to help engineers plan and execute the component and Integration testing for their respective projects. Integration testing should include the following objectives:
• •

Performed by the product group/Dev test team after feature complete Determines that all product components on a list of specific platforms function successfully together (The List specified in Master test plan) Performed in a basic product / platform environment (Basic environment specified in Master test plan) Tests the product functionality against the specification Tests functionality of fake languages with sample single and double byte languages Tests scaling to an acceptable minimum level as called out in the master test plan Tests performance, reliability to an acceptable level as called out in the master test plan Final integration tests done after all components are integrated, with the build in production format The tasks of the project have been integrated and the functioning of the entire

• •

system has been found to be satisfactory. The functionality of the entire system has been subjected to a series of tests and all the modules have been found to interoperate properly. Finally the integration testing was performed on the integrated system and found to work properly.

14

Testing

Chapter 6

6.3 SAMPLE TEST CASES
The following are the some of the sample test cases employed along with the test results have been described in the table below. Table 6.1 Sample Test Cases Test Description Is Server stable for running more than one clients? Is Clients are return the results properly? Is Client using the Internet Optimally? Is Server DB Connectivity is Optimal? Is Client takes Lower Resources? Result OK OK OK OK OK

15

Snapshot

Chapter 7

CHAPTER 7
SNAPSHOT
This chapter contains the snapshot of various forms in our system.

7.1 Server

16

Snapshot

Chapter 7

7.2 Client (When Searching Process)

17

Conclusion

CONCLUSION
Thus the analysis, design and implementation of mobile database views are done successfully. So that the users can able to view the database as they wants and also the server give better results when number of mobile client requests are increased.

17

Future Enhancements

FUTURE ENHANCEMENTS
Currently we need GPRS for Mobile clients, Due to Hardware Limitations currently we can only view Database Contents, and results from Server are limited. In future improvements are the communication between Mobile Terminal and Server extended with other Network Technologies like Bluetooth, Infrared…Abilities for modifying the database, and retrieves more results from Server.

18

Bibliography

BIBLIOGRAPHY
• • • J2ME Complete Reference Java Network Programming, O'Reilly & Associates, Inc.,, Second Edition Herbert Schildt ., and Patrick Naughton , 2001,“Java2: The Complete Reference “, Fourth Edition , Tata McGraw-Hill Publishing Company Limited .

Websites
http://ibm.com/developerWorks

19

Appendix

APPENDIX
SOURCE CODE LISTINGS
This chapter provides source code listings.

OUTPUT (In Server)
Socket[addr=/127.0.0.1,port=1046,localport=6776] Connected. ID:1 Data Sent:[[B@6ca1c] Connection Closed. Socket[addr=/127.0.0.1,port=1047,localport=6776] Connected. ID:1 Data: VendorID:1 VendorName:v1 VendorAddr:va1 ProductID:1 Data Sent:[[B@5740bb] Connection Closed.

SERVER
public class Start { public static void main(String[] aa) { new Server(); } } //////////// import java.io.*; import java.net.*; public class Server implements SharedInterface

20

Appendix
{ public Server() { new ServerListener(this); } public void newClient(Socket s) { infoMsg(s.toString()+" Connected."); new ClientThread(this,s); } public void errorMsg(String msg) { System.out.println(msg); } public void infoMsg(String msg) { System.out.println(msg); } } ////////////// import java.net.*; import java.io.*; import java.sql.*; public class ClientThread extends Thread { Socket S=null; SharedInterface SI=null; public InputStream in=null; public OutputStream out=null; public ClientThread(SharedInterface si,Socket s) { SI=si; S=s; start(); } public String getDBData(int opt,String dt,int id) { String sss=""; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:gmb"); Statement st=con.createStatement(); ResultSet rs=null; switch(opt) { case 1: rs=st.executeQuery("select * from OrderForm where odate='"+dt+"'");

21

Appendix
while (rs.next()) { sss+="OrderID:"+rs.getInt(1)+"\nCustID:"+rs.getInt(2)+"\nDate:"+rs.getString(3)+" \nProductID:"+rs.getInt(4)+"\nQty:"+rs.getInt(5)+"\nTotalCost:"+rs.getInt(6); } break; case 2: rs=st.executeQuery("select * from OrderForm where cid="+id); while (rs.next()) { sss+="\nOrderID:"+rs.getInt(1)+"\nCustID:"+rs.getInt(2)+"\nDate:"+rs.getString(3) +"\nProductID:"+rs.getInt(4)+"\nQty:"+rs.getInt(5)+"\nTotalCost:"+rs.getInt(6); } break; case 3: rs=st.executeQuery("select * from Vendor where vid="+id); while (rs.next()) { sss+="\nVendorID:"+rs.getInt(1)+"\nVendorName:"+rs.getString(2)+"\nVendorAd dr:"+rs.getString(3)+"\nProductID:"+rs.getInt(4); } break; case 4: rs=st.executeQuery("select * from Customer where cid="+id); while (rs.next()) { sss+="\nCustID:"+rs.getInt(1)+"\nCustName:"+rs.getString(2)+"\nCustAddr:"+rs.g etString(3); } break; case 5: rs=st.executeQuery("select * from Product where pid="+id); while (rs.next()) { sss+="\nProductID:"+rs.getInt(1)+"\nProductName:"+rs.getString(2)+"\nUnitCost: "+rs.getInt(3)+"\nInventory:"+rs.getInt(4)+"\nVendorID:"+rs.getInt(5); } break; } rs.close(); st.close(); con.close(); } catch(Exception e1) { sss="SQL Error:"+e1.getMessage(); }

22

Appendix
return sss; } public void run() { try { in=S.getInputStream(); BufferedReader in1=new BufferedReader(new InputStreamReader(in)); out=S.getOutputStream(); PrintStream out1=new PrintStream(out); DataOutputStream out2=new DataOutputStream(out); String rs=""; int cond=0; String dt=""; int tmP=0; int id=0; int opt=in.read(); if(opt==1) { dt=in1.readLine(); SI.infoMsg(dt); rs=getDBData(opt,dt,id); SI.infoMsg(rs); out1.write(rs.getBytes()); } else { id=in.read(); SI.infoMsg("ID:"+id); rs=getDBData(opt,dt,id); SI.infoMsg("Data:\n"+rs); out1.write(rs.getBytes()); } in.close(); out.close(); out1.close(); SI.infoMsg("Data Sent:["+rs.getBytes()+"]\n Connection Closed."); } catch(Exception e2) { SI.errorMsg("Client Data Write Error:"+e2.getMessage()); } } } /////////// import java.net.*; import java.io.*; public class ServerListener extends Thread { SharedInterface SI=null; ServerSocket SS=null; int port=0;

23

Appendix
boolean tF=false; public ServerListener(SharedInterface si) { SI=si; port=SI.PORT; tF=false; start(); } public void terminate() { tF=true; } public void run() { try { SS=new ServerSocket(port); while(tF==false) { SI.newClient(SS.accept()); } } catch(Exception e1) { SI.errorMsg("Server Listener Error:"+e1.getMessage()); } } } //////////////// import java.net.*; public interface SharedInterface { public final int PORT=6776; public void newClient(Socket s); public void errorMsg(String msg); public void infoMsg(String msg); }

MOBILE CLIENT
import java.io.DataInputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import javax.microedition.io.Connector; import javax.microedition.io.SocketConnection; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /**

24

Appendix
* @author SuperStar */ public class VisualMIDlet extends DBI,CommandListener,ItemCommandListener { private boolean midletPaused = false; // String IP="127.0.0.1"; private int opt=0; private String rs="",lbl=""; private String dt=""; private int id=0; // //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GENBEGIN:|fields|0| private java.util.Hashtable __previousDisplayables = new java.util.Hashtable(); private Form form; private ImageItem imageItem; private StringItem stringItem; private StringItem stringItem1; private Form form1; private TextField textField; private Form form2; private ChoiceGroup choiceGroup; private Form form3; private TextField textField1; private Form form4; private StringItem stringItem2; private Command exitCommand; private Command okCommand; private Command cancelCommand; private Command okCommand1; private Command cancelCommand1; private Command backCommand; private Command backCommand1; private Command okCommand3; private Command exitCommand1; private Command okCommand5; private Command okCommand2; private Image image1; //</editor-fold>//GEN-END:|fields|0| /** * The VisualMIDlet constructor. */ public VisualMIDlet() { } //<editor-fold defaultstate="collapsed" desc=" Generated Methods BEGIN:|methods|0| /** * Switches a display to previous displayable of the current displayable. ">//GEN-

MIDlet

implements

25

Appendix
* The <code>display</code> instance is obtain from the <code>getDisplay</code> method. */ private void switchToPreviousDisplayable() { Displayable __currentDisplayable = getDisplay().getCurrent(); if (__currentDisplayable != null) { Displayable __nextDisplayable = (Displayable) __previousDisplayables.get(__currentDisplayable); if (__nextDisplayable != null) { switchDisplayable(null, __nextDisplayable); } } } //</editor-fold>//GEN-END:|methods|0| //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GENBEGIN:|0-initialize|0|0-preInitialize /** * Initilizes the application. * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method. */ private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize // write pre-initialize user code here //GEN-LINE:|0-initialize|1|0-postInitialize // write post-initialize user code here }//GEN-BEGIN:|0-initialize|2| //</editor-fold>//GEN-END:|0-initialize|2| //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GENBEGIN:|3-startMIDlet|0|3-preAction /** * Performs an action assigned to the Mobile Device - MIDlet Started point. */ public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction // write pre-action user code here switchDisplayable(null, getForm());//GEN-LINE:|3-startMIDlet|1|3-postAction // write post-action user code here }//GEN-BEGIN:|3-startMIDlet|2| //</editor-fold>//GEN-END:|3-startMIDlet|2| //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction /** * Performs an action assigned to the Mobile Device - MIDlet Resumed point. */ public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction // write pre-action user code here //GEN-LINE:|4-resumeMIDlet|1|4-postAction // write post-action user code here }//GEN-BEGIN:|4-resumeMIDlet|2| //</editor-fold>//GEN-END:|4-resumeMIDlet|2| //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch /**

26

Appendix
* Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable. * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately * @param nextDisplayable the Displayable to be set */ public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5switchDisplayable|0|5-preSwitch // write pre-switch user code here Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch Displayable __currentDisplayable = display.getCurrent(); if (__currentDisplayable != null && nextDisplayable != null) { __previousDisplayables.put(nextDisplayable, __currentDisplayable); } if (alert == null) { display.setCurrent(nextDisplayable); } else { display.setCurrent(alert, nextDisplayable); }//GEN-END:|5-switchDisplayable|1|5-postSwitch // write post-switch user code here }//GEN-BEGIN:|5-switchDisplayable|2| //</editor-fold>//GEN-END:|5-switchDisplayable|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form ">//GENBEGIN:|23-getter|0|23-preInit /** * Returns an initiliazed instance of form component. * @return the initialized component instance */ public Form getForm() { if (form == null) {//GEN-END:|23-getter|0|23-preInit // write pre-init user code here form = new Form("SuperStar DB", new Item[] { getStringItem1(), getImageItem(), getStringItem() });//GEN-BEGIN:|23-getter|1|23-postInit form.addCommand(getExitCommand()); form.addCommand(getOkCommand()); form.setCommandListener(this);//GEN-END:|23-getter|1|23-postInit // write post-init user code here }//GEN-BEGIN:|23-getter|2| return form; } //</editor-fold>//GEN-END:|23-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: imageItem ">//GENBEGIN:|27-getter|0|27-preInit /** * Returns an initiliazed instance of imageItem component. * @return the initialized component instance */ public ImageItem getImageItem() { if (imageItem == null) {//GEN-END:|27-getter|0|27-preInit // write pre-init user code here imageItem = new ImageItem("Welcome To PSG College of Technology", getImage1(), ImageItem.LAYOUT_DEFAULT, "<Missing Image>", Item.PLAIN);//GENLINE:|27-getter|1|27-postInit

27

Appendix
// write post-init user code here }//GEN-BEGIN:|27-getter|2| return imageItem; } //</editor-fold>//GEN-END:|27-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image1 ">//GENBEGIN:|28-getter|0|28-preInit /** * Returns an initiliazed instance of image1 component. * @return the initialized component instance */ public Image getImage1() { if (image1 == null) {//GEN-END:|28-getter|0|28-preInit // write pre-init user code here try {//GEN-BEGIN:|28-getter|1|28-@java.io.IOException image1 = Image.createImage("/PSG (Custom).JPG"); } catch (java.io.IOException e) {//GEN-END:|28-getter|1|28-@java.io.IOException e.printStackTrace(); }//GEN-LINE:|28-getter|2|28-postInit // write post-init user code here }//GEN-BEGIN:|28-getter|3| return image1; } //</editor-fold>//GEN-END:|28-getter|3| //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction /** * Called by a system to indicated that a command has been invoked on a particular displayable. * @param command the Command that was invoked * @param displayable the Displayable where the command was invoked */ public void commandAction(Command command, Displayable displayable) {//GENEND:|7-commandAction|0|7-preCommandAction // write pre-action user code here if (displayable == form) {//GEN-BEGIN:|7-commandAction|1|30-preAction if (command == exitCommand) {//GEN-END:|7-commandAction|1|30-preAction // write pre-action user code here exitMIDlet();//GEN-LINE:|7-commandAction|2|30-postAction // write post-action user code here } else if (command == okCommand) {//GEN-LINE:|7-commandAction|3|33preAction // write pre-action user code here switchDisplayable(null, getForm1());//GEN-LINE:|7-commandAction|4|33postAction // write post-action user code here }//GEN-BEGIN:|7-commandAction|5|40-preAction } else if (displayable == form1) { if (command == cancelCommand) {//GEN-END:|7-commandAction|5|40-preAction // write pre-action user code here switchDisplayable(null, getForm());//GEN-LINE:|7-commandAction|6|40postAction // write post-action user code here

28

Appendix
} else if (command == okCommand1) {//GEN-LINE:|7-commandAction|7|38preAction // write pre-action user code here IP=textField.getString(); switchDisplayable(null, getForm2());//GEN-LINE:|7-commandAction|8|38postAction // write post-action user code here }//GEN-BEGIN:|7-commandAction|9|53-preAction } else if (displayable == form2) { if (command == cancelCommand1) {//GEN-END:|7-commandAction|9|53preAction // write pre-action user code here switchDisplayable(null, getForm());//GEN-LINE:|7-commandAction|10|53postAction // write post-action user code here } else if (command == okCommand5) {//GEN-LINE:|7-commandAction|11|90preAction // write pre-action user code here if (choiceGroup.getSelectedIndex()==-1) opt=2; else opt=choiceGroup.getSelectedIndex()+1; if(opt==1) lbl=("Enter Date [DD-MM-YYYY]:"); else if(opt==2) lbl=("Enter Order ID:"); else if(opt==3) lbl=("Enter Vendor ID:"); else if(opt==4) lbl=("Enter Customer ID:"); else lbl=("Enter Product ID:"); switchDisplayable(null, getForm3());//GEN-LINE:|7-commandAction|12|90postAction // write post-action user code here textField1.setLabel(lbl); }//GEN-BEGIN:|7-commandAction|13|63-preAction } else if (displayable == form3) { if (command == backCommand) {//GEN-END:|7-commandAction|13|63-preAction // write pre-action user code here switchToPreviousDisplayable();//GEN-LINE:|7-commandAction|14|63postAction // write post-action user code here } else if (command == okCommand3) {//GEN-LINE:|7-commandAction|15|66preAction // write pre-action user code here id=1; dt="10-10-00"; if(opt==1) dt=textField1.getString(); else id=Integer.parseInt(textField1.getString()); switchDisplayable(null, postAction getForm4());//GEN-LINE:|7-commandAction|16|66-

29

Appendix
// write post-action user code here DB db=new DB(IP, opt, dt, id,this); }//GEN-BEGIN:|7-commandAction|17|72-preAction } else if (displayable == form4) { if (command == backCommand1) {//GEN-END:|7-commandAction|17|72preAction // write pre-action user code here switchDisplayable(null, getForm2());//GEN-LINE:|7-commandAction|18|72postAction // write post-action user code here } else if (command == exitCommand1) {//GEN-LINE:|7-commandAction|19|74preAction // write pre-action user code here exitMIDlet();//GEN-LINE:|7-commandAction|20|74-postAction // write post-action user code here } else if (command == okCommand2) {//GEN-LINE:|7-commandAction|21|93preAction // write pre-action user code here //GEN-LINE:|7-commandAction|22|93-postAction // write post-action user code here stringItem2.setText(rs); }//GEN-BEGIN:|7-commandAction|23|7-postCommandAction }//GEN-END:|7-commandAction|23|7-postCommandAction // write post-action user code here }//GEN-BEGIN:|7-commandAction|24| //</editor-fold>//GEN-END:|7-commandAction|24| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|29-getter|0|29-preInit /** * Returns an initiliazed instance of exitCommand component. * @return the initialized component instance */ public Command getExitCommand() { if (exitCommand == null) {//GEN-END:|29-getter|0|29-preInit // write pre-init user code here exitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|29getter|1|29-postInit // write post-init user code here }//GEN-BEGIN:|29-getter|2| return exitCommand; } //</editor-fold>//GEN-END:|29-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand ">//GENBEGIN:|32-getter|0|32-preInit /** * Returns an initiliazed instance of okCommand component. * @return the initialized component instance */ public Command getOkCommand() { if (okCommand == null) {//GEN-END:|32-getter|0|32-preInit // write pre-init user code here okCommand = new Command("Ok", Command.OK, 0);//GEN-LINE:|32getter|1|32-postInit // write post-init user code here

30

Appendix
}//GEN-BEGIN:|32-getter|2| return okCommand; } //</editor-fold>//GEN-END:|32-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form1 ">//GENBEGIN:|34-getter|0|34-preInit /** * Returns an initiliazed instance of form1 component. * @return the initialized component instance */ public Form getForm1() { if (form1 == null) {//GEN-END:|34-getter|0|34-preInit // write pre-init user code here form1 = new Form("Student DB", new Item[] { getTextField() });//GEN-BEGIN:|34getter|1|34-postInit form1.addCommand(getOkCommand1()); form1.addCommand(getCancelCommand()); form1.setCommandListener(this);//GEN-END:|34-getter|1|34-postInit // write post-init user code here }//GEN-BEGIN:|34-getter|2| return form1; } //</editor-fold>//GEN-END:|34-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: textField ">//GENBEGIN:|36-getter|0|36-preInit /** * Returns an initiliazed instance of textField component. * @return the initialized component instance */ public TextField getTextField() { if (textField == null) {//GEN-END:|36-getter|0|36-preInit // write pre-init user code here textField = new TextField("Enter Server IP:", "127.0.0.1", 32, TextField.ANY);//GEN-LINE:|36-getter|1|36-postInit // write post-init user code here }//GEN-BEGIN:|36-getter|2| return textField; } //</editor-fold>//GEN-END:|36-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand1 ">//GEN-BEGIN:|37-getter|0|37-preInit /** * Returns an initiliazed instance of okCommand1 component. * @return the initialized component instance */ public Command getOkCommand1() { if (okCommand1 == null) {//GEN-END:|37-getter|0|37-preInit // write pre-init user code here okCommand1 = new Command("Ok", Command.OK, 0);//GEN-LINE:|37getter|1|37-postInit // write post-init user code here }//GEN-BEGIN:|37-getter|2|

31

Appendix
return okCommand1; } //</editor-fold>//GEN-END:|37-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: cancelCommand ">//GEN-BEGIN:|39-getter|0|39-preInit /** * Returns an initiliazed instance of cancelCommand component. * @return the initialized component instance */ public Command getCancelCommand() { if (cancelCommand == null) {//GEN-END:|39-getter|0|39-preInit // write pre-init user code here cancelCommand = new Command("Cancel", Command.CANCEL, 0);//GENLINE:|39-getter|1|39-postInit // write post-init user code here }//GEN-BEGIN:|39-getter|2| return cancelCommand; } //</editor-fold>//GEN-END:|39-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form2 ">//GENBEGIN:|42-getter|0|42-preInit /** * Returns an initiliazed instance of form2 component. * @return the initialized component instance */ public Form getForm2() { if (form2 == null) {//GEN-END:|42-getter|0|42-preInit // write pre-init user code here form2 = new Form("Select Option", new Item[] { getChoiceGroup() });//GENBEGIN:|42-getter|1|42-postInit form2.addCommand(getCancelCommand1()); form2.addCommand(getOkCommand5()); form2.setCommandListener(this);//GEN-END:|42-getter|1|42-postInit // write post-init user code here }//GEN-BEGIN:|42-getter|2| return form2; } //</editor-fold>//GEN-END:|42-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: choiceGroup ">//GENBEGIN:|44-getter|0|44-preInit /** * Returns an initiliazed instance of choiceGroup component. * @return the initialized component instance */ public ChoiceGroup getChoiceGroup() { if (choiceGroup == null) {//GEN-END:|44-getter|0|44-preInit // write pre-init user code here choiceGroup = new ChoiceGroup("Query", Choice.POPUP);//GEN-BEGIN:|44getter|1|44-postInit choiceGroup.append("View Product Sales For a Day", null); choiceGroup.append("View Orders For a Single Customer", null); choiceGroup.append("View Vendor Details", null); choiceGroup.append("View Customer Details", null);

32

Appendix
choiceGroup.append("View Product Details", null); choiceGroup.setItemCommandListener(this); choiceGroup.setSelectedFlags(new boolean[] { true, false, false, false, false }); choiceGroup.setFont(0, null); choiceGroup.setFont(1, null); choiceGroup.setFont(2, null); choiceGroup.setFont(3, null); choiceGroup.setFont(4, null);//GEN-END:|44-getter|1|44-postInit // write post-init user code here }//GEN-BEGIN:|44-getter|2| return choiceGroup; } //</editor-fold>//GEN-END:|44-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: cancelCommand1 ">//GEN-BEGIN:|52-getter|0|52-preInit /** * Returns an initiliazed instance of cancelCommand1 component. * @return the initialized component instance */ public Command getCancelCommand1() { if (cancelCommand1 == null) {//GEN-END:|52-getter|0|52-preInit // write pre-init user code here cancelCommand1 = new Command("Cancel", Command.CANCEL, 0);//GENLINE:|52-getter|1|52-postInit // write post-init user code here }//GEN-BEGIN:|52-getter|2| return cancelCommand1; } //</editor-fold>//GEN-END:|52-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form3 ">//GENBEGIN:|57-getter|0|57-preInit /** * Returns an initiliazed instance of form3 component. * @return the initialized component instance */ public Form getForm3() { if (form3 == null) {//GEN-END:|57-getter|0|57-preInit // write pre-init user code here form3 = new Form("Enter Details:", new Item[] { getTextField1() });//GENBEGIN:|57-getter|1|57-postInit form3.addCommand(getBackCommand()); form3.addCommand(getOkCommand3()); form3.setCommandListener(this);//GEN-END:|57-getter|1|57-postInit // write post-init user code here }//GEN-BEGIN:|57-getter|2| return form3; } //</editor-fold>//GEN-END:|57-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: textField1 ">//GENBEGIN:|61-getter|0|61-preInit /**

33

Appendix
* Returns an initiliazed instance of textField1 component. * @return the initialized component instance */ public TextField getTextField1() { if (textField1 == null) {//GEN-END:|61-getter|0|61-preInit // write pre-init user code here textField1 = new TextField("Value:", "0", 32, TextField.ANY);//GEN-LINE:|61getter|1|61-postInit // write post-init user code here }//GEN-BEGIN:|61-getter|2| return textField1; } //</editor-fold>//GEN-END:|61-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form4 ">//GENBEGIN:|67-getter|0|67-preInit /** * Returns an initiliazed instance of form4 component. * @return the initialized component instance */ public Form getForm4() { if (form4 == null) {//GEN-END:|67-getter|0|67-preInit // write pre-init user code here form4 = new Form("Output", new Item[] { getStringItem2() });//GEN-BEGIN:|67getter|1|67-postInit form4.addCommand(getBackCommand1()); form4.addCommand(getExitCommand1()); form4.addCommand(getOkCommand2()); form4.setCommandListener(this);//GEN-END:|67-getter|1|67-postInit // write post-init user code here }//GEN-BEGIN:|67-getter|2| return form4; } //</editor-fold>//GEN-END:|67-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand ">//GEN-BEGIN:|62-getter|0|62-preInit /** * Returns an initiliazed instance of backCommand component. * @return the initialized component instance */ public Command getBackCommand() { if (backCommand == null) {//GEN-END:|62-getter|0|62-preInit // write pre-init user code here backCommand = new Command("Back", Command.BACK, 0);//GEN-LINE:|62getter|1|62-postInit // write post-init user code here }//GEN-BEGIN:|62-getter|2| return backCommand; } //</editor-fold>//GEN-END:|62-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: ">//GEN-BEGIN:|65-getter|0|65-preInit /** * Returns an initiliazed instance of okCommand3 component. okCommand3

34

Appendix
* @return the initialized component instance */ public Command getOkCommand3() { if (okCommand3 == null) {//GEN-END:|65-getter|0|65-preInit // write pre-init user code here okCommand3 = new Command("Ok", Command.OK, getter|1|65-postInit // write post-init user code here }//GEN-BEGIN:|65-getter|2| return okCommand3; } //</editor-fold>//GEN-END:|65-getter|2|

0);//GEN-LINE:|65-

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand1 ">//GEN-BEGIN:|71-getter|0|71-preInit /** * Returns an initiliazed instance of backCommand1 component. * @return the initialized component instance */ public Command getBackCommand1() { if (backCommand1 == null) {//GEN-END:|71-getter|0|71-preInit // write pre-init user code here backCommand1 = new Command("Back", Command.BACK, 0);//GEN-LINE:|71getter|1|71-postInit // write post-init user code here }//GEN-BEGIN:|71-getter|2| return backCommand1; } //</editor-fold>//GEN-END:|71-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand1 ">//GEN-BEGIN:|73-getter|0|73-preInit /** * Returns an initiliazed instance of exitCommand1 component. * @return the initialized component instance */ public Command getExitCommand1() { if (exitCommand1 == null) {//GEN-END:|73-getter|0|73-preInit // write pre-init user code here exitCommand1 = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|73getter|1|73-postInit // write post-init user code here }//GEN-BEGIN:|73-getter|2| return exitCommand1; } //</editor-fold>//GEN-END:|73-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem ">//GENBEGIN:|77-getter|0|77-preInit /** * Returns an initiliazed instance of stringItem component. * @return the initialized component instance */

35

Appendix
public StringItem getStringItem() { if (stringItem == null) {//GEN-END:|77-getter|0|77-preInit // write pre-init user code here stringItem = new StringItem("Developed By", (08MW03)");//GEN-LINE:|77-getter|1|77-postInit // write post-init user code here }//GEN-BEGIN:|77-getter|2| return stringItem; } //</editor-fold>//GEN-END:|77-getter|2|

"G.BAKTAVATCHALAM

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem1 ">//GENBEGIN:|78-getter|0|78-preInit /** * Returns an initiliazed instance of stringItem1 component. * @return the initialized component instance */ public StringItem getStringItem1() { if (stringItem1 == null) {//GEN-END:|78-getter|0|78-preInit // write pre-init user code here stringItem1 = new StringItem("DBMS For", "Product Sales Management");//GENLINE:|78-getter|1|78-postInit // write post-init user code here }//GEN-BEGIN:|78-getter|2| return stringItem1; } //</editor-fold>//GEN-END:|78-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand5 ">//GEN-BEGIN:|89-getter|0|89-preInit /** * Returns an initiliazed instance of okCommand5 component. * @return the initialized component instance */ public Command getOkCommand5() { if (okCommand5 == null) {//GEN-END:|89-getter|0|89-preInit // write pre-init user code here okCommand5 = new Command("Ok", "OK", Command.OK, 0);//GEN-LINE:|89getter|1|89-postInit // write post-init user code here }//GEN-BEGIN:|89-getter|2| return okCommand5; } //</editor-fold>//GEN-END:|89-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: ">//GEN-BEGIN:|92-getter|0|92-preInit /** * Returns an initiliazed instance of okCommand2 component. * @return the initialized component instance */ public Command getOkCommand2() { if (okCommand2 == null) {//GEN-END:|92-getter|0|92-preInit // write pre-init user code here okCommand2

36

Appendix
okCommand2 = new Command("View Results", Command.OK, 0);//GENLINE:|92-getter|1|92-postInit // write post-init user code here }//GEN-BEGIN:|92-getter|2| return okCommand2; } //</editor-fold>//GEN-END:|92-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem2 ">//GENBEGIN:|94-getter|0|94-preInit /** * Returns an initiliazed instance of stringItem2 component. * @return the initialized component instance */ public StringItem getStringItem2() { if (stringItem2 == null) {//GEN-END:|94-getter|0|94-preInit // write pre-init user code here stringItem2 = new StringItem("Results", "0");//GEN-LINE:|94-getter|1|94-postInit // write post-init user code here }//GEN-BEGIN:|94-getter|2| return stringItem2; } //</editor-fold>//GEN-END:|94-getter|2| public void commandAction(Command c, Item item) { } /** * Returns a display instance. * @return the display instance. */ public Display getDisplay () { return Display.getDisplay(this); } /** * Exits MIDlet. */ public void exitMIDlet() { switchDisplayable (null, null); destroyApp(true); notifyDestroyed(); } /** * Called when MIDlet is started. * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet. */ public void startApp() { if (midletPaused) { resumeMIDlet (); } else { initialize (); startMIDlet (); }

37

Appendix
midletPaused = false; } /** * Called when MIDlet is paused. */ public void pauseApp() { midletPaused = true; } /** * Called to signal the MIDlet to terminate. * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released. */ public void destroyApp(boolean unconditional) { } public void getRs(String ss) { rs=ss; stringItem2.setText(rs); } } class DB extends Thread { String IP; int opt; String dt; int id; String rs=""; DBI dbi=null; public DB(String IP1,int opt1,String dt1,int id1,DBI dd) { IP=IP1; opt=opt1; dt=dt1; id=id1; dbi=dd; start(); } public void run() { try { //IP=textBox2.getString(); SocketConnection sc (SocketConnection)Connector.open("socket://"+IP+":6776"); sc.setSocketOption(SocketConnection.LINGER, 5); InputStream is = sc.openInputStream(); OutputStream os = sc.openOutputStream(); DataInputStream in1=(new DataInputStream(is)); PrintStream out1=new PrintStream(os); os.write(opt); if(opt==0) out1.println(dt); else

=

38

Appendix
os.write(id); byte[] b=new byte[1]; while(in1.read(b)!=-1) rs+=(new String(b)); is.close(); os.close(); sc.close(); } catch(Exception e1) { rs="Error:"+e1.toString(); } dbi.getRs(rs); } } interface DBI { public void getRs(String ss); }

39

Sign up to vote on this title
UsefulNot useful