Advertisement
alishaik786

QueryExecution

Oct 6th, 2011
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. public class QueryExecution
  2. {
  3. public static QueryExecution queryObj;
  4. int flag=0;
  5. public QueryExecution()
  6. {
  7.  
  8. }
  9.  
  10. // This Method works for Table creation, Data Insertion, Updating Data, Data Deletion;
  11. public void excuteQuery(String statement,int flag)
  12. {
  13. this.flag=flag;
  14. try
  15. {
  16. LoadingScreen.uri=URI.create(LoadingScreen.dbLocation+"ManualRecords.db");
  17. LoadingScreen.database=DatabaseFactory.openOrCreate(LoadingScreen.uri, new DatabaseSecurityOptions(false));
  18. LoadingScreen.database.beginTransaction();
  19. Statement st=LoadingScreen.database.createStatement(statement);
  20. st.prepare();
  21. st.execute();
  22. st.close();
  23. LoadingScreen.database.commitTransaction();
  24. LoadingScreen.database.close();
  25. if(flag==1)
  26. {
  27. System.out.println("============================Table Created Successfully");
  28. }
  29. else if(flag==2)
  30. {
  31. UiApplication.getUiApplication().invokeLater(new Runnable()
  32. {
  33. public void run()
  34. {
  35. Dialog.alert("Record Added Successfully");
  36. }
  37. });
  38. }
  39. else if(flag==3)
  40. {
  41. UiApplication.getUiApplication().invokeLater(new Runnable()
  42. {
  43. public void run()
  44. {
  45. Dialog.alert("Record Updated Successfully");
  46. }
  47. });
  48. }
  49. }
  50. catch(Exception e)
  51. {
  52. try
  53. {
  54. LoadingScreen.database.commitTransaction();
  55. LoadingScreen.database.close();
  56. }
  57. catch(Exception exp)
  58. {
  59. exp.printStackTrace();
  60. System.out.println("Exception:======"+exp.getMessage()+"\n");
  61. }
  62. e.printStackTrace();
  63. System.out.println("Exception:======"+e.getMessage()+"\n");
  64. }
  65. }
  66. }
  67.  
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement