Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hsqldb;
- import java.io.IOException;
- import java.sql.ResultSet;
- import java.util.Scanner;
- public class AnimalsDBTest
- {
- public static void main(String[] args) throws Exception
- {
- Database db = null;
- try
- {
- db = new Database("sa", "","AnimalsDB");
- db.update("INSERT INTO animals VALUES('ant');");
- ResultSet rs = db.query("SELECT * FROM animals;");
- while (rs.next())
- {
- System.out.println(rs.getString("type"));
- }
- Scanner scan = new Scanner(System.in);
- boolean stop = false;
- while(!stop)
- {
- System.out.println("Would you like to delete the entry 'ant'?");
- String sc = scan.nextLine();
- if ("y".equals(sc))
- {
- db.update("DELETE FROM animals WHERE type = 'ant'");
- System.out.println("Entry was deleted");
- rs = db.query("SELECT * FROM animals;");
- stop=true;
- while (rs.next())
- {
- System.out.println(rs.getString("type"));
- }
- }
- else if("n".equals(sc))
- {
- System.out.println("Thanks");
- stop=true;
- }
- else
- {
- System.out.println("Invalid Char");
- }
- }
- }
- catch(Exception e)
- {
- e.printStackTrace();
- System.out.println("There was an error accessing the Database");
- }
- finally
- {
- try
- {
- db.close();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- }//end of main
- }//end of AnimalsDBTest class
Add Comment
Please, Sign In to add comment