DBResults.java: Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways #Programming Code Examples #Java/J2EE/J2ME #JDBC


# DBResults.java  Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways:

    * ResultSet doesn?t necessarily have all the data; reconnection to database occurs as you ask for later rows.
    * This class stores results as strings, in arrays.
    * This class includes DatabaseMetaData (database product name and version) and ResultSetMetaData (the column names).
    * This class has a toHTMLTable method that turns the results into a long string corresponding to an HTML table. 




package cwp;

import java.sql.*;
import java.util.*;

/** Class to store completed results of a JDBC Query.
 *  Differs from a ResultSet in several ways:
 *  
    *
  • ResultSet doesn't necessarily have all the data; * reconnection to database occurs as you ask for * later rows. *
  • This class stores results as strings, in arrays. *
  • This class includes DatabaseMetaData (database product * name and version) and ResultSetMetaData * (the column names). *
  • This class has a toHTMLTable method that turns * the results into a long string corresponding to * an HTML table. *
*

*/ public class DBResults { private Connection connection; private String productName; private String productVersion; private int columnCount; private String[] columnNames; private Vector queryResults; String[] rowData; public DBResults(Connection connection, String productName, String productVersion, int columnCount, String[] columnNames) { this.connection = connection; this.productName = productName; this.productVersion = productVersion; this.columnCount = columnCount; this.columnNames = columnNames; rowData = new String[columnCount]; queryResults = new Vector(); } public Connection getConnection() { return(connection); } public String getProductName() { return(productName); } public String getProductVersion() { return(productVersion); } public int getColumnCount() { return(columnCount); } public String[] getColumnNames() { return(columnNames); } public int getRowCount() { return(queryResults.size()); } public String[] getRow(int index) { return((String[])queryResults.elementAt(index)); } public void addRow(String[] row) { queryResults.addElement(row); } /** Output the results as an HTML table, with * the column names as headings and the rest of * the results filling regular data cells. */ public String toHTMLTable(String headingColor) { StringBuffer buffer = new StringBuffer("

n"); if (headingColor != null) { buffer.append(" n "); } else { buffer.append(" n "); } for(int col=0; col<getcolumncount (); col++) { buffer.append("n "); String[] rowData = getRow(row); for(int col=0; col<getcolumncount (); col++) { buffer.append("
" + columnNames[col]); } for(int row=0; row<getrowcount (); row++) { buffer.append("n
" + rowData[col]); } } buffer.append("n
"); return(buffer.toString()); } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10204
Categories:Programming Code Examples, Java/J2EE/J2ME, JDBC
Tags:Java/J2EE/J2MEJDBC
Post Data:2017-01-02 16:04:23

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

DatabaseUtilities.java: Several general-purpose utilities discussed and used in the chapter. #Programming Code Examples #Java/J2EE/J2ME #JDBC

package cwp;

import java.sql.*;

/** Three database utilities:
* 1) getQueryResults. Connects to a database, executes * a query, retrieves all the rows as arrays * of strings, and puts them inside a DBResults * object. Also places the database product name, * database version, and the names of all the columns * into the DBResults object. This has two versions: * one that makes a new connection and another that * uses an existing connection.

* 2) createTable. Given a table name, a string denoting * the column formats, and an array of strings denoting * the row values, this method connects to a database, * removes any existing versions of the designated * table, issues a CREATE TABLE command with the * designated format, then sends a series of INSERT INTO * commands for each of the rows. Again, there are * two versions: one that makes a new connection and * another that uses an existing connection.

* 3) printTable. Given a table name, this connects to * the specified database, retrieves all the rows, * and prints them on the standard output. */ public class DatabaseUtilities { /** Connect to database, execute specified query, * and accumulate results into DBRresults object. * If the database connection is left open (use the * close argument to specify), you can retrieve the * connection via DBResults.getConnection. */ public static DBResults getQueryResults(String driver, String url, String username, String password, String query, boolean close) { try { Class.forName(driver); Connection connection = DriverManager.getConnection(url, username, password); return(getQueryResults(connection, query, close)); } catch(ClassNotFoundException cnfe) { System.err.println("Error loading driver: " + cnfe); return(null); } catch(SQLException sqle) { System.err.println("Error connecting: " + sqle); return(null); } } /** Retrieves results as in previous method, but uses * an existing connection instead of opening a new one. */ public static DBResults getQueryResults(Connection connection, String query, boolean close) { try { DatabaseMetaData dbMetaData = connection.getMetaData(); String productName = dbMetaData.getDatabaseProductName(); String productVersion = dbMetaData.getDatabaseProductVersion(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query); ResultSetMetaData resultsMetaData = resultSet.getMetaData(); int columnCount = resultsMetaData.getColumnCount(); String[] columnNames = new String[columnCount]; // Column index starts at 1 (ala SQL) not 0 (ala Java). for(int i=1; i<columncount +1; i++) { columnNames[i-1] = resultsMetaData.getColumnName(i).trim(); } DBResults dbResults = new DBResults(connection, productName, productVersion, columnCount, columnNames); while(resultSet.next()) { String[] row = new String[columnCount]; // Again, ResultSet index starts at 1, not 0. for(int i=1; i<columnCount+1; i++) { String entry = resultSet.getString(i); if (entry != null) { entry = entry.trim(); } row[i-1] = entry; } dbResults.addRow(row); } if (close) { connection.close(); } return(dbResults); } catch(SQLException sqle) { System.err.println("Error connecting: " + sqle); return(null); } } /** Build a table with the specified format and rows. */ public static Connection createTable(String driver, String url, String username, String password, String tableName, String tableFormat, String[] tableRows, boolean close) { try { Class.forName(driver); Connection connection = DriverManager.getConnection(url, username, password); return(createTable(connection, username, password, tableName, tableFormat, tableRows, close)); } catch(ClassNotFoundException cnfe) { System.err.println("Error loading driver: " + cnfe); return(null); } catch(SQLException sqle) { System.err.println("Error connecting: " + sqle); return(null); } } /** Like the previous method, but uses existing connection. */ public static Connection createTable(Connection connection, String username, String password, String tableName, String tableFormat, String[] tableRows, boolean close) { try { Statement statement = connection.createStatement(); // Drop previous table if it exists, but don't get // error if it doesn't. Thus the separate try/catch here. try { statement.execute("DROP TABLE " + tableName); } catch(SQLException sqle) {} String createCommand = "CREATE TABLE " + tableName + " " + tableFormat; statement.execute(createCommand); String insertPrefix = "INSERT INTO " + tableName + " VALUES"; for(int i=0; i<tableRows.length; i++) { statement.execute(insertPrefix + tableRows[i]); } if (close) { connection.close(); return(null); } else { return(connection); } } catch(SQLException sqle) { System.err.println("Error creating table: " + sqle); return(null); } } public static void printTable(String driver, String url, String username, String password, String tableName, int entryWidth, boolean close) { String query = "SELECT * FROM " + tableName; DBResults results = getQueryResults(driver, url, username, password, query, close); printTableData(tableName, results, entryWidth, true); } /** Prints out all entries in a table. Each entry will * be printed in a column that is entryWidth characters * wide, so be sure to provide a value at least as big * as the widest result. */ public static void printTable(Connection connection, String tableName, int entryWidth, boolean close) { String query = "SELECT * FROM " + tableName; DBResults results = getQueryResults(connection, query, close); printTableData(tableName, results,entryWidth, true); } public static void printTableData(String tableName, DBResults results, int entryWidth, boolean printMetaData) { if (results == null) { return; } if (printMetaData) { System.out.println("Database: " + results.getProductName()); System.out.println("Version: " + results.getProductVersion()); System.out.println(); } System.out.println(tableName + ":"); String underline = padString("", tableName.length()+1, "="); System.out.println(underline); int columnCount = results.getColumnCount(); String separator = makeSeparator(entryWidth, columnCount); System.out.println(separator); String row = makeRow(results.getColumnNames(), entryWidth); System.out.println(row); System.out.println(separator); int rowCount = results.getRowCount(); for(int i=0; i<rowCount; i++) { row = makeRow(results.getRow(i), entryWidth); System.out.println(row); } System.out.println(separator); } // A String of the form "| xxx | xxx | xxx |" private static String makeRow(String[] entries, int entryWidth) { String row = "|"; for(int i=0; i<entries.length; i++) { row = row + padString(entries[i], entryWidth, " "); row = row + " |"; } return(row); } // A String of the form "+------+------+------+" private static String makeSeparator(int entryWidth, int columnCount) { String entry = padString("", entryWidth+1, "-"); String separator = "+"; for(int i=0; i<columnCount; i++) { separator = separator + entry + "+"; } return(separator); } private static String padString(String orig, int size, String padChar) { if (orig == null) { orig = ""; } // Use StringBuffer, not just repeated String concatenation // to avoid creating too many temporary Strings. StringBuffer buffer = new StringBuffer(""); int extraChars = size - orig.length(); for(int i=0; i<extrachars ; i++) { buffer.append(padChar); } buffer.append(orig); return(buffer.toString()); } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10203
Categories:Programming Code Examples, Java/J2EE/J2ME, JDBC
Tags:Java/J2EE/J2MEJDBC
Post Data:2017-01-02 16:04:23

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

FruitCreation.java: Creates a simple table named fruits in either an Oracle or a Sybase database. #Programming Code Examples #Java/J2EE/J2ME #JDBC

FruitCreation.java  Creates a simple table named fruits 
in either an Oracle or a Sybase database. 
**************************************

package cwp;

import java.sql.*;

/** Creates a simple table named "fruits" in either
 *  an Oracle or a Sybase database.
 *  

*/ public class FruitCreation { public static void main(String[] args) { if (args.length < 5) { printUsage(); return; } String vendorName = args[4]; int vendor = DriverUtilities.getVendor(vendorName); if (vendor == DriverUtilities.UNKNOWN) { printUsage(); return; } String driver = DriverUtilities.getDriver(vendor); String host = args[0]; String dbName = args[1]; String url = DriverUtilities.makeURL(host, dbName, vendor); String username = args[2]; String password = args[3]; String format = "(quarter int, " + "apples int, applesales float, " + "oranges int, orangesales float, " + "topseller varchar(16))"; String[] rows = { "(1, 32248, 3547.28, 18459, 3138.03, 'Maria')", "(2, 35009, 3850.99, 18722, 3182.74, 'Bob')", "(3, 39393, 4333.23, 18999, 3229.83, 'Joe')", "(4, 42001, 4620.11, 19333, 3286.61, 'Maria')" }; Connection connection = DatabaseUtilities.createTable(driver, url, username, password, "fruits", format, rows, false); // Test to verify table was created properly. Reuse // old connection for efficiency. DatabaseUtilities.printTable(connection, "fruits", 11, true); } private static void printUsage() { System.out.println("Usage: FruitCreation host dbName " + "username password oracle|sybase."); } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10202
Categories:Programming Code Examples, Java/J2EE/J2ME, JDBC
Tags:Java/J2EE/J2MEJDBC
Post Data:2017-01-02 16:04:23

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Some simple utilities for building Oracle and Sybase JDBC connections #Programming Code Examples #Java/J2EE/J2ME #JDBC

DriverUtilities.java  Some simple utilities for building Oracle and Sybase JDBC connections. 
This is not general-purpose code -- it is specific to our local setup.

package cwp;

/** Some simple utilities for building Oracle and Sybase
 *  JDBC connections. This is not general-purpose
 *  code -- it is specific to my local setup.
 */

public class DriverUtilities {
  public static final int ORACLE = 1;
  public static final int SYBASE = 2;
  public static final int UNKNOWN = -1;

  /** Build a URL in the format needed by the
   *  Oracle and Sybase drivers I am using.
   */
  
  public static String makeURL(String host, String dbName,
                               int vendor) {
    if (vendor == ORACLE) {
      return("jdbc:oracle:thin:@" + host + ":1521:" + dbName);
    } else if (vendor == SYBASE) {
      return("jdbc:sybase:Tds:" + host  + ":1521" +
             "?SERVICENAME=" + dbName);
    } else {
      return(null);
    }
  }

  /** Get the fully qualified name of a driver. */
  
  public static String getDriver(int vendor) {
    if (vendor == ORACLE) {
      return("oracle.jdbc.driver.OracleDriver");
    } else if (vendor == SYBASE) {
      return("com.sybase.jdbc.SybDriver");
    } else {
      return(null);
    }
  }

  /** Map name to int value. */

  public static int getVendor(String vendorName) {
    if (vendorName.equalsIgnoreCase("oracle")) {
      return(ORACLE);
    } else if (vendorName.equalsIgnoreCase("sybase")) {
      return(SYBASE);
    } else {
      return(UNKNOWN);
    }
  }
}

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10201
Categories:Programming Code Examples, Java/J2EE/J2ME, JDBC
Tags:Java/J2EE/J2MEJDBC
Post Data:2017-01-02 16:04:23

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

FruitTest.java: A class that connects to either an Oracle or a Sybase database and prints out the values of predetermined columns in the "fruits" table. #Programming Code Examples #Java/J2EE/J2ME #JDBC

# FruitTest.java  A class that connects to either an Oracle or a Sybase database and prints out the values of predetermined columns in the "fruits" table. 

package cwp;

import java.sql.*;

/** A JDBC example that connects to either an Oracle or
 *  a Sybase database and prints out the values of
 *  predetermined columns in the "fruits" table.
 *  

*/ public class FruitTest { /** Reads the hostname, database name, username, password, * and vendor identifier from the command line. It * uses the vendor identifier to determine which * driver to load and how to format the URL. The * driver, URL, username, host, and password are then * passed to the showFruitTable method. */ public static void main(String[] args) { if (args.length < 5) { printUsage(); return; } String vendorName = args[4]; int vendor = DriverUtilities.getVendor(vendorName); if (vendor == DriverUtilities.UNKNOWN) { printUsage(); return; } String driver = DriverUtilities.getDriver(vendor); String host = args[0]; String dbName = args[1]; String url = DriverUtilities.makeURL(host, dbName, vendor); String username = args[2]; String password = args[3]; showFruitTable(driver, url, username, password); } /** Get the table and print all the values. */ public static void showFruitTable(String driver, String url, String username, String password) { try { // Load database driver if not already loaded Class.forName(driver); // Establish network connection to database Connection connection = DriverManager.getConnection(url, username, password); // Look up info about the database as a whole. DatabaseMetaData dbMetaData = connection.getMetaData(); String productName = dbMetaData.getDatabaseProductName(); System.out.println("Database: " + productName); String productVersion = dbMetaData.getDatabaseProductVersion(); System.out.println("Version: " + productVersion + "n"); System.out.println("Comparing Apples and Orangesn" + "============================"); Statement statement = connection.createStatement(); String query = "SELECT * FROM fruits"; // Send query to database and store results ResultSet resultSet = statement.executeQuery(query); // Look up information about a particular table ResultSetMetaData resultsMetaData = resultSet.getMetaData(); int columnCount = resultsMetaData.getColumnCount(); // Column index starts at 1 (ala SQL) not 0 (ala Java). for(int i=1; i<columnCount+1; i++) { System.out.print(resultsMetaData.getColumnName(i) + " "); } System.out.println(); // Print results while(resultSet.next()) { // Quarter System.out.print(" " + resultSet.getInt(1)); // Num Apples System.out.print(" " + resultSet.getInt(2)); // Apple Sales System.out.print(" $" + resultSet.getFloat(3)); // Num Oranges System.out.print(" " + resultSet.getInt(4)); // Orange Sales System.out.print(" $" + resultSet.getFloat(5)); // Top Salesman System.out.println(" " + resultSet.getString(6)); } } catch(ClassNotFoundException cnfe) { System.err.println("Error loading driver: " + cnfe); } catch(SQLException sqle) { System.err.println("Error connecting: " + sqle); } } private static void printUsage() { System.out.println("Usage: FruitTest host dbName " + "username password oracle|sybase."); } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10200
Categories:Programming Code Examples, Java/J2EE/J2ME, JDBC
Tags:Java/J2EE/J2MEJDBC
Post Data:2017-01-02 16:04:23

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

StringBean.java Bean used to demonstrate jsp:useBean, etc. Remember to install it in the WEB-INF/classes/cwp directory. #Programming Code Examples #Java/J2EE/J2ME #JSP

StringBean.java  Bean used to demonstrate jsp:useBean, etc. Remember to install it in the WEB-INF/classes/cwp directory. 

package cwp;

/** A simple bean that has a single String property
 *  called message.
 *  <P>
 *  Taken from Core Web Programming Java 2 Edition
 *  from Prentice Hall and Sun Microsystems Press,
 *  .
 *  May be freely used or adapted.
 */

public class StringBean {
  private String message = "No message specified";

  public String getMessage() {
    return(message);
  }

  public void setMessage(String message) {
    this.message = message;
  }
}

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10262
Categories:Programming Code Examples, Java/J2EE/J2ME, JSP
Tags:Java/J2EE/J2MEJSP
Post Data:2017-01-02 16:04:28

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

PluginApplet.jsp Page that demonstrates the use of jsp:plugin. #Programming Code Examples #Java/J2EE/J2ME #JSP

PluginApplet.jsp  Page that demonstrates the use of jsp:plugin. Requires you to compile and install PluginApplet.java, TextPanel.java, DrawingPanel.java, and WindowUtilities.java  Since these are classes sent to the client to used by applets, the .class files should be in the same directory as the JSP page, not in the WEB-INF/classes directory where classes the server uses go. Uses the JSP-Styles  style sheet. Warning: Allaire JRun 3.0 SP2 does not properly support jsp:plugin.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- 
Example of using jsp:plugin for an applet that uses Java 2. 

Taken from Core Web Programming Java 2 Edition
from Prentice Hall and Sun Microsystems Press,
.
May be freely used or adapted.
-->
<HTML>
<HEAD>
<TITLE>Using jsp:plugin</TITLE>
<LINK REL=STYLESHEET
      HREF="JSP-Styles.css"
      TYPE="text/css">
</HEAD>

<BODY>

<TABLE BORDER=5 ALIGN="CENTER">
  <TR><TH CLASS="TITLE">
      Using jsp:plugin</TABLE>
<P>
<CENTER>
<jsp:plugin type="applet" 
            code="PluginApplet.class"
            width="370" height="420">
</jsp:plugin>
</CENTER>

</BODY>
</HTML>

PluginApplet.java

import javax.swing.*;

/** An applet that uses Swing and Java 2D and thus requires
 *  the Java Plug-In.
 *  <P>
 *  Taken from Core Web Programming Java 2 Edition
 *  from Prentice Hall and Sun Microsystems Press,
 *  .
 *  May be freely used or adapted.
 */

public class PluginApplet extends JApplet {
  public void init() {
    WindowUtilities.setNativeLookAndFeel();
    setContentPane(new TextPanel());
  }
}


TextPanel.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/** JPanel that places a panel with text drawn at various angles
 *  in the top part of the window and a JComboBox containing
 *  font choices in the bottom part.
 *  <P>
 *  Taken from Core Web Programming Java 2 Edition
 *  from Prentice Hall and Sun Microsystems Press,
 *  .
 *  May be freely used or adapted.
 */

public class TextPanel extends JPanel
                       implements ActionListener {
  private JComboBox fontBox;
  private DrawingPanel drawingPanel;

  public TextPanel() {
    GraphicsEnvironment env =
      GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontNames = env.getAvailableFontFamilyNames();
    fontBox = new JComboBox(fontNames);
    setLayout(new BorderLayout());
    JPanel fontPanel = new JPanel();
    fontPanel.add(new JLabel("Font:"));
    fontPanel.add(fontBox);
    JButton drawButton = new JButton("Draw");
    drawButton.addActionListener(this);
    fontPanel.add(drawButton);
    add(fontPanel, BorderLayout.SOUTH);
    drawingPanel = new DrawingPanel();
    fontBox.setSelectedItem("Serif");
    drawingPanel.setFontName("Serif");
    add(drawingPanel, BorderLayout.CENTER);
  }

  public void actionPerformed(ActionEvent e) {
    drawingPanel.setFontName((String)fontBox.getSelectedItem());
    drawingPanel.repaint();
  }
}


DrawingPanel.java
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

/** A window with text drawn at an angle. The font is
 *  set by means of the setFontName method.
 *  <P>
 *  Taken from Core Web Programming Java 2 Edition
 *  from Prentice Hall and Sun Microsystems Press,
 *  .
 *  May be freely used or adapted.
 */

class DrawingPanel extends JPanel {
  private Ellipse2D.Double circle =
    new Ellipse2D.Double(10, 10, 350, 350);
  private GradientPaint gradient =
    new GradientPaint(0, 0, Color.red, 180, 180, Color.yellow,
                      true); // true means to repeat pattern
  private Color[] colors = { Color.white, Color.black };

  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D)g;
    g2d.setPaint(gradient);
    g2d.fill(circle);
    g2d.translate(185, 185);
    for (int i=0; i<16; i++) {
      g2d.rotate(Math.PI/8.0);
      g2d.setPaint(colors[i%2]);
      g2d.drawString("jsp:plugin", 0, 0);
    }
  }

  public void setFontName(String fontName) {
    setFont(new Font(fontName, Font.BOLD, 35));
  }
}


WindowUtilities.java

import javax.swing.*;
import java.awt.*;

/** A few utilities that simplify using windows in Swing.
 *  <P>
 *  Taken from Core Web Programming Java 2 Edition
 *  from Prentice Hall and Sun Microsystems Press,
 *  .
 *  May be freely used or adapted.
 */

public class WindowUtilities {

  /** Tell system to use native look and feel, as in previous
   *  releases. Metal (Java) LAF is the default otherwise.
   */

  public static void setNativeLookAndFeel() {
    try {
      UIManager.setLookAndFeel
        (UIManager.getSystemLookAndFeelClassName());
    } catch(Exception e) {
      System.out.println("Error setting native LAF: " + e);
    }
  }

  public static void setJavaLookAndFeel() {
    try {
      UIManager.setLookAndFeel
        (UIManager.getCrossPlatformLookAndFeelClassName());
    } catch(Exception e) {
      System.out.println("Error setting Java LAF: " + e);
    }
  }

  public static void setMotifLookAndFeel() {
    try {
      UIManager.setLookAndFeel
        ("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
    } catch(Exception e) {
      System.out.println("Error setting Motif LAF: " + e);
    }
  }

  /** A simplified way to see a JPanel or other Container.
   *  Pops up a JFrame with specified Container
   *  as the content pane.
   */

  public static JFrame openInJFrame(Container content,
                                    int width,
                                    int height,
                                    String title,
                                    Color bgColor) {
    JFrame frame = new JFrame(title);
    frame.setBackground(bgColor);
    content.setBackground(bgColor);
    frame.setSize(width, height);
    frame.setContentPane(content);
    frame.addWindowListener(new ExitListener());
    frame.setVisible(true);
    return(frame);
  }

  /** Uses Color.white as the background color. */

  public static JFrame openInJFrame(Container content,
                                    int width,
                                    int height,
                                    String title) {
    return(openInJFrame(content, width, height, title, Color.white));
  }

  /** Uses Color.white as the background color, and the
   *  name of the Container's class as the JFrame title.
   */

  public static JFrame openInJFrame(Container content,
                                    int width,
                                    int height) {
    return(openInJFrame(content, width, height,
                        content.getClass().getName(),
                        Color.white));
  }
}



Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10261
Categories:Programming Code Examples, Java/J2EE/J2ME, JSP
Tags:Java/J2EE/J2MEJSP
Post Data:2017-01-02 16:04:28

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Excel.jsp Page that demonstrates the use of JSP to build Excel spreadsheets #Programming Code Examples #Java/J2EE/J2ME #JSP

Excel.jsp  Page that demonstrates the use of JSP to build Excel spreadsheets

First	Last	Email Address
Marty	Hall	hall@corewebprogramming.com
Larry	Brown	brown@corewebprogramming.com
Bill	Gates	gates@sun.com
Larry	Ellison	ellison@microsoft.com
<%@ page contentType="application/vnd.ms-excel" %>
<%-- There are tabs, not spaces, between columns. --%>	

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10259
Categories:Programming Code Examples, Java/J2EE/J2ME, JSP
Tags:Java/J2EE/J2MEJSP
Post Data:2017-01-02 16:04:28

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

ImportAttribute.jsp Page that demonstrates the import attribute of the page directive. Uses the ServletUtilities class #Programming Code Examples #Java/J2EE/J2ME #JSP

ImportAttribute.jsp  Page that demonstrates the import attribute of the page directive. Uses the ServletUtilities class (Check Servlet Section)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- 
Example of the import attribute of the page directive. 
   
Taken from Core Web Programming Java 2 Edition
from Prentice Hall and Sun Microsystems Press,
.
May be freely used or adapted.
-->
<HTML>
<HEAD>
<TITLE>The import Attribute</TITLE>
<LINK REL=STYLESHEET
      HREF="JSP-Styles.css"
      TYPE="text/css">
</HEAD>

<BODY>
<H2>The import Attribute</H2>
<%-- JSP page directive --%>
<%@ page import="java.util.*,cwp.*" %>

<%-- JSP Declaration --%>
<%!
private String randomID() {
  int num = (int)(Math.random()*10000000.0);
  return("id" + num);
}

private final String NO_VALUE = "<I>No Value</I>";
%>

<%-- JSP Scriptlet --%>
<%
Cookie[] cookies = request.getCookies();
String oldID = 
  ServletUtilities.getCookieValue(cookies, "userID", NO_VALUE);
if (oldID.equals(NO_VALUE)) {
  String newID = randomID();
  Cookie cookie = new Cookie("userID", newID);
  response.addCookie(cookie);
}
%>

<%-- JSP Expressions --%>
This page was accessed on <%= new Date() %> with a userID
cookie of <%= oldID %>.

</BODY>
</HTML>

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10258
Categories:Programming Code Examples, Java/J2EE/J2ME, JSP
Tags:Java/J2EE/J2MEJSP
Post Data:2017-01-02 16:04:28

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

AccessCounts.jsp Page that demonstrates JSP declarations. #Programming Code Examples #Java/J2EE/J2ME #JSP

AccessCounts.jsp  Page that demonstrates JSP declarations.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--   
Taken from Core Web Programming Java 2 Edition
from Prentice Hall and Sun Microsystems Press,
.
May be freely used or adapted.
-->
<HTML>
<HEAD>
<TITLE>JSP Declarations</TITLE>
<META NAME="keywords"
      CONTENT="JSP,declarations,JavaServer,Pages,servlets">
<META NAME="description"
      CONTENT="A quick example of JSP declarations.">
<LINK REL=STYLESHEET
      HREF="JSP-Styles.css"
      TYPE="text/css">
</HEAD>

<BODY>
<H1>JSP Declarations</H1>

<%! private int accessCount = 0; %>
<H2>Accesses to page since server reboot: 
<%= ++accessCount %></H2>

</BODY>
</HTML>

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10257
Categories:Programming Code Examples, Java/J2EE/J2ME, JSP
Tags:Java/J2EE/J2MEJSP
Post Data:2017-01-02 16:04:28

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada