YouTube Video Viewing Organizer

JSP

Gone are the days when simple logos and letters mean anything. There is just too much video content. Cable got a clue and so cable channels are somewhat more mnemonic about their content and identity, but, with YouTube serving up literally millions of videos, people need an updated meaning for the term “channel”. Personally, I do not relate at all to nutty anonymous meaningless user ids, especially when they are innumerable. They’re just garbage data, and who needs that? What we need is some functionality for the viewers to save “search terms” with their own labels as channels.

So, it took a few hours of coding, but it's done. Basically, I just “tweaked” a copy of another application that I wrote that does a similar type of job. I guess, YouTube can dress it up and scale it for itself, if it so chooses.

First of all, we can use a table to store our channel records. Here is the SQL for creating a reasonable looking table. -- DROP TABLE YouTube ; CREATE TABLE YouTube ( 	id            INTEGER, -- unique id  	search_terms  VARCHAR(255), -- example : 'surfing hawaii'  	description   VARCHAR(255) -- descriptive label for channel ) ;

With that little prerequisite out of the way, here is a screen shot of the main page. It is pretty self explanatory. Click a “hotspot” to see a list of videos. Click a button to manage the list of channels.



That’s the background. Here is the code. &lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.text.*" import="java.io.*" import="java.sql.*" import="java.util.*" errorPage="" %> &lt;%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> &lt;% /* * YouTubeChannelGuide.jsp * * Copyright (c) 2013 Alfred J Wheeler * All rights reserved. * * This software is the proprietary * information of Alfred J Wheeler * */ /**  * The purpose of this program is to provide user defined * channels, i.e. saved and named searches, for YouTube. * * USAGE *  YouTubeChannelGuide.jsp * * @author      10/9/2013 created by Alfred J Wheeler. * * @version     0.1 * * @see         YouTubeChannelAdd, YouTubeChannelEdit, YouTubeChannelRemove * */ /*  * Database : demonstration, Table : youtube *  * field name                        data type * ---  ---  * id                                integer * search_terms                     character varying(255) * description                      character varying(255) */ /* * Initialize some variables */ String message = ""; long dt = 0; String title = null; Connection conn = null; Statement st = null; ResultSet rs = null; String sql = ""; /* * Get a date time stamp. Set a page title, if needed... */ dt = System.currentTimeMillis; title = "YouTube Video Channels"; /* * Get the database connection values, etc... from the properties file * ( This eventually will be externalized to reduce code clutter... ) */ String p = application.getRealPath("/") + "properties/Demo.properties"; InputStream propsFile; Properties appProp = new Properties; try { propsFile = new FileInputStream(p); appProp.load(propsFile); propsFile.close; } catch (IOException ioe) { out.println("&lt;PRE>"); out.println("I/O Exception."); ioe.printStackTrace; out.println("&lt;/PRE>"); } String dbDriver = "" + appProp.getProperty("dbDriver"); String dbUrl   = "" + appProp.getProperty("dbUrl"); String dbUid   = "" + appProp.getProperty("dbUid"); String dbUpw   = "" + appProp.getProperty("dbUpw"); String css     = "" + appProp.getProperty("css"); //out.println("&lt;PRE>"); //out.println(dbDriver); //out.println(dbUrl); //out.println(dbUid); //out.println(dbUpw); //out.println("&lt;/PRE>"); /* * Open the database */ try { Class.forName(dbDriver); conn = DriverManager.getConnection(dbUrl, dbUid, dbUpw); st = conn.createStatement; %> &lt;!DOCTYPE html> &lt;HTML> &lt;HEAD> &lt;link rel="stylesheet" type="text/css" href="&lt;%=css%>"> &lt;TITLE>&lt;%=title%>&lt;/TITLE> &lt;SCRIPT LANGUAGE="JavaScript" SRC="angular.js">&lt;/SCRIPT> &lt;/HEAD> &lt;BODY> &lt;H1>&lt;%=title%>&lt;/H1> &lt;br> &lt;div class="centered"> &lt;nobr> &lt;form action="YouTubeChannelAdd.jsp" name=f> &lt;input name=btnG type=submit value=" Add New Channel "> &lt;/form> &lt;/nobr> &lt;/div> &lt;br> &lt;TABLE border="1" cellspacing="0"> &lt;TBODY> &lt;th colspan="2">Channels&lt;/th> &lt;tr> &lt;td colspan="2">&lt;A HREF="http://www.youtube.com/" target="_blank">YouTube&lt;/A>&lt;/td> &lt;/tr> &lt;% sql = "SELECT " + "id, " + "search_terms, " + "description " + "FROM youtube " + "ORDER BY UPPER( description )"; //		out.print("sql = " + sql + " \n"); rs = st.executeQuery(sql); while(rs.next) { out.println( "&lt;tr>" ); out.println( "&lt;td>&lt;A HREF=\"https://gdata.youtube.com/feeds/api/videos?q=" + rs.getString("search_terms") + "\" target=\"_blank\" >" + rs.getString("description") + "&lt;/A>&lt;/td>" ); out.println( "&lt;td>" ); out.println( "&lt;table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" ); out.println( "&lt;tr>" ); out.println( "&lt;td>" ); out.println( "&lt;form action=\"YouTubeChannelEdit.jsp\" name=\"edit\">" ); out.println( "&lt;input name=\"id\" type=\"hidden\" value=\"" + rs.getString("id") + "\">" ); out.println( "&lt;input name=\"btnG\" type=\"submit\" value=\"Edit Channel\">" ); out.println( "&lt;/form>" ); out.println( "&lt;/td>" ); out.println( "&lt;td>" ); out.println( "&lt;form action=\"YouTubeChannelRemove.jsp\" name=\"remove\">" ); out.println( "&lt;input name=\"id\" type=\"hidden\" value=\"" + rs.getString("id") + "\">" ); out.println( "&lt;input name=\"btnG\" type=\"submit\" value=\"Remove Channel\">" ); out.println( "&lt;/form>" ); out.println( "&lt;/td>" ); out.println( "&lt;/tr>" ); out.println( "&lt;/table>" ); out.println( "&lt;/td>" ); out.println( "&lt;/tr>" ); } %> &lt;/tbody>&lt;/table> &lt;% } // end try catch ( SQLException ex ) { out.println ( "&lt;pre>" ); out.println ( "---" ); out.println ( "--                      FATAL ERROR IN SQL" ); out.println ( "---" ); out.println ( "-- " ); while ( ex != null ) { out.println ("-- SQLState: " + ex.getSQLState ); out.println ("-- Message: " + ex.getMessage ); out.println ("-- Vendor:  " + ex.getErrorCode ); ex = ex.getNextException ; out.println ( "-- " ); } 		out.println ( "---" ); } // end catch catch ( java.lang.Exception ex ) { /* 		 * Got some other type of exception. Dump it. */ 		out.println ( "&lt;pre>" ); out.println ( "---" ); ex.printStackTrace ; out.println("exception: " + ex.getMessage ); } // end catch finally { // No action for now } // end finally %> &lt;br>&lt;br>&lt;br>&lt;br> &lt;/body> &lt;/html>

