Advertisement
alishaik786

SelectDataFromTable

Oct 6th, 2011
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. public class SelectDataFromTable
  2. {
  3. public static Vector tableVector,selectedRowVector;
  4. public static SelectDataFromTable staticTablaDataObject,selectedRowData;
  5. SelectDataFromTable tableRowObj;
  6.  
  7. String Name,DateofBirth,address,description;
  8.  
  9. // This is for Query: Select * from Table;
  10. public boolean TableSelection(String statement)
  11. {
  12. tableVector=new Vector();
  13. try
  14. {
  15. LoadingScreen.uri=URI.create(LoadingScreen.dbLocation+"ManualRecords.db");
  16. LoadingScreen.database=DatabaseFactory.openOrCreate(LoadingScreen.uri, new DatabaseSecurityOptions(false));
  17. LoadingScreen.database.beginTransaction();
  18. Statement st=LoadingScreen.database.createStatement(statement);
  19. st.prepare();
  20. Cursor c = st.getCursor();
  21.  
  22. Row r;
  23. int i = 0;
  24. while(c.next())
  25. {
  26. tableRowObj=new SelectDataFromTable();
  27. r = c.getRow();
  28. i++;
  29. tableRowObj.setName(r.getString(0));
  30. tableRowObj.setDateofBirth(r.getString(1));
  31. tableRowObj.setAddress(r.getString(2));
  32. tableRowObj.setDescription(r.getString(3));
  33. tableVector.addElement(tableRowObj);
  34. }
  35. st.execute();
  36. st.close();
  37. LoadingScreen.database.commitTransaction();
  38. LoadingScreen.database.close();
  39. if (i==0)
  40. {
  41. return false;
  42. }
  43. System.out.println("============================Got Table Data Successfully");
  44. }
  45. catch(Exception e)
  46. {
  47. try
  48. {
  49. LoadingScreen.database.commitTransaction();
  50. LoadingScreen.database.close();
  51. }
  52. catch(Exception exp)
  53. {
  54. exp.printStackTrace();
  55. System.out.println("Exception:==========================="+exp.getMessage()+"\n");
  56. }
  57. e.printStackTrace();
  58. System.out.println("Exception:============================="+e.getMessage()+"\n");
  59. }
  60. return true;
  61. }
  62.  
  63. // selected Perticular Row from the Table; Query: Select * from Employee where name='abc';
  64. public boolean selectedRow(String statement)
  65. {
  66. selectedRowVector=new Vector();
  67. try
  68. {
  69. LoadingScreen.uri=URI.create(LoadingScreen.dbLocation+"ManualRecords.db");
  70. LoadingScreen.database=DatabaseFactory.openOrCreate(LoadingScreen.uri, new DatabaseSecurityOptions(false));
  71. LoadingScreen.database.beginTransaction();
  72. Statement st=LoadingScreen.database.createStatement(statement);
  73. st.prepare();
  74.  
  75. Cursor c = st.getCursor();
  76. Row r;
  77. int i = 0;
  78. while(c.next())
  79. {
  80. selectedRowData=new SelectDataFromTable();
  81. r = c.getRow();
  82. i++;
  83. selectedRowData.setName(r.getString(0));
  84. selectedRowData.setDateofBirth(r.getString(1));
  85. selectedRowData.setAddress(r.getString(2));
  86. selectedRowData.setDescription(r.getString(3));
  87. selectedRowVector.addElement(selectedRowData);
  88. }
  89. st.execute();
  90. st.close();
  91. LoadingScreen.database.commitTransaction();
  92. LoadingScreen.database.close();
  93. if (i==0)
  94. {
  95. return false;
  96. }
  97. System.out.println("============================Selected Perticular Data is Done Successfully");
  98. }
  99. catch(Exception e)
  100. {
  101. try
  102. {
  103. LoadingScreen.database.commitTransaction();
  104. LoadingScreen.database.close();
  105. }
  106. catch(Exception exp)
  107. {
  108. exp.printStackTrace();
  109. System.out.println("Exception:======"+exp.getMessage()+"\n");
  110. }
  111. e.printStackTrace();
  112. System.out.println("Exception:======"+e.getMessage()+"\n");
  113. }
  114. return true;
  115. }
  116.  
  117.  
  118. // Setter and getter Methods;
  119.  
  120. public void setName(String Name)
  121. {
  122. this.Name=Name;
  123. }
  124. public String getName()
  125. {
  126. return Name;
  127. }
  128. //
  129. public void setDateofBirth(String date)
  130. {
  131. DateofBirth=date;
  132. }
  133. public String getDateofBirth()
  134. {
  135. return DateofBirth;
  136. }
  137. //
  138. public void setAddress(String Address)
  139. {
  140. address=Address;
  141. }
  142. public String getAddress()
  143. {
  144. return address;
  145. }
  146. //
  147. public void setDescription(String description)
  148. {
  149. this.description=description;
  150. }
  151. public String getDescription()
  152. {
  153. return description;
  154. }
  155. }
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement