private void search() {
		
		String searchPrototype = view.getSearchText().getText().trim();
		
		String sqlQueryString = "select * from songs where title = ?";
		
		// from here up to the try statement is part C.
		
		boolean specialCase = false;
		boolean invalidEntry = false;
		
		//check some special cases
        if(searchPrototype.equals("*") || searchPrototype.equals("%") || searchPrototype.equals(""))
        {
        	sqlQueryString = "select * from songs";
        	specialCase = true;
        }
        
        
        // outputs invalid sql command if there is a sql insertion in the gui
        if (searchPrototype.startsWith("Select *") || searchPrototype.startsWith("select *") || searchPrototype.startsWith("SELECT *") )
        {
        	sqlQueryString = "select * from songs";
        	invalidEntry = true;
        	System.out.println("\nInvalid sql command \n");
        }
        
		if (selectedBook != null && !specialCase && !invalidEntry)
			sqlQueryString += " and bookcode = ?";
		
		else if (specialCase && selectedBook != null && !invalidEntry)
			sqlQueryString += " where bookcode = ?";
		
		
		sqlQueryString += " order by title asc;";
        
        
        
        

	    try {
	    	
	    	// part D
	    	PreparedStatement select = this.databaseConnection.prepareStatement(sqlQueryString);
	    	
	    	if (!specialCase && !invalidEntry)
	    		select.setString(1, searchPrototype);
	    	
	    	if (selectedBook != null && specialCase && !invalidEntry)
	    		select.setString(1, selectedBook.getBookCode());
	    	
	    	else if (selectedBook != null && !specialCase && !invalidEntry)
	    		select.setString(2, selectedBook.getBookCode());
	    	
			select.execute();
	    	
			ResultSet rs = select.getResultSet();
			
	    	
			//ResultSet rs = stat.executeQuery(sqlQueryString);
			
            ArrayList<FakeBookSong> songSearchResults = new ArrayList<FakeBookSong>();

	        int count = 0;
	        while (rs.next() && count < GUI_DISPLAY_LIMIT){
	        	FakeBookSong song = new FakeBookSong(
	        			rs.getInt("id"),
	        			rs.getString("bookcode"),
	        			rs.getInt("page"),
	        			rs.getString("title")
	        			);
	        	
	            songSearchResults.add(song);
            count++;
	        }
	        rs.close(); //close the query result table
	        FakeBookSong songArray[] = new FakeBookSong[1]; //just to establish array type
	        songList = songSearchResults;

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println("Search clicked");
		update();
	}