That’s all there is to the main page. As usual, we want to be able to add, edit and delete records.

Here is a screen shot of the “Add a record” page.



Here is the code. &lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.io.*" import="java.sql.*" import="java.util.*" import="java.util.Properties" errorPage="" %> &lt;% /* * YouTubeChannelAdd.jsp * * Copyright (c) 2013 Alfred J Wheeler * All rights reserved. * * This software is the proprietary * information of Alfred J Wheeler * */ /**  * The purpose of this application is to add a record to table YouTube * * USAGE *  YouTubeChannelAdd.jsp * * @author      10/9/2013 created by Alfred J Wheeler. * * @version     0.1 * * @see         YouTubeChannelGuide, YouTubeChannelEdit, YouTubeChannelRemove * */ /*  * Database : demonstration, Table : youtube *  * field name                        data type * ---  ---  * id                                integer * search_terms                     character varying(255) * description                      character varying(255) */ /* * Initialize some variables */ long dt = 0; String title = null; Connection conn = null; Statement st = null; ResultSet rs = null; String sql = ""; String posted = "false"; boolean populated = true; boolean duplicate = false; int records = 0; String message = ""; int errors = 0; //String tableName = null; String youtubeSearchTerms = ""; String youtubeDescription = ""; /* * Get a date time stamp. Set a page title, if needed... */ dt = System.currentTimeMillis; title = "YouTube - Add New Channel"; /* * Get the database connection values, etc... from the properties file * ( This eventually will be externalized to reduce code clutter... ) */ String p = application.getRealPath("/") + "properties/Demo.properties"; InputStream propsFile; Properties appProp = new Properties; try { propsFile = new FileInputStream(p); appProp.load(propsFile); propsFile.close; } catch (IOException ioe) { out.println("&lt;PRE>"); out.println("I/O Exception."); ioe.printStackTrace; out.println("&lt;/PRE>"); } String dbDriver = "" + appProp.getProperty("dbDriver"); String dbUrl   = "" + appProp.getProperty("dbUrl"); String dbUid   = "" + appProp.getProperty("dbUid"); String dbUpw   = "" + appProp.getProperty("dbUpw"); String css     = "" + appProp.getProperty("css"); //out.println("&lt;PRE>"); //out.println(dbDriver); //out.println(dbUrl); //out.println(dbUid); //out.println(dbUpw); //out.println("&lt;/PRE>"); /* * Open the database */ try { Class.forName(dbDriver); conn = DriverManager.getConnection(dbUrl, dbUid, dbUpw); st = conn.createStatement; /* 	 * Get the request values */ 	if ( request.getParameter( "posted" ) == null ) { posted = "false"; } 	else { posted = request.getParameter( "posted" ); } 	if ( posted.equals("true") ) { /* 		 * Are the fields populated? */ 		youtubeSearchTerms = request.getParameter( "youtube_search_terms" ); youtubeDescription = request.getParameter( "youtube_description" ); populated = true; if ( (request.getParameter( "youtube_description" )).equals( "" ) ) { if ( (request.getParameter( "youtube_search_terms" )).equals( "" ) ) { populated = false; message = "Blank record not allowed. Please enter some values."; errors++; } 		} 		/* 		 * Does record exist already? */ 		duplicate = false; if ( populated ) { sql = "SELECT COUNT(*) AS records " + "FROM " + "youtube" + " " + // It may make sense to use a variable here at some point... "WHERE description = '" + request.getParameter( "youtube_description" ) + "' " + "AND search_terms = '" + request.getParameter( "youtube_search_terms" ) + "' " ; //			out.print("sql = " + sql + " \n"); rs = st.executeQuery(sql); if (rs.next) { records = Integer.parseInt( rs.getString("records") ); if ( records > 0 ) { duplicate = true; message = "Record already exists. Duplicate records not allowed. Please check your entries."; errors++; } 			} 		} 		/* 		 * If no error, save data, clear fields, display form */ 		/* 		 * Save data... */ 		if ( errors == 0 ) { sql = "INSERT INTO " + "youtube" + " " + // It may make sense to use a variable for the tableName here at some point... "SELECT " + "(SELECT COALESCE(MAX(id), 0) + 1 FROM youtube) AS id, " + "'" + request.getParameter( "youtube_search_terms" ) + "' AS search_terms, " + "'" + request.getParameter( "youtube_description" ) + "' AS description " ; //			out.print("sql = " + sql + " \n"); st.execute(sql); } 		/* 		 * Clear fields... */ 		youtubeSearchTerms = ""; youtubeDescription = ""; /* 		 * If error, display form as is with the message produced by the preceding code... 		 */ } %> &lt;!DOCTYPE html> &lt;HTML> &lt;HEAD> &lt;link rel="stylesheet" type="text/css" href="&lt;%=css%>"> &lt;TITLE>&lt;%=title%>&lt;/TITLE> &lt;SCRIPT LANGUAGE="JavaScript" SRC="angular.js">&lt;/SCRIPT> &lt;SCRIPT LANGUAGE="JavaScript" SRC="jquery.js">&lt;/SCRIPT> &lt;/HEAD> &lt;BODY> &lt;H1>&lt;%=title%>&lt;/H1> &lt;br> &lt;div align="center"> &lt;nobr> &lt;div class="centered"> &lt;nobr> &lt;form action="YouTubeChannelGuide.jsp" name=f> &lt;input name=btnG type=submit value=" Return to YouTube Video Channel Guide "> &lt;/form> &lt;/nobr> &lt;/div> &lt;br> &lt;p class="centered">&lt;%=message%>&lt;/p> &lt;FORM NAME="form1" METHOD="POST"> &lt;!--Get time and pass as hidden variable in query_string to force browser to get page from server instead of cache... --> &lt;% dt = System.currentTimeMillis; %> &lt;input type="hidden" name="dt&lt;%= dt %>" value="&lt;%= dt %>"> &lt;input type="hidden" name="posted" value="true"> &lt;input type="hidden" name="tableName" value="youtube"> &lt;table class="ivory" align="center" xwidth="80%" border="0" cellspacing="0" cellpadding="16"> &lt;TBODY> &lt;tr> &lt;td>&lt;b>Search terms:&lt;/B>&lt;/td>&lt;td>&lt;input type="text" name="youtube_search_terms" size="127" value="">&lt;/td> &lt;/tr> &lt;tr> &lt;td>&lt;b>Channel description:&lt;/B>&lt;/td>&lt;td>&lt;input type="text" name="youtube_description" size="127" value="">&lt;/td> &lt;/tr> &lt;tr> &lt;td> &lt;/td>&lt;td> &lt;div > &lt;input type="submit" name="submit" value="Submit"> &lt;input type="reset" name="clear" value="Reset"> &lt;/div> &lt;/td> &lt;/tr> &lt;/table> &lt;br>&lt;br> &lt;/form> &lt;/nobr> &lt;/div> &lt;% } // end try catch ( SQLException ex ) { out.println ( "&lt;pre>" ); out.println ( "---" ); out.println ( "--                      FATAL ERROR IN SQL" ); out.println ( "---" ); out.println ( "-- " ); while ( ex != null ) { out.println ("-- SQLState: " + ex.getSQLState ); out.println ("-- Message: " + ex.getMessage ); out.println ("-- Vendor:  " + ex.getErrorCode ); ex = ex.getNextException ; out.println ( "-- " ); } 	out.println ( "---" ); } // end catch catch ( java.lang.Exception ex ) { /* 	 * Got some other type of exception. Dump it. */ 	out.println ( "&lt;pre>" ); out.println ( "---" ); ex.printStackTrace ; out.println("exception: " + ex.getMessage ); } // end catch finally { // No action for now } // end finally %> &lt;/BODY> &lt;/HTML>

