Guest User

Untitled

a guest
Jan 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. package hsqldb;
  2.  
  3. import java.io.IOException;
  4. import java.sql.ResultSet;
  5. import java.util.Scanner;
  6.  
  7. public class AnimalsDBTest
  8. {
  9. public static void main(String[] args) throws Exception
  10. {
  11. Database db = null;
  12. try
  13. {
  14. db = new Database("sa", "","AnimalsDB");
  15. db.update("INSERT INTO animals VALUES('ant');");
  16. ResultSet rs = db.query("SELECT * FROM animals;");
  17. while (rs.next())
  18. {
  19. System.out.println(rs.getString("type"));
  20. }
  21.  
  22. Scanner scan = new Scanner(System.in);
  23. boolean stop = false;
  24. while(!stop)
  25. {
  26. System.out.println("Would you like to delete the entry 'ant'?");
  27. String sc = scan.nextLine();
  28. if ("y".equals(sc))
  29. {
  30. db.update("DELETE FROM animals WHERE type = 'ant'");
  31. System.out.println("Entry was deleted");
  32. rs = db.query("SELECT * FROM animals;");
  33. stop=true;
  34. while (rs.next())
  35. {
  36. System.out.println(rs.getString("type"));
  37. }
  38. }
  39. else if("n".equals(sc))
  40. {
  41. System.out.println("Thanks");
  42. stop=true;
  43. }
  44. else
  45. {
  46. System.out.println("Invalid Char");
  47. }
  48. }
  49.  
  50.  
  51. }
  52. catch(Exception e)
  53. {
  54. e.printStackTrace();
  55. System.out.println("There was an error accessing the Database");
  56. }
  57. finally
  58. {
  59. try
  60. {
  61. db.close();
  62. }
  63. catch (Exception ex)
  64. {
  65. ex.printStackTrace();
  66. }
  67. }
  68.  
  69. }//end of main
  70. }//end of AnimalsDBTest class
Add Comment
Please, Sign In to add comment