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
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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
i
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.
Contents
iii
CONTENTS
CHAPTER Page No. Synopsis………………….………………………………………………..…………….. .(i) List of Figures.………….………………………………………………...…………….. .(ii) List of Tables.…………………………………………………………………………….(iii) 1. INTRODUCTION.……...…………………………………………………………... .1
1.1. Problem Definition 1
1.2. Objective of the Project 1
1.3. Significance of the Project 1
1.4. Outline of the Project 1
2. SYSTEM STUDY..…….……………………..……………………………………...3 2.1. Proposed System 3
3. SYSTEM ANALYSIS..…….……………………..………………………………….4 3.1 Requirement Analysis 4 3.2 Feasibility Study 4
4. SYSTEM DESIGN…...…….……………………..………………………………….6 4.1 Use case Diagram 6
4.2 Class Diagram 7
4.3 Sequence Diagram 7
4.4 Collaboration Diagram 8
4.5 Activity Diagram 8
4.6 Table Design 9
5. SYSTEM IMPLEMENTATION.………………..…………………………………...10 5.1 Server Module 10
5.2 Mobile Client Module 11
6. TESTING……………………….………………..……………………………………12 6.1 Unit Testing 12
public class Start { public static void main(String[] aa) { new Server(); } } //////////// import java.io.*; import java.net.*; public class Server implements SharedInterface
Appendix
21
{ 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+"'");
Appendix
22
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)+"\nVendorAddr:"+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.getString(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(); }
Appendix
23
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;
Appendix
24
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); }
* @author SuperStar */ public class VisualMIDlet extends MIDlet implements 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 ">//GEN-BEGIN:|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 ">//GEN-BEGIN:|methods|0| /** * Switches a display to previous displayable of the current displayable.
Appendix
26
* 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 ">//GEN-BEGIN:|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 ">//GEN-BEGIN:|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 /**
Appendix
27
* 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:|5-switchDisplayable|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 ">//GEN-BEGIN:|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 ">//GEN-BEGIN:|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);//GEN-LINE:|27-getter|1|27-postInit
Appendix
28
// 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 ">//GEN-BEGIN:|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|[email protected] image1 = Image.createImage("/PSG (Custom).JPG"); } catch (java.io.IOException e) {//GEN-END:|28-getter|1|[email protected] 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) {//GEN-END:|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|33-preAction // write pre-action user code here switchDisplayable(null, getForm1());//GEN-LINE:|7-commandAction|4|33-postAction // 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|40-postAction // write post-action user code here
Appendix
29
} else if (command == okCommand1) {//GEN-LINE:|7-commandAction|7|38-preAction // write pre-action user code here IP=textField.getString(); switchDisplayable(null, getForm2());//GEN-LINE:|7-commandAction|8|38-postAction // 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|53-preAction // write pre-action user code here switchDisplayable(null, getForm());//GEN-LINE:|7-commandAction|10|53-postAction // write post-action user code here } else if (command == okCommand5) {//GEN-LINE:|7-commandAction|11|90-preAction // 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|90-postAction // 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|63-postAction // write post-action user code here } else if (command == okCommand3) {//GEN-LINE:|7-commandAction|15|66-preAction // 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, getForm4());//GEN-LINE:|7-commandAction|16|66-postAction
Appendix
30
// 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|72-preAction // write pre-action user code here switchDisplayable(null, getForm2());//GEN-LINE:|7-commandAction|18|72-postAction // write post-action user code here } else if (command == exitCommand1) {//GEN-LINE:|7-commandAction|19|74-preAction // 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|93-preAction // 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:|29-getter|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 ">//GEN-BEGIN:|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:|32-getter|1|32-postInit // write post-init user code here
Appendix
31
}//GEN-BEGIN:|32-getter|2| return okCommand; } //</editor-fold>//GEN-END:|32-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form1 ">//GEN-BEGIN:|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:|34-getter|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 ">//GEN-BEGIN:|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:|37-getter|1|37-postInit // write post-init user code here }//GEN-BEGIN:|37-getter|2|
Appendix
32
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);//GEN-LINE:|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 ">//GEN-BEGIN:|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() });//GEN-BEGIN:|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 ">//GEN-BEGIN:|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:|44-getter|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);
Appendix
33
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);//GEN-LINE:|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 ">//GEN-BEGIN:|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() });//GEN-BEGIN:|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 ">//GEN-BEGIN:|61-getter|0|61-preInit /**
Appendix
34
* 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:|61-getter|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 ">//GEN-BEGIN:|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:|67-getter|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:|62-getter|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: okCommand3 ">//GEN-BEGIN:|65-getter|0|65-preInit /** * Returns an initiliazed instance of okCommand3 component.
Appendix
35
* @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, 0);//GEN-LINE:|65-getter|1|65-postInit // write post-init user code here }//GEN-BEGIN:|65-getter|2| return okCommand3; } //</editor-fold>//GEN-END:|65-getter|2| //<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:|71-getter|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:|73-getter|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 ">//GEN-BEGIN:|77-getter|0|77-preInit /** * Returns an initiliazed instance of stringItem component. * @return the initialized component instance */
Appendix
36
public StringItem getStringItem() { if (stringItem == null) {//GEN-END:|77-getter|0|77-preInit // write pre-init user code here stringItem = new StringItem("Developed By", "G.BAKTAVATCHALAM (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| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem1 ">//GEN-BEGIN:|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");//GEN-LINE:|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:|89-getter|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: okCommand2 ">//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
Appendix
37
okCommand2 = new Command("View Results", Command.OK, 0);//GEN-LINE:|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 ">//GEN-BEGIN:|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 (); }
Appendix
38
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