That’s cool. We can watch our favorite channels and add new channels as our interests wander, but what if we messed up a description or our search terms, e.g. instead of returning videos about “God and Country”, our search returns videos about “Dog an Country”? Well, you know it, once again, we have an app for that! Here’s the screen shot.



Here is the code. &lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.io.*" import="java.sql.*" import="java.util.*" import="java.util.Properties" errorPage="" %> &lt;%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> &lt;% /* * YouTubeChannelEdit.jsp * * Copyright (c) 2013 Alfred Wheeler * All rights reserved. * * This software is the proprietary * information of Alfred Wheeler * */ /**  * The purpose of this application is to edit a record of table "YouTube" * * USAGE *  YouTubeChannelEdit.jsp * * @author      10/9/2013 created by Alfred Wheeler. * * @version     0.1 * * @see         YouTubeChannelGuide, YouTubeChannelAdd, YouTubeChannelRemove * */ /*  * Database : demonstration, Table : youtube *  * field name                        data type * ---  ---  * id                                integer * search_terms                     character varying(255) * description                      character varying(255) */ /* * Initialize some variables */ long dt = 0; String title = null; Connection conn = null; Statement st = null; ResultSet rs = null; String sql = ""; String posted = "false"; boolean populated = true; boolean recordExists = true; boolean duplicate = false; boolean updated = false; int records = 0; String message = ""; int errors = 0; //String tableName = null; String youtubeId = ""; String editYouTubeSearchTerms = ""; String editYouTubeDescription = ""; String s = null; // miscellaneous utility variable /* * Get a date time stamp. Set a page title, if needed... */ dt = System.currentTimeMillis; title = "YouTube - Edit Channel"; /* * Get the database connection values, etc... from the properties file * ( This should be externalized to reduce code clutter... ) */ String p = application.getRealPath("/") + "properties/Demo.properties"; InputStream propsFile; Properties appProp = new Properties; try { propsFile = new FileInputStream(p); appProp.load(propsFile); propsFile.close; } catch (IOException ioe) { out.println("&lt;PRE>"); out.println("I/O Exception."); ioe.printStackTrace; out.println("&lt;/PRE>"); } String dbDriver = "" + appProp.getProperty("dbDriver"); String dbUrl   = "" + appProp.getProperty("dbUrl"); String dbUid   = "" + appProp.getProperty("dbUid"); String dbUpw   = "" + appProp.getProperty("dbUpw"); String css     = "" + appProp.getProperty("css"); //out.println("&lt;PRE>"); //out.println(dbDriver); //out.println(dbUrl); //out.println(dbUid); //out.println(dbUpw); //out.println("&lt;/PRE>"); /* * Open the database */ try { Class.forName(dbDriver); conn = DriverManager.getConnection(dbUrl, dbUid, dbUpw); st = conn.createStatement; /* 	 * Get the request values */ 	if ( request.getParameter( "posted" ) == null ) { posted = "false"; } 	else { posted = request.getParameter( "posted" ); } 	if ( posted.equals("true") ) { /* 		 * 1. Check that the entries are not all blanked out (we don't want to erase any records...) * 2. Check that the entries are valid for their kind (a moot point, for this particular application...) * 3. Check that the significant (primary key) changes do not duplicate any other record... * 3. Make sure the record exists and, ideally, lock it, during the update * 4. Apply the change(s) * 5. Return to list */ 		/* 		 * Are the fields populated? */ 		youtubeId = request.getParameter( "youtube_id" ); editYouTubeSearchTerms = request.getParameter( "editYouTubeSearchTerms" ); editYouTubeDescription = request.getParameter( "editYouTubeDescription" ); populated = true; if ( (request.getParameter( "editYouTubeDescription" )).equals( "" ) ) { if ( (request.getParameter( "editYouTubeSearchTerms" )).equals( "" ) ) { populated = false; message = "Blank record not allowed. Please enter some values."; errors++; } 		} 		if ( (request.getParameter( "editYouTubeDescription" )).equals( "" ) ) { message = "Description is a required field. Please enter something."; errors++; } 		if ( (request.getParameter( "editYouTubeSearchTerms" )).equals( "" ) ) { message = "Search terms are required. Please enter some search values."; errors++; } 		/* 		 * Does record "still" exist? */ 		recordExists = true; if ( populated ) { sql = "SELECT COUNT(*) AS records " + "FROM " + "youtube" + " " + // It may make sense to use a variable for table_name at some point... "WHERE id = " + request.getParameter( "youtube_id" ) ; //			out.print("sql = " + sql + " \n"); rs = st.executeQuery(sql); if (rs.next) { records = Integer.parseInt( rs.getString("records") ); if ( records &lt; 1 ) { recordExists = false; message = "Record does not exist. You may have removed by some other means or another page."; errors++; } 			} 		} 		/* 		 * Would the change cause an "exact" duplicate? */ 		duplicate = false; if ( populated ) { sql = "SELECT COUNT(*) AS records " + "FROM " + "youtube" + " " + // It may make sense to use a variable here at some point... "WHERE description = '" + request.getParameter( "editYouTubeDescription" ) + "' " + "AND search_terms = '" + request.getParameter( "editYouTubeSearchTerms" ) + "' " + "AND id != " + request.getParameter( "youtube_id" ) ; //			out.print("sql = " + sql + " \n"); rs = st.executeQuery(sql); if (rs.next) { records = Integer.parseInt( rs.getString("records") ); if ( records > 0 ) { duplicate = true; message = "Record already exists. Duplicate records not allowed. Please check your entries."; errors++; } 			} 		} 		/* 		 * If no error, save data, clear fields, display form */ 		/* 		 * Save data... */ 		if ( errors == 0 ) { // This should be a call to a stored procedure... sql = "UPDATE youtube SET " + "search_terms = '" + request.getParameter( "editYouTubeSearchTerms" ) + "', " + "description = '" + request.getParameter( "editYouTubeDescription" ) + "' " + "WHERE id = '" + request.getParameter( "youtube_id" ) + "' "; //			out.print("sql = " + sql + " \n"); st.execute(sql); /* 			 * Return to list.... */ %> &lt;HTML> &lt;HEAD>&lt;TITLE>&lt;/TITLE>&lt;/HEAD> &lt;BODY onload="document.form1.submit"> &lt;div> &lt;form name="form1" method="POST" action="YouTubeChannelGuide.jsp?&lt;%=System.currentTimeMillis%>"> &lt;input type="image" src="images/dots/clear.gif" alt="submit" value="Continue"> &lt;/form> &lt;/div> &lt;% updated = true; } 	} 	else { // This is the first time here, so get the values from the database table /* 		 * Note: Must work out automating getting (or just editing) only the * fields that are relevant, e.g. the timestamps are generally not that * relevant to data entry persons */ 		sql = "SELECT " + "id AS youtube_id, " + "search_terms AS youtube_search_terms, " + "description AS youtube_description " + "FROM youtube " + "WHERE id = " + request.getParameter( "id" ) + " "; //		out.print("sql = " + sql + " \n"); rs = st.executeQuery(sql); if (rs.next) { youtubeId = rs.getString("youtube_id"); editYouTubeSearchTerms = rs.getString("youtube_search_terms"); editYouTubeDescription = rs.getString("youtube_description"); } 	} 	if ( updated == false ) { %> &lt;!DOCTYPE html> &lt;HTML> &lt;HEAD> &lt;link rel="stylesheet" type="text/css" href="&lt;%=css%>"> &lt;TITLE>&lt;%=title%>&lt;/TITLE> &lt;SCRIPT LANGUAGE="JavaScript" SRC="angular.js">&lt;/SCRIPT> &lt;SCRIPT LANGUAGE="JavaScript" SRC="jquery.js">&lt;/SCRIPT> &lt;/HEAD> &lt;BODY> &lt;H1>&lt;%=title%>&lt;/H1> &lt;br>&lt;br>&lt;br>&lt;br> &lt;div class="centered"> &lt;nobr> &lt;form action="YouTubeChannelGuide.jsp" name=f> &lt;input name=btnG type=submit value=" Return to YouTube Video Channel Guide "> &lt;/form> &lt;/nobr> &lt;/div> &lt;br> &lt;p class="centered">&lt;%=message%>&lt;/p> &lt;div class="centered"> &lt;FORM NAME="form1" METHOD="POST"> &lt;!--Get time and pass as hidden variable in query_string to force browser to get page from server instead of cache... --> &lt;% dt = System.currentTimeMillis; %> &lt;input type="hidden" name="dt&lt;%= dt %>" value="&lt;%= dt %>"> &lt;input type="hidden" name="posted" value="true"> &lt;input type="hidden" name="tableName" value="youtube"> &lt;input type="hidden" name="youtube_id" value="&lt;%=youtubeId%>"> &lt;table border="1"> &lt;TBODY> &lt;tr align="left"> &lt;td>&lt;b>Search terms:&lt;/B>&lt;/td>&lt;td>&lt;input type="text" name="editYouTubeSearchTerms" size="127" value="&lt;%= editYouTubeSearchTerms%>">&lt;/td> &lt;/tr> &lt;tr align="left"> &lt;td>&lt;b>Channel description:&lt;/B>&lt;/td>&lt;td>&lt;input type="text" name="editYouTubeDescription" size="127" value="&lt;%= editYouTubeDescription%>">&lt;/td> &lt;/tr> &lt;tr align="left"> &lt;td> &lt;/td>&lt;td> &lt;div > &lt;input type="submit" name="submit" value="Submit"> &lt;input type="reset" name="clear" value="Reset"> &lt;/div> &lt;/td> &lt;/tr> &lt;/table> &lt;br>&lt;br> &lt;/form> &lt;/div> &lt;% } } // end try catch ( SQLException ex ) { out.println ( "&lt;pre>" ); out.println ( "---" ); out.println ( "--                      FATAL ERROR IN SQL" ); out.println ( "---" ); out.println ( "-- " ); while ( ex != null ) { out.println ("-- SQLState: " + ex.getSQLState ); out.println ("-- Message: " + ex.getMessage ); out.println ("-- Vendor:  " + ex.getErrorCode ); ex = ex.getNextException ; out.println ( "-- " ); } 	out.println ( "---" ); } // end catch catch ( java.lang.Exception ex ) { /* 	 * Got some other type of exception. Dump it. */ 	out.println ( "&lt;pre>" ); out.println ( "---" ); ex.printStackTrace ; out.println("exception: " + ex.getMessage ); } // end catch finally { // No action for now } // end finally %> &lt;/body> &lt;/html>

Sometimes we lose interest in a topic and haven’t yet fixated on anything else, but that doggone channel is still on our list and it is just another distraction that we do not need. In such cases, the thing to do is remove the item from the list. Here is the screen shot.



Here is the code. &lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.io.*" import="java.sql.*" import="java.util.*" import="java.util.Properties" errorPage="" %> &lt;%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> &lt;% /* * YouTubeChannelRemove.jsp * * Copyright (c) 2013 Alfred Wheeler * All rights reserved. * * This software is the proprietary * information of Alfred Wheeler * */ /**  * The purpose of this application is to remove a record from table "YouTube" * * USAGE *  YouTubeChannelRemove.jsp * * @author      10/9/2013 created by Alfred Wheeler. * * @version     0.1 * * @see         YouTubeChannelGuide, YouTubeChannelAdd, YouTubeChannelEdit * */ /*  * Database : demonstration, Table : youtube *  * field name                        data type * ---  ---  * id                                integer * search_terms                     character varying(255) * description                      character varying(255) */ /* * Initialize some variables */ long dt = 0; String title = null; Connection conn = null; DatabaseMetaData dbmd = null; Statement st = null; ResultSet rs = null; ResultSetMetaData rsmd = null; String sql = ""; String posted = "false"; boolean populated = true; boolean recordExists = true; boolean duplicate = false; int records = 0; String message = ""; int errors = 0; //String tableName = null; String youtubeId = ""; String editYouTubeSearchTerms = ""; String editYouTubeDescription = ""; Integer columns = 0; int column = 0; String fields = null; String s = null; // miscellaneous utility variable /* * Get a date time stamp. Set a page title, if needed... */ dt = System.currentTimeMillis; title = "YouTube - Remove Channel"; /* * Get the database connection values, etc... from the properties file * ( This eventually will be externalized to reduce code clutter... ) */ String p = application.getRealPath("/") + "properties/Demo.properties"; InputStream propsFile; Properties appProp = new Properties; try { propsFile = new FileInputStream(p); appProp.load(propsFile); propsFile.close; } catch (IOException ioe) { out.println("&lt;PRE>"); out.println("I/O Exception."); ioe.printStackTrace; out.println("&lt;/PRE>"); } String dbDriver = "" + appProp.getProperty("dbDriver"); String dbUrl   = "" + appProp.getProperty("dbUrl"); String dbUid   = "" + appProp.getProperty("dbUid"); String dbUpw   = "" + appProp.getProperty("dbUpw"); String css     = "" + appProp.getProperty("css"); /* * Open the database */ try { Class.forName(dbDriver); conn = DriverManager.getConnection(dbUrl, dbUid, dbUpw); st = conn.createStatement; /* 	 * Get the request values */ 	if ( request.getParameter( "posted" ) == null ) { posted = "false"; } 	else { posted = request.getParameter( "posted" ); } 	if ( posted.equals("true") ) { /* 		 * 1. Make sure the record exists and, ideally, lock it, during the removal * 2. Remove the record * 3. Return to list */ 		/* 		 * Does record "still" exist? */ 		recordExists = true; if ( populated ) { sql = "SELECT COUNT(*) AS records " + "FROM " + "youtube" + " " + // It may make sense to use a variable for table_name at some point... "WHERE id = " + request.getParameter( "id" ) ; //			out.print("sql = " + sql + " \n"); rs = st.executeQuery(sql); if (rs.next) { records = Integer.parseInt( rs.getString("records") ); if ( records &lt; 1 ) { recordExists = false; message = "Record does not exist. You may have removed by some other means or another page."; errors++; } 			} 		} 		/* 		 * If no error, delete the record and then return to list */ 		if ( errors == 0 ) { sql = "DELETE FROM youtube " + "WHERE id = " + request.getParameter( "id" ) + " "; //out.println( "sql = " + sql); st.execute( sql ); %> &lt;BODY onload="document.form1.submit"> &lt;div> &lt;form name="form1" method="POST" action="YouTubeChannelGuide.jsp?&lt;%=dt%>"> &lt;input type="image" src="images/dots/clear.gif" alt="submit" value="Continue"> &lt;/form> &lt;/div> &lt;% } 	} 	/* 	 * If we got this far, then either we arrived from another page or there was some error... */ %> &lt;!DOCTYPE html> &lt;HTML> &lt;HEAD> &lt;link rel="stylesheet" type="text/css" href="&lt;%=css%>"> &lt;TITLE>&lt;%=title%>&lt;/TITLE> &lt;SCRIPT LANGUAGE="JavaScript" SRC="angular.js">&lt;/SCRIPT> &lt;SCRIPT LANGUAGE="JavaScript" SRC="jquery.js">&lt;/SCRIPT> &lt;/HEAD> &lt;BODY> &lt;H1>&lt;%=title%>&lt;/H1> &lt;br>&lt;br>&lt;br>&lt;br> &lt;div class="centered"> &lt;nobr> &lt;form action="YouTubeChannelGuide.jsp" name=f> &lt;input name=btnG type=submit value=" Return to YouTube Video Channel Guide "> &lt;/form> &lt;/nobr> &lt;/div> &lt;br> &lt;p class="centered">&lt;%=message%>&lt;/p> &lt;% fields = "id, search_terms, description"; // will implement this later... sql = "SELECT " + fields + " FROM " + "youtube" + " " + "WHERE id = " + request.getParameter( "id" ) + " "; //out.print("\n\nsql = " + sql + "\n\n"); rs = st.executeQuery(sql); rsmd = rs.getMetaData; columns = rsmd.getColumnCount; rs = st.executeQuery(sql); if (rs.next) { %> &lt;div class="centered"> &lt;FORM NAME="form1" METHOD="POST"> &lt;!--Get time and pass as hidden variable in query_string to force browser to get page from server instead of cache... --> &lt;% dt = System.currentTimeMillis; %> &lt;input type="hidden" name="dt&lt;%= dt %>" value="&lt;%= dt %>"> &lt;input type="hidden" name="posted" value="true"> &lt;input type="hidden" name="tableName" value="youtube"> &lt;input type="hidden" name="youtube_id" value="&lt;%=request.getParameter( "youtube_id" )%>"> &lt;table class="ivory" border="0" cellspacing="0"> &lt;TBODY> &lt;tr>&lt;th>Field&lt;/th>&lt;th>Value&lt;/th>&lt;/tr> &lt;% for( column=1; column&lt;=columns ; column++ ) { out.println ( "&lt;tr align=\"left\">" ); out.println ( "&lt;td>&lt;b>" + rsmd.getColumnName( column ) + ":&lt;/B>&lt;/td>" ); out.println ( "&lt;td>" + rs.getString( rsmd.getColumnName( column ) ) + "&lt;/td>" ); out.println ( "&lt;/tr>" ); } %> &lt;tr align="left"> &lt;td> &lt;/td>&lt;td> &lt;div > &lt;input type="submit" name="submit" value=" Confirm "> &lt;/div> &lt;/td> &lt;/tr> &lt;/table> &lt;br>&lt;br> &lt;/form> &lt;/div> &lt;% } // end if for result set handling } // end try catch ( SQLException ex ) { out.println ( "&lt;pre>" ); out.println ( "---" ); out.println ( "--                      FATAL ERROR IN SQL" ); out.println ( "---" ); out.println ( "-- " ); while ( ex != null ) { out.println ("-- SQLState: " + ex.getSQLState ); out.println ("-- Message: " + ex.getMessage ); out.println ("-- Vendor:  " + ex.getErrorCode ); ex = ex.getNextException ; out.println ( "-- " ); } 	out.println ( "---" ); } // end catch catch ( java.lang.Exception ex ) { /* 	 * Got some other type of exception. Dump it. */ 	out.println ( "&lt;pre>" ); out.println ( "---" ); ex.printStackTrace ; out.println("exception: " + ex.getMessage ); } // end catch finally { // No action for now } // end finally %> &lt;/body> &lt;/html>

That’s all there is to it. Enjoy your channel hopping!