<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8882010943472432760</id><updated>2012-02-16T19:39:11.919-08:00</updated><category term='java tutorial beginner newbie noob'/><title type='text'>Learning Java</title><subtitle type='html'>How easy is it to learn Java?  I have been using Microsoft languages since Basic A was around in 1982.  So how easy will it be for me to jump ship.  There is an abundance of teaching material out there, but will it make sense to a total newcomer like me?  This blog is intended to answer that question.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default?start-index=101&amp;max-results=100'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>151</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-742743949080348941</id><published>2011-12-07T07:43:00.000-08:00</published><updated>2011-12-07T07:49:00.705-08:00</updated><title type='text'>HTML &lt;div&gt; tag revisited</title><content type='html'>I was abruptly forced to revisit this topic when I discovered that my &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;  tag laid out login page, which seemed to look so great in Windows Internet  Explorer (see below), looked absolutely crap in Firefox (see further below). &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-d9eSTp74L0c/Tt-KiJGck_I/AAAAAAAAAPk/pDfPbEpVnbk/s1600/Fig1.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 280px; height: 320px;" src="http://2.bp.blogspot.com/-d9eSTp74L0c/Tt-KiJGck_I/AAAAAAAAAPk/pDfPbEpVnbk/s320/Fig1.png" alt="" id="BLOGGER_PHOTO_ID_5683413573927998450" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-jsVjior3N38/Tt-KiQb41ZI/AAAAAAAAAPs/_KU8bPiIR1U/s1600/Fig2.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 235px; height: 320px;" src="http://3.bp.blogspot.com/-jsVjior3N38/Tt-KiQb41ZI/AAAAAAAAAPs/_KU8bPiIR1U/s320/Fig2.png" alt="" id="BLOGGER_PHOTO_ID_5683413575896978834" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;So I did some reading, and the theme seemed to be that tables were never  intended to do layout.  Well I reckon there should be a counter argument,  that the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag was never intended to present data.&lt;/p&gt; &lt;p&gt;It seems to me that much of the orthodoxy around HTML is written by graphic  artists or publishers, and most of the web sites purported to show the power of &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tags and CSS, are littered with graphic art and fancy  fonts.&lt;/p&gt; &lt;p&gt;For anyone used to programming, meshing &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tags and CSS  is not technically difficult, but perhaps it is not second nature to graphic  artists and literary publishers.  The instructions emphasize the importance  of closing tags, and they suggest using borders during the design phase to get a  visual aid on the layout of the divisions.&lt;/p&gt; &lt;p&gt;So I tried that.  I show below the HTML for the beginning of a login  page:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id="container"&amp;gt;&lt;br /&gt;&amp;lt;div id="pageHeader"&amp;gt;&lt;br /&gt;&amp;lt;h1&amp;gt;&amp;lt;span&amp;gt;Rasch-ItemBank&amp;lt;/span&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;h3&amp;gt;&amp;lt;span&amp;gt;A &amp;lt;a class="top" href="http://www.interactived.com/softway.htm"&amp;gt;&lt;br /&gt;Softway&amp;lt;/a&amp;gt; Open Source Project &amp;lt;br&amp;gt;&lt;br /&gt;Hosted by &amp;lt;a class="top" href="http://java.net/projects"&amp;gt;Java.net&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;!-- end of "pageHeader" --&amp;gt;&lt;br /&gt;&amp;lt;div id="pageBody"&amp;gt;&lt;br /&gt;&amp;lt;h3&amp;gt;&amp;lt;span&amp;gt;&amp;lt;h3&amp;gt;Initial Login Screen&amp;lt;/h3&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;div id="cellA1"&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;&amp;lt;span&amp;gt;Please select user or administrator&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;!-- end of "cellA1" --&amp;gt;&lt;br /&gt;&amp;lt;div id="cellB1"&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;&amp;lt;span&amp;gt;&amp;lt;select name="usertype" class=cbox&amp;gt;&lt;br /&gt;&amp;lt;option value="user"&amp;gt;Student User&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;option value="admin"&amp;gt;Administrator&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;/select&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;!-- end of "cellB1" --&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;!-- end of "pageBody" --&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;!-- end of "container" --&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And below is the CSS to go with it:&lt;/p&gt; &lt;p&gt;&lt;code&gt;#container {&lt;br /&gt;padding: 0 25px 0 120px;&lt;br /&gt;margin: 0;&lt;br /&gt;position: relative;&lt;br /&gt;border: 1px dotted red;&lt;br /&gt;}&lt;br /&gt;#pageHeader {&lt;br /&gt;margin: 5px;&lt;br /&gt;border: 1px dotted orange;&lt;br /&gt;}&lt;br /&gt;#pageBody {&lt;br /&gt;margin: 5px;&lt;br /&gt;border: 1px dotted green;&lt;br /&gt;}&lt;br /&gt;#cellA1 {&lt;br /&gt;margin: 2px;&lt;br /&gt;height: 35px;&lt;br /&gt;float: left;&lt;br /&gt;border: 1px dotted fuchsia;&lt;br /&gt;}&lt;br /&gt;#cellB1 {&lt;br /&gt;margin: 2px;&lt;br /&gt;height: 35px;&lt;br /&gt;float: left;&lt;br /&gt;border: 1px dotted fuchsia;&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I put little margins around each "division", and I made the borders different  colors for clarity.  Having rainbows on my mind, I followed a rainbow  sequence: Richard of .. gave .. vain.  I show below how it came out:&lt;/p&gt; &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-SmW-C-zPWEo/Tt-KiXV77DI/AAAAAAAAAP4/DVEXidUiw8o/s1600/Fig3.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 258px;" src="http://2.bp.blogspot.com/-SmW-C-zPWEo/Tt-KiXV77DI/AAAAAAAAAP4/DVEXidUiw8o/s320/Fig3.JPG" alt="" id="BLOGGER_PHOTO_ID_5683413577751063602" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Notice how the red border, which is supposed to embrace everything, stops  short, and leaves off two divisions.  And the green border, which was  created to embrace the "table" and its heading, wraps itself around the heading  only.&lt;/p&gt; &lt;p&gt;After many hours of fiddling, I noticed that the "divisions" behave better if  they contain background images, but it strikes me that padding out divisions  with background images to make them behave predictably, is conceptually not far  removed from padding out real tables with spacer gifs.&lt;/p&gt; &lt;p&gt;So I shall put my login form, and all other forms back into tables.  I  may use CSS to format the tables, and I may use divisions in pages and areas of  pages devoted to text and graphics.  But my data and forms will be laid out in the  traditional manner, using tables.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-742743949080348941?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/742743949080348941/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=742743949080348941' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/742743949080348941'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/742743949080348941'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/12/html-tag-revisited.html' title='HTML &amp;lt;div&amp;gt; tag revisited'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-d9eSTp74L0c/Tt-KiJGck_I/AAAAAAAAAPk/pDfPbEpVnbk/s72-c/Fig1.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-8304456634450510413</id><published>2011-11-21T20:52:00.000-08:00</published><updated>2011-11-21T21:22:37.717-08:00</updated><title type='text'>Bringing a Custom Swing Component to Life</title><content type='html'>&lt;p&gt;I am sometimes down on the Java documentation, but in the sand plains of  lugubrious and often confusing material there is the occasional gem.  One  example is a lesson from &lt;a href="http://download.oracle.com/javase/tutorial/index.html"&gt;The Java  Tutorial&lt;/a&gt; entitled &lt;a href="http://download.oracle.com/javase/tutorial/uiswing/painting/index.html"&gt; Performing Custom Painting&lt;/a&gt;.  I was directed to it by a reply to &lt;a href="https://forums.oracle.com/forums/thread.jspa?messageID=9980569#9980569"&gt; this thread&lt;/a&gt; in the &lt;a href="https://forums.oracle.com/forums/category.jspa?categoryID=289"&gt;Oracle  Java Desktop forum&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;When I first began my efforts to create a rainbow colored Gaussian  distribution curve I began with one of the &lt;a href="http://download.oracle.com/javase/tutorial/index.html"&gt;Tutorial&lt;/a&gt;  lessons on colors.  I have unfortunately lost the URL for the lesson but  the code began something like this:&lt;/p&gt; &lt;p&gt;&lt;code&gt;import java.awt.Color;&lt;br /&gt;import java.awt.Graphics;&lt;br /&gt;import java.awt.Graphics2D;&lt;br /&gt;&lt;br /&gt;import javax.swing.JFrame;&lt;br /&gt;import javax.swing.JPanel;&lt;br /&gt;&lt;br /&gt;public class Colors extends JPanel {&lt;br /&gt;&lt;br /&gt;public void paintComponent(Graphics g) {&lt;br /&gt;super.paintComponent(g);&lt;br /&gt;&lt;br /&gt;Graphics2D g2d = (Graphics2D) g;&lt;br /&gt;&lt;br /&gt;g2d.setColor(new Color(255, 0, 0));//vivid red&lt;br /&gt;g2d.fillRect(10, 15, 90, 60);&lt;/code&gt;&lt;/p&gt; &lt;p&gt;&lt;code&gt;...&lt;/code&gt;&lt;/p&gt; &lt;p&gt;&lt;code&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;JFrame frame = new JFrame("Colors");&lt;br /&gt;frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;frame.add(new Colors());&lt;br /&gt;frame.setSize(360, 300);&lt;br /&gt;frame.setLocationRelativeTo(null);&lt;br /&gt;frame.setVisible(true);&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;It looked as shown below.&lt;/p&gt; &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-KrpGjc9ZzhE/TssrFAVcErI/AAAAAAAAAOE/FWV6dezmj6k/s1600/fig2.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 267px;" src="http://2.bp.blogspot.com/-KrpGjc9ZzhE/TssrFAVcErI/AAAAAAAAAOE/FWV6dezmj6k/s320/fig2.JPG" alt="" id="BLOGGER_PHOTO_ID_5677679120219902642" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I modified this by putting the rectangles side by side and end on to produce  a crude histogram as shown below:&lt;/p&gt;&lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-XhivH9vYM8M/TssrFGyz3GI/AAAAAAAAAOM/fzTBDYm654U/s1600/fig3.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 150px; height: 120px;" src="http://1.bp.blogspot.com/-XhivH9vYM8M/TssrFGyz3GI/AAAAAAAAAOM/fzTBDYm654U/s320/fig3.JPG" alt="" id="BLOGGER_PHOTO_ID_5677679121953709154" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;I reduced the width of the rectangles (to one pixel) and their number (to  800), and made their height and color the subject of mathematical functions.   The colors were produced by three out of phase sine waves.  That idea from  that came from &lt;a href="http://www.krazydad.com/makecolors.php"&gt;this&lt;/a&gt; article by  Jim Bumgardner.  His explanation is very thorough, so I shall not repeat it  here, but in recognition of the idea, my first rainbow colored curve was a sine  wave, as shown below:&lt;/p&gt; &lt;p&gt;&lt;a href="http://4.bp.blogspot.com/-tSJEB_Trsms/TssrFiaIw_I/AAAAAAAAAOk/GCBJRvd_Ogw/s1600/sine.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 132px;" src="http://4.bp.blogspot.com/-tSJEB_Trsms/TssrFiaIw_I/AAAAAAAAAOk/GCBJRvd_Ogw/s320/sine.JPG" alt="" id="BLOGGER_PHOTO_ID_5677679129366414322" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The mathematical function for a sine wave in Java is really simple:&lt;/p&gt; &lt;p&gt;&lt;code&gt;y = Math.sin(x);&lt;/code&gt;&lt;/p&gt; &lt;p&gt;There is, alas, no inbuilt function for a Normal/Gaussian distribution curve,  but &lt;a href="http://en.wikipedia.org/wiki/Normal_distribution"&gt;Wikipedia&lt;/a&gt;  gives the function as:&lt;/p&gt; &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-CP2BHrXWfNs/TsssMq1hNBI/AAAAAAAAAPY/-EOmdXYB3NI/s1600/normdist.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 45px;" src="http://1.bp.blogspot.com/-CP2BHrXWfNs/TsssMq1hNBI/AAAAAAAAAPY/-EOmdXYB3NI/s320/normdist.png" alt="" id="BLOGGER_PHOTO_ID_5677680351399457810" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I used the middle part of this expression to produce the rainbow colored  Gaussian distribution curve shown at the bottom of my &lt;a href="http://jhippjava.blogspot.com/2011/11/creating-custom-swing-component.html"&gt; previous post&lt;/a&gt;.  But as I said there, it did nothing.  I could not  send messages to it or make it change.&lt;/p&gt; &lt;p&gt;I will admit that when I first read the reply to &lt;a href="https://forums.oracle.com/forums/thread.jspa?messageID=9980569#9980569"&gt; my forum post&lt;/a&gt; recommending the &lt;a href="http://download.oracle.com/javase/tutorial/uiswing/painting/index.html"&gt; Custom Painting&lt;/a&gt; tutorial, I was not that optimistic, and I didn't look at it  properly until after I had tried all the articles described in my &lt;a href="http://jhippjava.blogspot.com/2011/11/creating-custom-swing-component.html"&gt; previous blog post&lt;/a&gt;.  But my cynicism was misplaced, and I should have  started there.&lt;/p&gt; &lt;p&gt;The essential code construction from the  &lt;a href="http://download.oracle.com/javase/tutorial/uiswing/painting/index.html"&gt;tutorial&lt;/a&gt; begins as follows:&lt;/p&gt; &lt;p&gt;&lt;code&gt;import javax.swing.SwingUtilities;&lt;br /&gt;import javax.swing.JFrame;&lt;br /&gt;&lt;br /&gt;public class SwingPaintDemo1 {&lt;br /&gt;&lt;br /&gt;public static void main(String[] args) {&lt;br /&gt;SwingUtilities.invokeLater(new Runnable() {&lt;br /&gt;public void run() {&lt;br /&gt;createAndShowGUI();&lt;br /&gt;}&lt;br /&gt;});&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private static void createAndShowGUI() {&lt;br /&gt;System.out.println("Created GUI on EDT? "+&lt;br /&gt;SwingUtilities.isEventDispatchThread());&lt;br /&gt;JFrame f = new JFrame("Swing Paint Demo");&lt;br /&gt;f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;f.setSize(250,250);&lt;br /&gt;f.setVisible(true);&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And the first essential point to note is that it uses:&lt;/p&gt; &lt;p&gt; &lt;cite&gt;The &lt;code&gt;SwingUtilities&lt;/code&gt; helper class to construct this GUI on the  Event Dispatch Thread.&lt;/cite&gt; &lt;/p&gt; &lt;p&gt;I don't fully understand this, but I've been told to do it before, and it was  only when I used this structure for my "custom swing component" that I could get  it to work properly.&lt;/p&gt; &lt;p&gt;The second slightly strange thing that the &lt;a href="http://download.oracle.com/javase/tutorial/uiswing/painting/index.html"&gt;tutorial&lt;/a&gt;  did was to create its own "custom" JPanel:&lt;/p&gt; &lt;p&gt;&lt;code&gt;class MyPanel extends JPanel {&lt;br /&gt;&lt;br /&gt;public MyPanel() {&lt;br /&gt;setBorder(BorderFactory.createLineBorder(Color.black));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public Dimension getPreferredSize() {&lt;br /&gt;return new Dimension(250,200);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paintComponent(Graphics g) {&lt;br /&gt;super.paintComponent(g);&lt;br /&gt;&lt;br /&gt;// Draw Text&lt;br /&gt;g.drawString("This is my custom Panel!",10,20);&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This was all in the same source file, which was modified by replacing:&lt;/p&gt; &lt;p&gt;&lt;code&gt;f.setSize(250,250);&lt;/code&gt;&lt;/p&gt; &lt;p&gt;with&lt;/p&gt; &lt;p&gt;&lt;code&gt;f.add(new MyPanel());&lt;br /&gt;f.pack();&lt;/code&gt;&lt;/p&gt; &lt;p&gt;It looks trivial, but by following this structure, I was able to use the &lt;code&gt;.pack()&lt;/code&gt; command in &lt;a href="http://www.interactived.com/JMTalpha/JMTalpha.htm"&gt;my applet&lt;/a&gt;.   Using my original code construction (as shown above), the first time I inserted  the new component, I thought it hadn't worked at all because it did not show,  and it was only after adding padding to the gridbaglayout and manually resizing  the &lt;a href="http://www.interactived.com/JMTalpha/JMTalpha.htm"&gt;applet&lt;/a&gt; that I could see it.&lt;/p&gt; &lt;p&gt;Another point worth noting is the line which inherits functionality from the  parent component.  This is described in the &lt;a href="http://download.oracle.com/javase/tutorial/uiswing/painting/index.html"&gt;tutorial&lt;/a&gt;  as follows:&lt;/p&gt; &lt;p&gt; &lt;cite&gt;Most of the standard Swing components have their look and feel implemented by  separate "UI Delegate" objects. The invocation of &lt;code&gt;super.paintComponent(g)&lt;/code&gt;  passes the graphics context off to the component's UI delegate, which paints the  panel's background.&lt;/cite&gt; &lt;/p&gt; &lt;p&gt;This avoided me having to mimic the code structure of the standard swing  components.   I could focus on the code that made my component  different.&lt;/p&gt; &lt;p&gt;The third thing that the &lt;a href="http://download.oracle.com/javase/tutorial/uiswing/painting/index.html"&gt;tutorial&lt;/a&gt;  did was to create a "sprite" and code to move it around.  My "sprite" is my  rainbow colored histogram, and I didn't need "event" code to drag it around the  page.  But I did need code to alter one or more of the parameters used to  build the histogram.  The code used by the &lt;a href="http://download.oracle.com/javase/tutorial/uiswing/painting/index.html"&gt;tutorial&lt;/a&gt;  was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;... previous imports&lt;br /&gt;import java.awt.event.MouseEvent;&lt;br /&gt;import java.awt.event.MouseListener;&lt;br /&gt;import java.awt.event.MouseAdapter;&lt;br /&gt;import java.awt.event.MouseMotionListener;&lt;br /&gt;import java.awt.event.MouseMotionAdapter;&lt;br /&gt;&lt;br /&gt;... previous unchanged code&lt;br /&gt;&lt;br /&gt;public MyPanel() {&lt;br /&gt;&lt;br /&gt;setBorder(BorderFactory.createLineBorder(Color.black));&lt;br /&gt;&lt;br /&gt;addMouseListener(new MouseAdapter() {&lt;br /&gt;public void mousePressed(MouseEvent e) {&lt;br /&gt;moveSquare(e.getX(),e.getY());&lt;br /&gt;}&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;addMouseMotionListener(new MouseAdapter() {&lt;br /&gt;public void mouseDragged(MouseEvent e) {&lt;br /&gt;moveSquare(e.getX(),e.getY());&lt;br /&gt;}&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void moveSquare(int x, int y) {&lt;br /&gt;int OFFSET = 1;&lt;br /&gt;if ((squareX!=x) || (squareY!=y)) {&lt;br /&gt;repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET);&lt;br /&gt;squareX=x;&lt;br /&gt;squareY=y;&lt;br /&gt;repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public Dimension getPreferredSize() {&lt;br /&gt;return new Dimension(250,200);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void paintComponent(Graphics g) {&lt;br /&gt;super.paintComponent(g);&lt;br /&gt;g.drawString("This is my custom Panel!",10,20);&lt;br /&gt;g.setColor(Color.RED);&lt;br /&gt;g.fillRect(squareX,squareY,squareW,squareH);&lt;br /&gt;g.setColor(Color.BLACK);&lt;br /&gt;g.drawRect(squareX,squareY,squareW,squareH);&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The fourth slightly strange thing that the &lt;a href="http://download.oracle.com/javase/tutorial/uiswing/painting/index.html"&gt;tutorial&lt;/a&gt;  did was to put the "sprite" is its own class:&lt;/p&gt; &lt;p&gt;&lt;code&gt;class RedSquare{&lt;br /&gt;&lt;br /&gt;private int xPos = 50;&lt;br /&gt;private int yPos = 50;&lt;br /&gt;private int width = 20;&lt;br /&gt;private int height = 20;&lt;br /&gt;&lt;br /&gt;public void setX(int xPos){&lt;br /&gt;this.xPos = xPos;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public int getX(){&lt;br /&gt;return xPos;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;... more set/get functions&lt;br /&gt;&lt;br /&gt;public void paintSquare(Graphics g){&lt;br /&gt;g.setColor(Color.RED);&lt;br /&gt;g.fillRect(xPos,yPos,width,height);&lt;br /&gt;g.setColor(Color.BLACK);&lt;br /&gt;g.drawRect(xPos,yPos,width,height);&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I'm not sure whether this was strictly necessary, but I followed the same  structure, putting my histogram into the &lt;code&gt;paintSquare(Graphics g)&lt;/code&gt;  method, although I called it &lt;code&gt;rainbowHist(Graphics g).&lt;/code&gt;  I also  renamed &lt;code&gt;MyPanel()&lt;/code&gt; to &lt;code&gt;MyHist()&lt;/code&gt;. The six set/get  functions I replaced with two:&lt;/p&gt; &lt;p&gt;&lt;code&gt;public void setMaxValue(int MaxValue){&lt;br /&gt;this.MaxValue = MaxValue;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void setActValue(int ActValue){&lt;br /&gt;this.ActValue = ActValue;&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The &lt;code&gt;moveSquare(int x, int y)&lt;/code&gt; function I made as follows:&lt;/p&gt; &lt;p&gt;&lt;code&gt;public void moveSquare(int MaxValue, int ActValue){&lt;br /&gt;myHist.setMaxValue(MaxValue);&lt;br /&gt;myHist.setActValue(ActValue);&lt;br /&gt;repaint();&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I didn't need the mouse listeners, so I removed them altogether.&lt;/p&gt; &lt;p&gt;Already my custom component was beginning to look a bit like a JProgressBar,  with a &lt;code&gt;MaxValue&lt;/code&gt; and an &lt;code&gt;ActValue&lt;/code&gt;, and "progress"  indicated by the relationship between the two.  In my initial version I  made the number of columns in the histogram a linear function of &lt;code&gt;ActValue&lt;/code&gt;  as a proportion of &lt;code&gt;MaxValue&lt;/code&gt;, just like the colored bit in an  ordinary JProgressBar.&lt;/p&gt; &lt;p&gt;But I needed to revise this, because I wanted "progress" to be indicated by  the &lt;i&gt;area&lt;/i&gt; under the curve, not the distance along the &lt;code&gt;x&lt;/code&gt; axis.&lt;/p&gt; &lt;p&gt; &lt;a href="http://en.wikipedia.org/wiki/Normal_distribution"&gt;Wikipedia&lt;/a&gt;  gives the area under the curve, or "&lt;span id="Cumulative_distribution_function" class="mw-headline"&gt;Cumulative  distribution function" as:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://4.bp.blogspot.com/-0cxofz0P9r0/TsssDJFSf0I/AAAAAAAAAO0/luAIxHVLH50/s1600/cumdist.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 30px;" src="http://4.bp.blogspot.com/-0cxofz0P9r0/TsssDJFSf0I/AAAAAAAAAO0/luAIxHVLH50/s320/cumdist.png" alt="" id="BLOGGER_PHOTO_ID_5677680187719974722" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In this expression "erf" is an abbreviation for "error function", and I was  interested to read that much of the work around and even the name of the  function derives from measurement theory.  Indeed, one of the approximation  expressions is:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-qFwvOn875ko/TsssDV9qZxI/AAAAAAAAAPA/AoP5K3-vW0Q/s1600/erfapprox.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 35px;" src="http://1.bp.blogspot.com/-qFwvOn875ko/TsssDV9qZxI/AAAAAAAAAPA/AoP5K3-vW0Q/s320/erfapprox.png" alt="" id="BLOGGER_PHOTO_ID_5677680191177647890" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And this could almost have been lifted straight from the &lt;a href="http://jhippjava.blogspot.com/2009/04/georg-rasch.html"&gt;Rasch&lt;/a&gt; book.   I must say, I've never liked that expression (in fact it gives me the heebie jeebies), so I  moved straight down to the &lt;a title="Abramowitz and Stegun" href="http://www.blogger.com/wiki/Abramowitz_and_Stegun"&gt;Abramowitz  and Stegun&lt;/a&gt; approximations, and used the first, because I'm aiming for a  visual impression here, and don't need seven decimal places of accuracy:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-FostPpqGR5s/TsssDS8L8GI/AAAAAAAAAPM/2OKW2XumJo8/s1600/erfstegun.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 39px;" src="http://2.bp.blogspot.com/-FostPpqGR5s/TsssDS8L8GI/AAAAAAAAAPM/2OKW2XumJo8/s320/erfstegun.png" alt="" id="BLOGGER_PHOTO_ID_5677680190366150754" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Because we are talking about probability here, the theoretical total area  under the graph is 1.  So while in the initial version, the critical  parameter was number of columns:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;for (double i=0; i&amp;lt;ActNoofColumns; i++){&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;I now set the histogram to build completely by default:&lt;/p&gt; &lt;p&gt;&lt;code&gt;for (double i=0; i&amp;lt;MaxNoofColumns; i++){&lt;/code&gt;&lt;/p&gt; &lt;p&gt;and inserted a break to trigger when the area approximation equates to &lt;code&gt; ActValue&lt;/code&gt; as a proportion of &lt;code&gt;MaxValue&lt;/code&gt;:&lt;/p&gt; &lt;p&gt;&lt;code&gt;if (jonathan &amp;gt; ProportionofMax) break;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I used the variable &lt;code&gt;jonathan&lt;/code&gt;, because &lt;a href="http://en.wikipedia.org/wiki/Error_function"&gt;Wikipedia&lt;/a&gt; was a bit  vague about the left hand portion of the curve when the mean is zero (and &lt;code&gt; x&amp;lt;0&lt;/code&gt;).  I guess the measurement theorists who did this work didn't  care, because they were only interested in the extreme right hand end of the  curve.  &lt;a href="http://en.wikipedia.org/wiki/Error_function"&gt;Wiki&lt;/a&gt;  suggested:&lt;/p&gt; &lt;p&gt;&lt;code&gt;erf(x)=-erf(-x)&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This is correct, but I missed the leading minus sign on the right hand side  of the expression, so I did a bit of fiddling around.  Anyway, it  eventually worked.  The illustration below shows my custom component under  the JprogressBar it will replace (as well as the curve shown in full for an  instance of the component not yet callibrated).&lt;/p&gt; &lt;code&gt;&lt;code&gt;&lt;code&gt;&lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-qvZllKa_TxI/TssrFUmGM0I/AAAAAAAAAOc/QZcuW7KbYeY/s1600/fig4.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 276px;" src="http://1.bp.blogspot.com/-qvZllKa_TxI/TssrFUmGM0I/AAAAAAAAAOc/QZcuW7KbYeY/s320/fig4.JPG" alt="" id="BLOGGER_PHOTO_ID_5677679125658481474" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-8304456634450510413?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/8304456634450510413/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=8304456634450510413' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8304456634450510413'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8304456634450510413'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/11/bringing-custom-swing-component-to-life.html' title='Bringing a Custom Swing Component to Life'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-KrpGjc9ZzhE/TssrFAVcErI/AAAAAAAAAOE/FWV6dezmj6k/s72-c/fig2.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-6570345857436039127</id><published>2011-11-15T21:34:00.000-08:00</published><updated>2011-11-15T21:45:23.340-08:00</updated><title type='text'>Creating a Custom Swing Component</title><content type='html'>I always return to my blog when I'm stuck, and I'm stuck right now. &lt;p&gt;I want to create a custom Swing component. Specifically, I want something  like a &lt;code&gt;JProgressBar&lt;/code&gt;, with the following changes:&lt;/p&gt; &lt;ol&gt;&lt;li&gt;In place of a flat Foreground color, I want a rainbow spectrum, showing    only the red range for low Values, and the whole spectrum for values close to    the Maximum value;&lt;/li&gt;&lt;li&gt;Instead of a rectangular box, I want the progress "bar" to take the shape    of a normal, or Gaussian, distribution curve;&lt;/li&gt;&lt;li&gt;I want progress to be displayed by the area under the curve, rather than by a    simple linear scale along the x axis.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;It's not that there isn't stuff out there.  I have five tabs open in my  browser, specifically addressing the creation of custom components in Swing, as  well as the &lt;a href="http://hg.openjdk.java.net/jdk7/jsn/jdk/file/664def01b886/src/share/classes/javax/swing/JProgressBar.java"&gt; source code for the JProgressBar&lt;/a&gt;.  It is that, like everything to do  with Java, it is bloody difficult to read. &lt;/p&gt; &lt;p&gt;I shall begin from the horse's mouth as it were, with an article on the &lt;a href="http://www.java.net/"&gt;Java.net&lt;/a&gt; website entitled: &lt;a href="http://today.java.net/pub/a/today/2007/02/22/how-to-write-custom-swing-component.html"&gt; How to Write a Custom Swing Component&lt;/a&gt;.  It begins by defining the  "building blocks" of Swing components as:&lt;/p&gt; &lt;cite&gt;&lt;ul&gt;&lt;li&gt;The component class itself, which provides an API for creating, changing,    and querying the component basic state.&lt;/li&gt;&lt;li&gt;The model interface and the model default implementation(s) that handle    the component business logic and change notifications.&lt;/li&gt;&lt;li&gt;The UI delegate that handles component layout, event handling (mouse and    keyboard), and painting.&lt;/li&gt;&lt;/ul&gt;&lt;/cite&gt; &lt;p&gt;I understand the first four words of that lot.  I hate it when  documents, especially formal ones, use abbreviations without definitions, but a  Google search on API produces a first page full of formal Sun/Oracle documents,  which do that, even in the title.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;According to an archived (by which I  mean so old or unimportant that Oracle has not woven itself into the URL)  &lt;a href="http://java.sun.com/docs/glossary.html"&gt;glossary&lt;/a&gt;, API is defined as:&lt;/p&gt; &lt;p&gt;&lt;cite&gt;Application Programming Interface. The specification of how a programmer  writing an application accesses the behavior and state of classes and objects.&lt;/cite&gt;&lt;/p&gt; &lt;p&gt;So if you insert the full definition into the first bullet, you get:&lt;/p&gt;  &lt;ul&gt;&lt;cite&gt;   &lt;li&gt;The component class itself, which provides a specification of how a    programmer writing an application accesses the behavior and state of classes    and objects for creating, changing,    and querying the component basic state.&lt;/li&gt;&lt;/cite&gt;&lt;/ul&gt; &lt;p&gt;And that is gibberish, like so much of the material used to describe Java,  and the closer you get to "the horse" often the more confusing it gets.  To  be fair, if you insert the words behind the acronym, it looks a little better:&lt;/p&gt;  &lt;ul&gt;&lt;cite&gt;   &lt;li&gt;The component class itself, which provides an Application Programming    Interface for creating, changing,    and querying the component basic state.&lt;/li&gt;&lt;/cite&gt;&lt;/ul&gt; &lt;p&gt;But then it starts to overlap with the second "building block", which begins:&lt;/p&gt;  &lt;p&gt; &lt;cite&gt;The model interface ... &lt;/cite&gt; &lt;/p&gt;  &lt;p&gt;When I first read that, I wasn't sure whether it said model or modal.   Either way it is not clear how the &lt;cite&gt;model interface&lt;/cite&gt; differs from the &lt;cite&gt;Application Programming Interface&lt;/cite&gt;.&lt;br /&gt;&lt;/p&gt; &lt;p&gt;The third "building block" opens with:&lt;/p&gt;&lt;p&gt;&lt;cite&gt;The UI delegate ...&lt;/cite&gt;&lt;/p&gt;&lt;p&gt;I used the same &lt;a href="http://java.sun.com/docs/glossary.html"&gt;glossary&lt;/a&gt;  to look up UI, and it wasn't even in there.  A Google search on UI brings  up a slew of pages on GUI, and the weight of evidence suggests "User Interface".   So now we have &lt;cite&gt;Application Programming Interface&lt;/cite&gt;, &lt;cite&gt;model interface&lt;/cite&gt;, and a &lt;cite&gt;User Interface&lt;/cite&gt;, each purportedly in their own "building block".&lt;/p&gt;&lt;p&gt;Are we really dealing with  distinct building "building blocks" here, or a "blob" of amorphous building material with  fuzzily defined functionality zones?&lt;/p&gt; &lt;p&gt;The next title in the article, after &lt;cite&gt;Basic Building Blocks&lt;/cite&gt;, is &lt;cite&gt;The Component Class: UI Delegate Plumbing&lt;/cite&gt;, which looks to me very  like a composite of building blocks 1 and 3.  The third heading is &lt;cite&gt;The Model Interface&lt;/cite&gt;, so presumably it refers to the second building  block.  It  includes some code, with two class declarations, and it opens with:&lt;/p&gt; &lt;p&gt;&lt;cite&gt;This (sic) is ... the most important class for a custom component.&lt;/cite&gt;&lt;/p&gt; &lt;p&gt;The article continues, on and on, in a similarly confusing fashion, so I thought I'd cut  to the chase and have a look at the  &lt;a href="http://today.java.net/today/2007/02/22/flexi-slider-src.zip"&gt;source  code&lt;/a&gt; and see if I could make it work.  The code for the main class &lt;code&gt;JFlexiSlider.java&lt;/code&gt;,  begins  with:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;package org.jvnet.flamingo.slider;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;import javax.swing.*;&lt;br /&gt;&lt;br /&gt;import org.jvnet.flamingo.slider.FlexiRangeModel.Range;&lt;br /&gt;import org.jvnet.flamingo.slider.ui.BasicFlexiSliderUI;&lt;br /&gt;import org.jvnet.flamingo.slider.ui.FlexiSliderUI;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Three questions arise from this.  Is the web address given for the imported  classes in the public domain?  Are the classes listed still there?   And if so, is Java smart enough to navigate through the Internet to find them?   When I tried to compile the class.  The first of 18 errors was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;package org.jvnet.flamingo.slider.FlexiRangeModel does not exist&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Out of curiosity I typed &lt;code&gt;jvnet.org&lt;/code&gt; into my browser and it came  up blank.  I ran a &lt;code&gt;whois&lt;/code&gt; on &lt;code&gt;jvnet.org&lt;/code&gt;, and this  confirmed that the domain name is registered, and to Oracle.  So I guess  that when this code was written, all the package and import information was  meaningful, but now it certainly isn't.  And to cut a long story short, the  effort of addressing each error in turn to make the code run outweighed any  possible benefit, so I gave up.&lt;/p&gt; &lt;p&gt;My next port of call was to the &lt;a href="http://hg.openjdk.java.net/jdk7/jsn/jdk/file/664def01b886/src/share/classes/javax/swing/JProgressBar.java"&gt; source code&lt;/a&gt; of the existing JProgressBar.  One of eleven imported  classes was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;import javax.swing.plaf.ProgressBarUI;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;So I checked out the &lt;a href="http://hg.openjdk.java.net/jdk7/jsn/jdk/file/664def01b886/src/share/classes/javax/swing/plaf/ProgressBarUI.java"&gt; source code&lt;/a&gt; for this, which was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;public abstract class ProgressBarUI extends ComponentUI {&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;To do a proper job I should have downloaded the &lt;a href="http://hg.openjdk.java.net/jdk7/jsn/jdk/file/664def01b886/src/share/classes/javax/swing/plaf/ComponentUI.java"&gt; source code&lt;/a&gt; for &lt;code&gt;ComponentUI&lt;/code&gt; as well, but to honest, the whole  thing was rendered virtually unreadable by all the comments, so I reached  another boredom threshold.&lt;/p&gt; &lt;p&gt;I then went to a much more readable article entitled &lt;a href="http://chp.smartlog.dk/creating-a-custom-component-in-swing-post24028"&gt; Creating a custom component in Swing&lt;/a&gt; by a Danish gentleman called Christian  Petersen.  As my Rasch Itembank Project is inspired by the Danish  Mathematician, Georg Rasch, I was happy to be reading something by one of his countrymen.&lt;/p&gt; &lt;p&gt;There were no remote or unreachable packages in the code given with this  article (in fact there were no packages at all), and the code compiled and ran  perfectly first time.  Inspired by this success, and the simplicity of his  approach, I went right back to basics, to a lesson in &lt;a href="http://download.oracle.com/javase/tutorial/index.html"&gt;The Java  Tutorial&lt;/a&gt; entitled &lt;a href="http://download.oracle.com/javase/tutorial/uiswing/start/compile.html"&gt; Compiling and Running Swing Programs&lt;/a&gt;.  This lesson gives a link to &lt;a href="http://download.oracle.com/javase/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java"&gt; source code&lt;/a&gt; for a "program" called HelloWorldSwing.&lt;/p&gt; &lt;p&gt;HelloWorldSwing essentially displays a Swing component called JLabel, in  another component called JFrame.  I took this code and replaced the JLabel  with the class for my rainbow colored Gaussian curve as follows:&lt;/p&gt; &lt;p&gt;&lt;code&gt;import javax.swing.*;&lt;br /&gt;public class HelloWorldSwing {&lt;br /&gt;private static void createAndShowGUI() {&lt;br /&gt;//Create and set up the window.&lt;br /&gt;JFrame frame = new JFrame("HelloWorldSwing");&lt;br /&gt;frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;//Add the ubiquitous "Hello World" label.&lt;br /&gt;NormJ2 label2 = new NormJ2();&lt;br /&gt;frame.getContentPane().add(label2);&lt;br /&gt;//Display the window.&lt;br /&gt;frame.setSize(520, 300);&lt;br /&gt;frame.setVisible(true);&lt;br /&gt;}&lt;br /&gt;public static void main(String[] args) {&lt;br /&gt;//Schedule a job for the event-dispatching thread:&lt;br /&gt;//creating and showing this application's GUI.&lt;br /&gt;javax.swing.SwingUtilities.invokeLater(new Runnable() {&lt;br /&gt;public void run() {&lt;br /&gt;createAndShowGUI();&lt;br /&gt;}&lt;br /&gt;});&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;And it came up as shown below:&lt;/p&gt; &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-tA7iHspuqS0/TsNN2VnuPPI/AAAAAAAAAN0/ewXKd6KeBQo/s1600/fig1.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 185px;" src="http://1.bp.blogspot.com/-tA7iHspuqS0/TsNN2VnuPPI/AAAAAAAAAN0/ewXKd6KeBQo/s320/fig1.JPG" alt="" id="BLOGGER_PHOTO_ID_5675465551328984306" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I've left all the comments and the HelloWorldSwing heading (and even the  component name: &lt;code&gt;label2&lt;/code&gt;) to emphasize that creating a custom swing  component is really as simple as that.  You don't need packages,  collections of remote and difficult to find "ui" classes.  You just insert  one class, compiled with Swing components, into another.&lt;/p&gt; &lt;p&gt;As components go, mine is currently somewhat limited.  It looks pretty  (though I say it myself), but it does nothing else.  The purpose of all the  guff at the head of this post is to bring components alive, but there has to be  a simpler, more commonsense, way to do it.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-6570345857436039127?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/6570345857436039127/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=6570345857436039127' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6570345857436039127'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6570345857436039127'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/11/creating-custom-swing-component.html' title='Creating a Custom Swing Component'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-tA7iHspuqS0/TsNN2VnuPPI/AAAAAAAAAN0/ewXKd6KeBQo/s72-c/fig1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-8257704984875251286</id><published>2011-11-12T04:10:00.000-08:00</published><updated>2011-11-12T04:14:44.345-08:00</updated><title type='text'>Mixing and Matching</title><content type='html'>&lt;p&gt;My unfamiliarity with PHP and JavaScript is illustrated by the fact that it  has only just occurred to me that I don't have to choose between one or the  other, but can in fact enjoy both.  So for example, bringing my &lt;a href="http://jhippjava.blogspot.com/2011/10/add-user-to-database.html"&gt;Add User&lt;/a&gt;  screen into the PHP fold was simply a matter of changing the file extension and  adding:&lt;/p&gt; &lt;p&gt;&lt;code&gt;session_start();&lt;/code&gt;&lt;/p&gt; &lt;p&gt;at the top of the file.  Everything else remained the same.  All  the JavaScript remained untouched, all the business rules remained the same, and  if the business rules were satisfied, the same PHP file was called to run the  data transaction.  For display purposes the username was called, and usertype was called to ensure only administrators added to the database.&lt;br /&gt;&lt;/p&gt; &lt;p&gt;I had also been scratching my head about passing PHP variables back to the  Applet to enrich the data stored in my database, but then it finally sunk into  my head that they didn't need to be passed backwards and forwards.   Variables (such as username, and IP) gathered by PHP, could simply be stored as  session variables, while the user navigated from the login page to the Applet,  and when the Applet called a PHP script, those same variables could be called on  the page hosting the PHP script.  They could then be woven into enhanced  SQL commands on that page, without ever having been near the Applet itself.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-8257704984875251286?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/8257704984875251286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=8257704984875251286' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8257704984875251286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8257704984875251286'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/11/mixing-and-matching.html' title='Mixing and Matching'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-8467336031846759935</id><published>2011-10-29T20:56:00.001-07:00</published><updated>2011-10-29T20:56:33.835-07:00</updated><title type='text'>Security Points</title><content type='html'>&lt;p&gt;The first point, about the security of &lt;a href="http://www.interactived.com/softway.htm"&gt;my web site&lt;/a&gt;, is that &lt;a href="http://www.interactived.com/JMTalpha/JMTalpha.htm"&gt;Active Math Java&lt;/a&gt;  is a test bed for code developed for the &lt;a href="http://rasch-itembank.blogspot.com/"&gt;Rasch-ItemBank&lt;/a&gt; open source &lt;a href="http://java.net/projects/rasch-itembank/"&gt;project&lt;/a&gt;.  It is  intended as a free resource for use by any child anywhere in the world with  access to a computer connected to the Internet and running Java.&lt;/p&gt; &lt;p&gt;So the purpose of &lt;a href="http://jhippjava.blogspot.com/2011/10/creating-login-page-front-end.html"&gt; my login page&lt;/a&gt; is not to secure a web resource for which users pay money.   Nor is it like a forum, where the login page protects the forum from spammers.   It is simply there for the convenience of certain users who have requested the  ability to track the performance of their children.&lt;/p&gt; &lt;p&gt;The second point, about the security of web sites in general, is that secure  pages usually include a server side script, such as PHP, and if security is  desired, all the pages have to be in the same or compatible format.&lt;/p&gt; &lt;p&gt;Using PHP has some advantages, besides security, such as retaining variables  across pages, within sessions.&lt;/p&gt; &lt;p&gt;I have enjoyed writing business rules in JavaScript, for a &lt;a href="http://jhippjava.blogspot.com/2011/10/javascript-business-rules.html"&gt; mock login page&lt;/a&gt; and a &lt;a href="http://jhippjava.blogspot.com/2011/10/add-user-to-database.html"&gt;mock  add user page&lt;/a&gt;, because I have never liked JavaScript, and I enjoyed getting  something to work with it.  However, I am now resigned to rewriting  everything in PHP, not for security, but for the convenience of retaining and  passing variables about the place.&lt;/p&gt; &lt;p&gt;Oh boy am I glad this is a blog about learning Java and related languages and  not a formal lesson.  If it were a formal lesson, any readers might be  really pissed off by now, because I have done about 3 180 degree turns.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-8467336031846759935?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/8467336031846759935/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=8467336031846759935' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8467336031846759935'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8467336031846759935'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/10/security-points.html' title='Security Points'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-1116177063847008758</id><published>2011-10-28T23:03:00.000-07:00</published><updated>2011-10-28T23:13:03.411-07:00</updated><title type='text'>Add User to Database</title><content type='html'>Having created &lt;a href="http://jhippjava.blogspot.com/2011/10/web-site-redesign.html"&gt;an HTML  layout&lt;/a&gt; and an external CSS page, and having written &lt;a href="http://jhippjava.blogspot.com/2011/10/javascript-business-rules.html"&gt; business rules&lt;/a&gt; for a login page, creating a page with a form to add users to  the database was relatively easy. &lt;p&gt;The layout was almost identical to the login screen, except for what I call  combo boxes for the age of the student users, and to comply with convention, a  password confirmation field.  But for that convention, the business rules  could have been cut and pasted verbatim from the login page, and that would have  made the job nice and easy.&lt;/p&gt;  &lt;p&gt;Identification of users is not mission critical for me, and if teachers can't  record and type in accurately a password on the first attempt, my first instinct  was to say "who cares?".  But part of the point of this exercise is to make  my web site/application look "professional", so I put in the second field.&lt;/p&gt;  &lt;p&gt;The login rules comprised four independent conditions nested within a super  condition, triggered by any of the four being met, the alternative (or else) to  which was the calling of the database query code.  So where to put the  fifth condition, the inequality of the passwords?&lt;/p&gt; &lt;p&gt;The nest of four are together because they are not mutually exclusive.   Most often the user will click the button with nothing in either field, and you  want a message to appear over both fields.  Or the name might be too long,  and the password field empty.&lt;/p&gt; &lt;p&gt;Technically the fifth condition might overlap with one or more of the other  four.  For example the password fields may be unequal and too long.   But if they are too long, and they are told to make them equal first, they will  be annoyed if they are told to shorten them after they have made them equal.   I guess if I had enough space for messages I could tell them both, but I don't.   So in my business rules they have to get the length right (between 1 and eight  characters) first, and then make the passwords match.  The rules are as  follows:&lt;/p&gt; &lt;p&gt;&lt;code&gt;function busrules(form)&lt;br /&gt;{&lt;br /&gt;var subtype = form.usertype.value;&lt;br /&gt;var subname = form.username.value;&lt;br /&gt;var subpass = form.password.value;&lt;br /&gt;var subpassc = form.passwordc.value;&lt;br /&gt;var subagey = form.ageyears.value;&lt;br /&gt;var subagem = form.agemonths.value;&lt;br /&gt;var showmessn;&lt;br /&gt;var showmessp;&lt;br /&gt;var ubercell1v = document.getElementById("ubercell1").innerHTML;&lt;br /&gt;var ubercell2v = document.getElementById("ubercell2").innerHTML;&lt;br /&gt;var myarg;&lt;br /&gt;if (ubercell1v.length &amp;gt; 0)&lt;br /&gt;{&lt;br /&gt;document.getElementById("ubercell1").innerHTML="";&lt;br /&gt;} //end of null check&lt;br /&gt;if (ubercell2v.length &amp;gt; 0)&lt;br /&gt;{&lt;br /&gt;document.getElementById("ubercell2").innerHTML="";&lt;br /&gt;} //end of null check&lt;br /&gt;if (subname.length &amp;gt; 8 || subname.length ==0 || subpass.length ==0 ||  subpass.length ==0 )&lt;br /&gt;{&lt;br /&gt;if (subname.length &amp;gt; 8)&lt;br /&gt;{&lt;br /&gt;showmessn = "Your user name is too long. Please use 8 characters.";&lt;br /&gt;document.getElementById("ubercell1").innerHTML=showmessn;&lt;br /&gt;} //end of condition 1&lt;br /&gt;if (subname.length ==0)&lt;br /&gt;{&lt;br /&gt;showmessn = "Oh Dear! You have not entered a user name.";&lt;br /&gt;document.getElementById("ubercell1").innerHTML=showmessn;&lt;br /&gt;} //end of condition 2&lt;br /&gt;if (subpass.length &amp;gt; 8)&lt;br /&gt;{&lt;br /&gt;showmessp = "Your user password is too long. Please use 8 characters.";&lt;br /&gt;document.getElementById("ubercell2").innerHTML=showmessp;&lt;br /&gt;} //end of condition 3&lt;br /&gt;if (subpass.length ==0)&lt;br /&gt;{&lt;br /&gt;showmessp = "Oh Dear! You have not entered a user password.";&lt;br /&gt;document.getElementById("ubercell2").innerHTML=showmessp;&lt;br /&gt;} //end of condition 4&lt;br /&gt;} //end of group of 4 conditions&lt;br /&gt;else if (subpass != subpassc)&lt;br /&gt;{&lt;br /&gt;showmessp = "Oh Dear! You need to enter the same password in both password  fields.";&lt;br /&gt;document.getElementById("ubercell2").innerHTML=showmessp;&lt;br /&gt;} //end of condition 5&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Then if all those rules are satisfied, the PHP script for the data  connection is called:&lt;/p&gt; &lt;p&gt;&lt;code&gt;else { //Code below is to set up parameters for the php script&lt;br /&gt;if (window.XMLHttpRequest) //format and create request variable according to  browser type&lt;br /&gt;{// code for IE7+, Firefox, Chrome, Opera, Safari&lt;br /&gt;xmlhttp=new XMLHttpRequest();&lt;br /&gt;} //end of current option&lt;br /&gt;else&lt;br /&gt;{// code for IE6, IE5&lt;br /&gt;xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");&lt;br /&gt;} // end of old option&lt;br /&gt;xmlhttp.onreadystatechange=function()&lt;br /&gt;{ // this code displays response text&lt;br /&gt;if (xmlhttp.readyState==4 &amp;amp;&amp;amp; xmlhttp.status==200)&lt;br /&gt;{&lt;br /&gt;document.getElementById("untencell1").innerHTML=xmlhttp.responseText;&lt;br /&gt;}&lt;br /&gt;} //the code below calls the php script on the server&lt;br /&gt;myarg = "('"+subname+"','"+subpass+"','"+subtype+"',"+subagey+","+subagem+")"&lt;br /&gt;xmlhttp.open("POST","adduser.php?myarg="+myarg,true);&lt;br /&gt;xmlhttp.send();&lt;br /&gt;} //end of master conditional statement&lt;br /&gt;} //end of function&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I took the opportunity to tidy up the layout a bit.  The "row" divisions  I had set up (following the structure of a table) seemed a bit redundant, so I  lost them, and I defined the warning divisions more concisely, to stop the form  jumping about, when the warnings come up.  And I made everything a bit  wider:&lt;/p&gt; &lt;p&gt;&lt;code&gt;.inputtable {margin:50; background-color:#BDEDFF}&lt;br /&gt;.row {width:520;}&lt;br /&gt;.col1 {text-align:right; float:left; width:300; height:25; margin:0 5 0 5;}&lt;br /&gt;.col2 {text-align:left; float:right; width:200; margin:0 5 0 5;}&lt;br /&gt;.itext {width:150;}&lt;br /&gt;.cbox {width:150; margin-left:5;}&lt;br /&gt;.warning {color="red";margin-bottom:0;margin-top:0;float:left; width:520; }&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The PHP script was similar in structure to the login script, but differed in  important details (such as running an INSERT command rather than a SELECT  query):&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;include('newinfo.php');// collect database variables.&lt;br /&gt;$myarg = $_GET['myarg']; // collect passed variable&lt;br /&gt;// To protect MySQL injection&lt;br /&gt;$myarg = stripslashes($myarg);&lt;br /&gt;// Connect to server and select database.&lt;br /&gt;$con = mysql_connect( $dbhost, $dbuser, $dbpass );&lt;br /&gt;if (!$con)&lt;br /&gt;{&lt;br /&gt;die('Could not connect: ' . mysql_error());&lt;br /&gt;}&lt;br /&gt;mysql_select_db($dbname, $con);&lt;br /&gt;$query = "INSERT INTO $table1 (Softid, PartPass, PartType, AgeYears, AgeMonths)  VALUES ";&lt;br /&gt;$query = $query . $myarg;&lt;br /&gt;$result = mysql_query($query) or die(mysql_error() . $query );&lt;br /&gt;if($result==1){&lt;br /&gt;echo"&amp;lt;p&amp;gt;Hooray you have added a user&amp;lt;/p&amp;gt;";&lt;br /&gt;} else {&lt;br /&gt;echo"&amp;lt;p&amp;gt;Oh Dear! Something went wrong. Query: &amp;lt;br/&amp;gt;$query &amp;lt;/p&amp;gt;";&lt;br /&gt;}&lt;br /&gt;mysql_close($con);&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;If the password were unequal, but everything else correct, the screen looked  as shown below:&lt;/p&gt; &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-MomRfpeiwMU/TquX63kEGLI/AAAAAAAAANY/s0EERgbqTJQ/s1600/pic06.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 302px;" src="http://1.bp.blogspot.com/-MomRfpeiwMU/TquX63kEGLI/AAAAAAAAANY/s0EERgbqTJQ/s320/pic06.JPG" alt="" id="BLOGGER_PHOTO_ID_5668791593579321522" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And after successfully adding a user is looked as shown below:&lt;/p&gt; &lt;p&gt;&lt;a href="http://4.bp.blogspot.com/-GFqRhC16i4M/TquX7HDGgmI/AAAAAAAAANg/upzjPn1LKQc/s1600/pic05b.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 302px;" src="http://4.bp.blogspot.com/-GFqRhC16i4M/TquX7HDGgmI/AAAAAAAAANg/upzjPn1LKQc/s320/pic05b.JPG" alt="" id="BLOGGER_PHOTO_ID_5668791597736034914" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-1116177063847008758?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/1116177063847008758/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=1116177063847008758' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/1116177063847008758'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/1116177063847008758'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/10/add-user-to-database.html' title='Add User to Database'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-MomRfpeiwMU/TquX63kEGLI/AAAAAAAAANY/s0EERgbqTJQ/s72-c/pic06.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-6271697873158353179</id><published>2011-10-26T04:22:00.000-07:00</published><updated>2011-10-26T04:26:31.650-07:00</updated><title type='text'>Check Login Details against the Database</title><content type='html'>After &lt;a href="http://jhippjava.blogspot.com/2011/10/javascript-business-rules.html"&gt; rewriting my business rules in JavaScript&lt;/a&gt;, the time now really had come to  create the live database interface.  So I busily changed the file extension  back to .php and added back the &lt;code&gt;include()&lt;/code&gt; statement, and started  adding PHP code to the JavaScript function called by the button click event, and  paused when I needed to pass a javascript variable to PHP.  I had a feeling  that what I was doing would not work, and a quick Google search confirmed that  it would not. &lt;p&gt;The whole point of converting my business rules to JavaScript was to keep the  field input checking local.  But as PHP scripts run on the server, you need  to call something on the server, and pass any variables to that.&lt;/p&gt; &lt;p&gt;It was a bit frustrating because neither of the login page examples I'd found  on the web used any business rules at all; they just called a PHP script from  the form submit button, one on the same page, one on another.&lt;/p&gt; &lt;p&gt;As a first pass I tried AJAX.&lt;/p&gt; &lt;p&gt;I had sidestepped the issue in my &lt;a href="http://jhippjava.blogspot.com/2011/10/javascript-business-rules.html"&gt; business rules test page&lt;/a&gt; with the line:&lt;/p&gt; &lt;p&gt; &lt;code&gt;alert ("Well Done. Your username and password were correctly  entered.");&lt;/code&gt; &lt;/p&gt; &lt;p&gt;I now replaced this with:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;if (window.XMLHttpRequest) //format and create request variable  according to browser type&lt;br /&gt;{// code for IE7+, Firefox, Chrome, Opera, Safari&lt;br /&gt;xmlhttp=new XMLHttpRequest();&lt;br /&gt;} //end of current option&lt;br /&gt;else&lt;br /&gt;{// code for IE6, IE5&lt;br /&gt;xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");&lt;br /&gt;} // end of old option&lt;br /&gt;xmlhttp.onreadystatechange=function()&lt;br /&gt;{ // this code displays response text&lt;br /&gt;if (xmlhttp.readyState==4 &amp;amp;&amp;amp; xmlhttp.status==200)&lt;br /&gt;{&lt;br /&gt;document.getElementById("untencell1").innerHTML=xmlhttp.responseText;&lt;br /&gt;}&lt;br /&gt;} //the code below calls the php script on the server&lt;br /&gt;xmlhttp.open("POST","logincheck.php?id="+subname+"&amp;amp;pw="+subpass,true);&lt;br /&gt;xmlhttp.send();&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I also added one more division to receive a message back from the PHP script:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;div id=untencell1&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This cell was placed under the button but within the form division.  The  PHP script was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;include('newinfo.php');// collect database variables.&lt;br /&gt;$id = $_GET['id']; // collect passed variable 1&lt;br /&gt;$pw = $_GET['pw']; // collect passed variable 2&lt;br /&gt;// To protect MySQL injection&lt;br /&gt;$id = stripslashes($id);&lt;br /&gt;$pw = stripslashes($pw);&lt;br /&gt;// $id = mysql_real_escape_string($id);&lt;br /&gt;// $pw = mysql_real_escape_string($pw);&lt;br /&gt;&lt;br /&gt;// Connect to server and select databse.&lt;br /&gt;$con = mysql_connect( $dbhost, $dbuser, $dbpass );&lt;br /&gt;if (!$con)&lt;br /&gt;{&lt;br /&gt;die('Could not connect: ' . mysql_error());&lt;br /&gt;}&lt;br /&gt;mysql_select_db($dbname, $con);&lt;br /&gt;$query = "SELECT Softid, PartPass FROM $table1 WHERE Softid = '$id' and PartPass  = '$pw'";&lt;br /&gt;$result = mysql_query($query) or die(mysql_error() . $query );&lt;br /&gt;// Mysql_num_row is counting table row&lt;br /&gt;$count=mysql_num_rows($result);&lt;br /&gt;if($count==1){&lt;br /&gt;echo"&amp;lt;p&amp;gt;Hooray you are logged in&amp;lt;/p&amp;gt;";&lt;br /&gt;} else {&lt;br /&gt;echo"&amp;lt;p&amp;gt;Oh Dear! Something went wrong. Query: &amp;lt;br/&amp;gt;$query &amp;lt;/p&amp;gt;";&lt;br /&gt;}&lt;br /&gt;mysql_close($con);&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;A couple of things still need fixing.  First the user is not taken  anywhere useful after logging in successfully.  That is because there is  currently nowhere to go.  The second is that the diagnostic display of the  query on login failure needs removing, after everything is definitely working.&lt;/p&gt; &lt;p&gt;After a successful login, the page currently looks as shown below:&lt;/p&gt; &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-evux4j_SvQY/TqfuRfyisrI/AAAAAAAAANI/ZltYOyei7fY/s1600/pic04.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 316px;" src="http://1.bp.blogspot.com/-evux4j_SvQY/TqfuRfyisrI/AAAAAAAAANI/ZltYOyei7fY/s320/pic04.JPG" alt="" id="BLOGGER_PHOTO_ID_5667760640427733682" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-6271697873158353179?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/6271697873158353179/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=6271697873158353179' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6271697873158353179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6271697873158353179'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/10/check-login-details-against-database.html' title='Check Login Details against the Database'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-evux4j_SvQY/TqfuRfyisrI/AAAAAAAAANI/ZltYOyei7fY/s72-c/pic04.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-5060230313672153234</id><published>2011-10-25T09:05:00.001-07:00</published><updated>2011-10-25T09:11:11.956-07:00</updated><title type='text'>JavaScript Business Rules</title><content type='html'>&lt;p&gt;In my last two entries, I created the &lt;a href="http://jhippjava.blogspot.com/2011/10/creating-login-page-front-end.html"&gt; front end interface&lt;/a&gt; for a login screen, and wrote a couple of simple &lt;a href="http://jhippjava.blogspot.com/2011/10/business-rules.html"&gt;business  rules&lt;/a&gt; in a PHP script to ensure both username and password fields are filled before running  a query on the database.  The time has now come to write the query and  check it against the field entries.&lt;/p&gt;  &lt;p&gt;Reading tutorials on the topic, I am first fascinated by the level of  paranoia and then I become paranoid myself.  So instead of getting on with  writing a query, I add another business rule prohibiting usernames or passwords  over eight characters.  Eight is the length of the fields in the database, so it is as silly  for users to enter 9 characters as no characters, so I might as well stop them  doing it.  It won't stop every SQL injection exploit, but it will preclude  them from attempting to write essays.&lt;/p&gt;  &lt;p&gt;I'm looking at a couple of tutorials for inspiration.  They both use  different SQL injection protection code.  One uses the &lt;code&gt;ereg()&lt;/code&gt; function, which  is apparently being phased out, so I won't use that.  The other takes the  user to another page on login, which won't work with my business rules code.&lt;/p&gt;  &lt;p&gt;I have to say I am not sure why I wrote the business rules into a PHP script.   If I used Java Script for the business rules, I could take the user to a new  page on successful login, and I could completely avoid unnecessary calls on the  server itself, as well as on the database.  But it will require a complete  rethink.&lt;/p&gt;  &lt;p&gt;To start fiddling, I change the login page back to an HTML file and remove  all PHP.  I then replace the PHP scripted error messages with division  placed in the same place.  The first is as follows:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;div id=ubercell1 class=warning&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;br/&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;In the CSS file the class &lt;code&gt;warning&lt;/code&gt; takes the color red.  I  then reduce  the form tag down from:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;form method="post" action="&amp;lt;?php echo $_SERVER['PHP_SELF']; ?&amp;gt;"&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;to:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And the button is changed from:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;input type="submit" name="login" value="Log in to Portal" class=itext  /&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;to:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;input type="button" value="Log in to Portal" class=itext onclick="busrules(this.form)"  /&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;And of course the PHP code is replaced by the JavaScript function  &lt;code&gt;busrules(form)&lt;/code&gt;.  I spent some time fiddling with the JavaScript, because I  don't know it very well.  The essential logic is that any one or more of four possible errors will generate a warning and preclude the call to the database.   When an error is corrected the warning message must be cleared, but where there  is no warning (i.e. if the user gets it right first time) nothing needs to  happen.  And in this test page, if everything is OK, an alert message says  everything is OK.&lt;/p&gt; &lt;p&gt;The rest of the page code remained the same, and the page looked the same,  but without needing a call back to the server, the error messages came up a lot  quicker than they did using PHP.  The full  JavaScript was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;function busrules(form)&lt;br /&gt;{&lt;br /&gt;var subname = form.username.value;&lt;br /&gt;var subpass = form.password.value;&lt;br /&gt;var showmessn;&lt;br /&gt;var showmessp;&lt;br /&gt;var ubercell1v = document.getElementById("ubercell1").innerHTML;&lt;br /&gt;var ubercell2v = document.getElementById("ubercell2").innerHTML;&lt;br /&gt;if (ubercell1v.length &amp;gt; 0)&lt;br /&gt;{&lt;br /&gt;document.getElementById("ubercell1").innerHTML="";&lt;br /&gt;} //end of null check&lt;br /&gt;if (ubercell2v.length &amp;gt; 0)&lt;br /&gt;{&lt;br /&gt;document.getElementById("ubercell2").innerHTML="";&lt;br /&gt;} //end of null check&lt;br /&gt;if (subname.length &amp;gt; 8 || subname.length ==0 || subpass.length ==0 ||  subpass.length ==0)&lt;br /&gt;{&lt;br /&gt;if (subname.length &amp;gt; 8)&lt;br /&gt;{&lt;br /&gt;showmessn = "Your user name is too long. Please use 8 characters.";&lt;br /&gt;document.getElementById("ubercell1").innerHTML=showmessn;&lt;br /&gt;} //end of condition 1&lt;br /&gt;if (subname.length ==0)&lt;br /&gt;{&lt;br /&gt;showmessn = "Oh Dear! You have not entered your user name.";&lt;br /&gt;document.getElementById("ubercell1").innerHTML=showmessn;&lt;br /&gt;} //end of condition 2&lt;br /&gt;if (subpass.length &amp;gt; 8)&lt;br /&gt;{&lt;br /&gt;showmessp = "Your user password is too long. Please use 8 characters.";&lt;br /&gt;document.getElementById("ubercell2").innerHTML=showmessp;&lt;br /&gt;} //end of condition 3&lt;br /&gt;if (subpass.length ==0)&lt;br /&gt;{&lt;br /&gt;showmessp = "Oh Dear! You have not entered your user password.";&lt;br /&gt;document.getElementById("ubercell2").innerHTML=showmessp;&lt;br /&gt;} //end of condition 4&lt;br /&gt;} else {&lt;br /&gt;alert ("Well Done. Your username and password were correctly entered.");&lt;br /&gt;} //end of master conditional statement&lt;br /&gt;} //end of function&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-5060230313672153234?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/5060230313672153234/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=5060230313672153234' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5060230313672153234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5060230313672153234'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/10/javascript-business-rules.html' title='JavaScript Business Rules'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-5377699124599286949</id><published>2011-10-23T02:02:00.000-07:00</published><updated>2011-10-25T08:41:39.155-07:00</updated><title type='text'>PHP Business Rules</title><content type='html'>&lt;p&gt;The purpose of the business rules layer is to prevent gibberish being written  to a database.  If you have a field designated to record currency values,  you don't want someone posting a long letter to their mother to it.  Of  course if you try to write text to a numeric field the database itself will  probably reject it, but doing so wastes server resources and risks corrupting  the database.&lt;/p&gt;&lt;p&gt;And in an age of web applications, where servers and clients are separated by  long distance and heavy traffic, sending redundant requests to the server wastes  time and annoys the user.&lt;/p&gt; &lt;p&gt;There are two aspects to the business rules layer:&lt;/p&gt; &lt;ol&gt;&lt;li&gt;The coded rules;&lt;/li&gt;&lt;li&gt;The front end manifestation when one or more of the conditions set out in    the rules is not met.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;In the olden days, if you tried to make an illegal entry into a database field,  a new window or dialog box opened up with a rude message, and sometimes the  computer would beep at you.  The dialog box would then have to be closed  manually by the user before they could continue with their work.  &lt;/p&gt; &lt;p&gt;Nowadays a more subtle approach is preferred.  Usually a message is  written on to the data entry form itself, just above or close to the field with  the inappropriate or missing entry.&lt;/p&gt; &lt;p&gt;In the case of a login screen, nothing is being written to the database, and  a null field is conceptually similar to an incorrect entry, so some  applications skip business rules in the login screen and send null fields for  checking against the database along with everything else.&lt;/p&gt; &lt;p&gt;My server is particularly slow, and I am always aware of the implicit cost of  making unnecessary calls on the database, so I shall write a couple of lines to  ensure users at least put something in both username and password fields.&lt;/p&gt; &lt;p&gt;The login screen shown in my &lt;a href="http://jhippjava.blogspot.com/2011/10/creating-login-page-front-end.html"&gt; previous post&lt;/a&gt; was written in HTML and tested at home.  I shall now have  to migrate across to PHP and as I don't have PHP installed at home, I shall have to  work on my web host server.&lt;/p&gt; &lt;p&gt;The PHP script will open with the &lt;code&gt;include()&lt;/code&gt; statement and a  variable declaration for the error condition:&lt;/p&gt; &lt;p&gt;&lt;code&gt;include('dbinfo.php'); // get database information&lt;br /&gt;$error = false; //boolean used to contain error condition&lt;/code&gt;&lt;/p&gt; &lt;p&gt;It will continue with the equivalent of event code for the button click  event.  In this case there is no need to register an actual event, because  the login button is calling the containing page:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;form method="post" action="&amp;lt;?php echo $_SERVER['PHP_SELF']; ?&amp;gt;"&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The code for the whole page is rerun when the button is clicked, so there is  no need to register the event as such, but rather the condition of &lt;i&gt;having  been clicked&lt;/i&gt;:&lt;/p&gt; &lt;p&gt;&lt;code&gt;if (isset($_POST['login'])) {&lt;br /&gt;// variables filled with form inputs&lt;br /&gt;$usertype = $_POST['usertype'];&lt;br /&gt;$username = $_POST['username'];&lt;br /&gt;$password = $_POST['password'];&lt;br /&gt;// check that neither field is empty&lt;br /&gt;if ( !empty($firstname) &amp;amp;&amp;amp; !empty($lastname) ) {&lt;br /&gt;//run crunchy code&lt;br /&gt;} else {&lt;br /&gt;$error = true; // error condition met&lt;br /&gt;} // end of empty field check&lt;br /&gt;} // end of buttonclicked conditional code&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The "crunchy code" will be discussed later.  For now, I need to insert a  couple of extra lines into the page to use the $error variable.  The first  insert goes at the top of the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; I called &lt;code&gt;row2&lt;/code&gt;,  which holds the username field:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;if ( $error &amp;amp;&amp;amp; empty($username) ) {&lt;br /&gt;echo '&amp;lt;span style="gt;Oh Dear! You did not enter your name.&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;',"\n";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The second insert goes at the top of the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; I called &lt;code&gt;row3&lt;/code&gt;, which holds the password field:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;if ( $error &amp;amp;&amp;amp; empty($password) ) {&lt;br /&gt;echo '&amp;lt;span style="gt;Oh Dear! You did not enter your password.&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;',"\n";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I have to admit that this is easier using the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag  than it would have been using a table. A table would have required a new row,  and a cell spanning two column widths for each insert.  Using the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;  tag, I just squashed the new code inside the containing division and above the  two floating "cells".&lt;/p&gt; &lt;p&gt;The code for the whole page has now become:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;include('dbinfo.php'); // get database information&lt;br /&gt;$error = false; //boolean used to contain error condition&lt;br /&gt;/**&lt;br /&gt;* The code below is ignored when the page loads&lt;br /&gt;* but is run on reload after button click.&lt;br /&gt;*/&lt;br /&gt;if (isset($_POST['login'])) {&lt;br /&gt;// variables filled with form inputs&lt;br /&gt;$usertype = $_POST['usertype'];&lt;br /&gt;$username = $_POST['username'];&lt;br /&gt;$password = $_POST['password'];&lt;br /&gt;// check that neither field is empty&lt;br /&gt;if ( !empty($firstname) &amp;amp;&amp;amp; !empty($lastname) ) {&lt;br /&gt;//run crunchy code&lt;br /&gt;} else {&lt;br /&gt;$error = true; // error condition met&lt;br /&gt;} // end of input check&lt;br /&gt;} // end of buttonclicked conditional code&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;Active Math Java Private Portal&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;link rel="stylesheet" type="text/css" href="pportal.css" /&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id="container"&amp;gt;&lt;br /&gt;&amp;lt;div id="header"&amp;gt;&lt;br /&gt;&amp;lt;h1 class="top"&amp;gt;Rasch-ItemBank&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;h3 class="top"&amp;gt;A&lt;br /&gt;&amp;lt;a class="top" href="http://www.interactived.com/softway.htm"&amp;gt;&lt;br /&gt;Softway&amp;lt;/a&amp;gt; Open Source Project &amp;lt;br/&amp;gt;&lt;br /&gt;Hosted by &amp;lt;a class="top" href="http://java.net/projects"&amp;gt;Java.net&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id="left"&amp;gt;&lt;br /&gt;&amp;lt;b&amp;gt;Menu&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;a class="menu" href="http://www.interactived.com/softway.htm"&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;br  /&amp;gt;&lt;br /&gt;&amp;lt;a class="menu" href="http://www.interactived.com/research.htm"&amp;gt;Research&amp;lt;/a&amp;gt;&amp;lt;br  /&amp;gt;&lt;br /&gt;&amp;lt;a class="menu" href="http://www.interactived.com/software.htm"&amp;gt;Software&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id="content" style="height:400px;width:85%;"&amp;gt;&lt;br /&gt;&amp;lt;h1 class="main"&amp;gt;Active Math Java&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;h3 class="main"&amp;gt;Private Portal&amp;lt;br/&amp;gt;&lt;br /&gt;The Blueridge School of Apalit, Inc.&lt;br /&gt;&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;div id=logintable class=inputtable&amp;gt;&lt;br /&gt;&amp;lt;div id=row1 class=row&amp;gt;&lt;br /&gt;&amp;lt;h3&amp;gt;Initial Login Screen&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;form method="post" action="&amp;lt;?php echo $_SERVER['PHP_SELF']; ?&amp;gt;"&amp;gt;&lt;br /&gt;&amp;lt;div id=row1 class=row&amp;gt;&lt;br /&gt;&amp;lt;div id=cell11 class=col1&amp;gt;Please select user or admin&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=cell12 class=col2&amp;gt;&lt;br /&gt;&amp;lt;select name="usertype" class=cbox&amp;gt;&lt;br /&gt;&amp;lt;option value="user"&amp;gt;user&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;option value="admin"&amp;gt;admin&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;/select&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;div id=row2 class=row&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;if ( $error &amp;amp;&amp;amp; empty($username) ) {&lt;br /&gt;echo '&amp;lt;span style="gt;Oh Dear! You did not enter your name.&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;',"\n";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;div id=cell21 class=col1&amp;gt;Please enter your name&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=cell22 class=col2&amp;gt;&amp;lt;input type="text" name="username" class=itext  /&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;div id=row3 class=row&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;if ( $error &amp;amp;&amp;amp; empty($password) ) {&lt;br /&gt;echo '&amp;lt;span style="gt;Oh Dear! You did not enter your password.&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;',"\n";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;div id=cell31 class=col1&amp;gt;Please enter your password&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=cell32 class=col2&amp;gt;&amp;lt;input type="password" name="password" class=itext  /&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;div id=row4 class=row&amp;gt;&lt;br /&gt;&amp;lt;div id=cell41 class=col1&amp;gt;Click button to log in&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=cell42 class=col2&amp;gt;&amp;lt;input type="submit" name="login" value="Log  in to Portal" class=itext /&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id="footer"&amp;gt;&lt;br /&gt;Helping Children to Achieve their Potential&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And when I clicked the login button, with two empty fields, the page came up  as shown below:&lt;/p&gt; &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-HNSCVA9-6Mo/TqPYdBttaDI/AAAAAAAAAM8/xo-Ucnfdlh4/s1600/pic03.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 298px;" src="http://3.bp.blogspot.com/-HNSCVA9-6Mo/TqPYdBttaDI/AAAAAAAAAM8/xo-Ucnfdlh4/s320/pic03.JPG" alt="" id="BLOGGER_PHOTO_ID_5666610749350176818" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-5377699124599286949?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/5377699124599286949/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=5377699124599286949' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5377699124599286949'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5377699124599286949'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/10/business-rules.html' title='PHP Business Rules'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-HNSCVA9-6Mo/TqPYdBttaDI/AAAAAAAAAM8/xo-Ucnfdlh4/s72-c/pic03.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-7044497268775671023</id><published>2011-10-22T09:35:00.000-07:00</published><updated>2011-10-22T09:42:19.967-07:00</updated><title type='text'>Creating a login page</title><content type='html'>There are three steps to creating a login page, or really any page which  exchanges information with a database. &lt;ol&gt;&lt;li&gt;Creating the front end interface;&lt;/li&gt;&lt;li&gt;Writing the business rules;&lt;/li&gt;&lt;li&gt;Writing the interface with the database.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;In a &lt;a href="http://jhippjava.blogspot.com/2011/09/simple-web-application-add-data-form.html"&gt; previous post&lt;/a&gt; I already described a form which added records to a data table.  In  that example I was a bit sloppy, because I omitted any business rules code.   My excuse was that the data table in that example was intended to be populated automatically, so  the input form would never be used in real life.&lt;/p&gt; &lt;p&gt;I am now dealing with a request from a school to track student performance,  so I have to create a manual database portal or interface for them.  The  first step is the login screen.  At a trivial level, this is just a couple  of fields and a button, so not much thought needs to go into it.&lt;/p&gt;  &lt;p&gt;But as I am using the exercise to stimulate a web site redesign, I have  chosen to go a little deeper.  My usual method of making forms look  reasonably neat is to shove them in a table.  But the HTML purists don't  like table any more, so I decided to look into using the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;  tag instead.  At the same time, I extended my use of the external CSS page,  which I used in my &lt;a href="http://jhippjava.blogspot.com/2011/10/web-site-redesign.html"&gt;previous  post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Whether correctly or not, I followed the pattern of a table, with a series  of horizontal rows, each nested with two "cells", one floating to the left, the  other to the right, and all inside a "zone" which I classified as "inputtable",  which in turn lay inside the page (code not shown) created in my &lt;a href="http://jhippjava.blogspot.com/2011/10/web-site-redesign.html"&gt;previous  post&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;div id=logintable class=inputtable&amp;gt;&lt;br /&gt;&amp;lt;div id=row0 class=row&amp;gt;&lt;br /&gt;&amp;lt;h3&amp;gt;Initial Login Screen&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;form&amp;gt;&lt;br /&gt;&amp;lt;div id=row1 class=row&amp;gt;&lt;br /&gt;&amp;lt;div id=cell11 class=col1&amp;gt;Please select user or admin&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=cell12 class=col2&amp;gt;&lt;br /&gt;&amp;lt;select name="usertype" class=cbox&amp;gt;&lt;br /&gt;&amp;lt;option value="user"&amp;gt;user&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;option value="admin"&amp;gt;admin&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;/select&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;div id=row2 class=row&amp;gt;&lt;br /&gt;&amp;lt;div id=cell21 class=col1&amp;gt;Please enter your name&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=cell22 class=col2&amp;gt;&amp;lt;input type="text" name="username" class=itext  /&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;div id=row3 class=row&amp;gt;&lt;br /&gt;&amp;lt;div id=cell31 class=col1&amp;gt;Please enter your password&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=cell32 class=col2&amp;gt;&amp;lt;input type="password" name="password" class=itext  /&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;div id=row4 class=row&amp;gt;&lt;br /&gt;&amp;lt;div id=cell41 class=col1&amp;gt;Click button to log in&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=cell42 class=col2&amp;gt;&amp;lt;input type="submit" value="Log in to Portal"  class=itext /&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;To accommodate the extra classes, the CSS page was expanded as follows:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;body {&lt;br /&gt;margin:10px 0px; padding:0px;&lt;br /&gt;text-align:center;&lt;br /&gt;}&lt;br /&gt;#container {width:800;}&lt;br /&gt;#header {background-color:#151B8D;text-align:left;}&lt;br /&gt;#left {background-color:#5CB3FF;height:500px;width:15%;float:left;text-align:left;}&lt;br /&gt;#content {height:400px;width:85%;}&lt;br /&gt;#footer {background-color:#488AC7;clear:both;text-align:center;}&lt;br /&gt;&lt;br /&gt;a:link {text-decoration:none;} /* unvisited link */&lt;br /&gt;a:visited {text-decoration:none;} /* visited link */&lt;br /&gt;a:hover {text-decoration:underline;} /* mouse over link */&lt;br /&gt;a:active {text-decoration:none;} /* selected link */&lt;br /&gt;&lt;br /&gt;h1.top {margin-bottom:0;color=#FFFF00;}&lt;br /&gt;h3.top {margin-bottom:0;margin-top:0;color=#FFFF00;}&lt;br /&gt;a.top {color=#FFFF00;}&lt;br /&gt;&lt;br /&gt;h1.main {margin-bottom:0;text-align:center;}&lt;br /&gt;h3.main {margin-bottom:0;margin-top:0;text-align:center;}&lt;br /&gt;&lt;br /&gt;a.menu {color=#000000;}&lt;br /&gt;&lt;br /&gt;.inputtable {margin:50; background-color:#BDEDFF}&lt;br /&gt;.row {width:420;}&lt;br /&gt;.col1 {text-align:right; float:left; width:200; margin:0 5 0 5;}&lt;br /&gt;.col2 {text-align:left; float:right; width:200; margin:0 5 0 5;}&lt;br /&gt;.itext {width:150;}&lt;br /&gt;.cbox {width:150; margin-left:5;}&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;And the finished page looked as follows:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://4.bp.blogspot.com/-1ulbU5bJxEs/TqLxRk61QMI/AAAAAAAAAMw/qMWgS2PLQiU/s1600/pic02.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 302px;" src="http://4.bp.blogspot.com/-1ulbU5bJxEs/TqLxRk61QMI/AAAAAAAAAMw/qMWgS2PLQiU/s320/pic02.JPG" alt="" id="BLOGGER_PHOTO_ID_5666356565456011458" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-7044497268775671023?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/7044497268775671023/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=7044497268775671023' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/7044497268775671023'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/7044497268775671023'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/10/creating-login-page-front-end.html' title='Creating a login page'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-1ulbU5bJxEs/TqLxRk61QMI/AAAAAAAAAMw/qMWgS2PLQiU/s72-c/pic02.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-3386803682813030557</id><published>2011-10-21T04:26:00.000-07:00</published><updated>2011-10-21T04:28:34.693-07:00</updated><title type='text'>Web site redesign</title><content type='html'>In my quest to get &lt;a href="http://www.interactived.com/JMT1111/JMT1111.htm"&gt; my Applet&lt;/a&gt; talking to a commercially hosted MySQL database, I was forced to  update my knowledge of a number of related areas, including HTML.   Coincidentally, I get a lot of spam telling me how dreary and old fashioned my  MS Front page designed &lt;a href="http://www.interactived.com/softway.htm"&gt;website&lt;/a&gt;  is.  &lt;p&gt;A school has asked for a private portal to &lt;a href="http://www.interactived.com/JMT1111/JMT1111.htm"&gt;the Applet&lt;/a&gt;, and I  want the page to remain outside the main &lt;a href="http://www.interactived.com/softway.htm"&gt;website&lt;/a&gt; navigation  structure.  I could just give them a form on a plain page.  Or I could  use the opportunity to play with HTML layouts and CSS.&lt;/p&gt; &lt;p&gt;My favorite tutorial site, &lt;a href="http://www.w3schools.com/default.asp"&gt; W3schools&lt;/a&gt;, has a nice &lt;a href="http://www.w3schools.com/html/html_layout.asp"&gt;sample layout&lt;/a&gt;,  similar to their own.  I have adapted this with my own colors and text.   I have also changed the behavior of links, so that they look more like  surrounding test, except when they are hovered over.  My HTML was as  follows:&lt;/p&gt; &lt;p&gt; &lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;Active Math Java Private Portal&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;style type="text/css"&amp;gt;&lt;br /&gt;a:link {text-decoration:none;} /* unvisited link */&lt;br /&gt;a:visited {text-decoration:none;} /* visited link */&lt;br /&gt;a:hover {text-decoration:underline;} /* mouse over link */&lt;br /&gt;a:active {text-decoration:none;} /* selected link */&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id="container" style="width:100%"&amp;gt;&lt;br /&gt;&amp;lt;div id="header" style="background-color:#151B8D"&amp;gt;&lt;br /&gt;&amp;lt;h1 style="margin-bottom:0;color=#FFFF00;"&amp;gt;Rasch-ItemBank&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;h3 style="margin-bottom:0;margin-top:0;color=#FFFF00;"&amp;gt;A&lt;br /&gt;&amp;lt;a href="http://www.interactived.com/softway.htm"  style="color=#FFFF00;"&amp;gt;&lt;br /&gt;Softway&amp;lt;/a&amp;gt; Open Source Project&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;h3 style="margin-bottom:0;margin-top:0;color=#FFFF00;"&amp;gt;Hosted by&lt;br /&gt;&amp;lt;a href="http://java.net/projects" style="color=#FFFF00;"&amp;gt;Java.net&amp;lt;/a&amp;gt;&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id="menu" style="background-color:#82CAFA;height:400px;width:15%;float:left;"&amp;gt;&lt;br /&gt;&amp;lt;b&amp;gt;Menu&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;a href="http://www.interactived.com/softway.htm"  style="color=#000000;"&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;a href="http://www.interactived.com/research.htm"  style="color=#000000;"&amp;gt;Research&amp;lt;/a&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;a href="http://www.interactived.com/software.htm"  style="color=#000000;"&amp;gt;Software&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id="content" style="height:400px;width:85%;"&amp;gt;&lt;br /&gt;&amp;lt;h1 style="margin-bottom:0;text-align:center"&amp;gt;Active Math Java&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;h3 style="margin-bottom:0;margin-top:0;text-align:center"&amp;gt;Private Portal&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;h3 style="margin-bottom:0;margin-top:0;text-align:center"&amp;gt;&lt;br /&gt;The Blueridge School of Apalit, Inc.&lt;br /&gt;&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id="footer"  style="background-color:#56A5EC;clear:both;text-align:center;"&amp;gt;&lt;br /&gt;Helping Children to Achieve their Potential&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;And it came up as shown below:&lt;/p&gt; &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-ozkEW0SOGKM/TqFXO1DKwcI/AAAAAAAAAMk/lYWR13zD090/s1600/pic01.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 256px; height: 320px;" src="http://1.bp.blogspot.com/-ozkEW0SOGKM/TqFXO1DKwcI/AAAAAAAAAMk/lYWR13zD090/s320/pic01.JPG" alt="" id="BLOGGER_PHOTO_ID_5665905718478946754" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The &lt;a href="http://www.w3schools.com/css/default.asp"&gt;tutorial&lt;/a&gt;  recommended using an external CSS style sheet, so as to facilitate site wide  design changes.  That's fine for colors and fonts, but a question running  through my mind is how they achieve site wide menu changes.  Their own  source code betrays few secrets these days because it might have been generated  with a script, although it certainly represents a thorough example of using the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;  &lt;p&gt;I found the CSS tutorial a bit confusing when it came to &lt;a href="http://www.w3schools.com/css/css_id_class.asp"&gt;classes&lt;/a&gt;, but part of  the confusion arose because of my inability to type.  Anyway, after some  fiddling around, my CSS page looked like this:&lt;/p&gt; &lt;p&gt;&lt;code&gt;a:link {text-decoration:none;} /* unvisited link */&lt;br /&gt;a:visited {text-decoration:none;} /* visited link */&lt;br /&gt;a:hover {text-decoration:underline;} /* mouse over link */&lt;br /&gt;a:active {text-decoration:none;} /* selected link */&lt;br /&gt;&lt;br /&gt;h1.top {margin-bottom:0;color=#FFFF00;}&lt;br /&gt;h3.top {margin-bottom:0;margin-top:0;color=#FFFF00;}&lt;br /&gt;a.top {color=#FFFF00;}&lt;br /&gt;&lt;br /&gt;h1.main {margin-bottom:0;text-align:center;}&lt;br /&gt;h3.main {margin-bottom:0;margin-top:0;text-align:center;}&lt;br /&gt;&lt;br /&gt;a.menu {color=#000000;}&lt;br /&gt;&lt;br /&gt;#header {background-color:#151B8D;}&lt;br /&gt;#left {background-color:#82CAFA;height:400px;width:15%;float:left;}&lt;br /&gt;#content {height:400px;width:85%;}&lt;br /&gt;#footer {background-color:#56A5EC;clear:both;text-align:center;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And the HTML became:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;Active Math Java Private Portal&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;link rel="stylesheet" type="text/css" href="pportal.css" /&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id="container" style="width:100%"&amp;gt;&lt;br /&gt;&amp;lt;div id="header"&amp;gt;&lt;br /&gt;&amp;lt;h1 class="top"&amp;gt;Rasch-ItemBank&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;h3 class="top"&amp;gt;A&lt;br /&gt;&amp;lt;a class="top" href="http://www.interactived.com/softway.htm"&amp;gt;&lt;br /&gt;Softway&amp;lt;/a&amp;gt; Open Source Project &amp;lt;br/&amp;gt;&lt;br /&gt;Hosted by &amp;lt;a class="top" href="http://java.net/projects"&amp;gt;Java.net&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id="left"&amp;gt;&lt;br /&gt;&amp;lt;b&amp;gt;Menu&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;a class="menu" href="http://www.interactived.com/softway.htm"&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;br  /&amp;gt;&lt;br /&gt;&amp;lt;a class="menu" href="http://www.interactived.com/research.htm"&amp;gt;Research&amp;lt;/a&amp;gt;&amp;lt;br  /&amp;gt;&lt;br /&gt;&amp;lt;a class="menu" href="http://www.interactived.com/software.htm"&amp;gt;Software&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id="content" style="height:400px;width:85%;"&amp;gt;&lt;br /&gt;&amp;lt;h1 class="main"&amp;gt;Active Math Java&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;h3 class="main"&amp;gt;Private Portal&amp;lt;br/&amp;gt;&lt;br /&gt;The Blueridge School of Apalit, Inc.&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id="footer"&amp;gt;&lt;br /&gt;Helping Children to Achieve their Potential&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And to my enormous surprise it ended up looking exactly the same as that  produced by the single page as shown above.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-3386803682813030557?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/3386803682813030557/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=3386803682813030557' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3386803682813030557'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3386803682813030557'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/10/web-site-redesign.html' title='Web site redesign'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-ozkEW0SOGKM/TqFXO1DKwcI/AAAAAAAAAMk/lYWR13zD090/s72-c/pic01.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-2420597751166191029</id><published>2011-09-24T00:59:00.000-07:00</published><updated>2011-10-25T23:07:27.416-07:00</updated><title type='text'>Applet to AJAX to PHP methodology</title><content type='html'>&lt;p&gt;I have an Applet, which adds lines to a database one at a time, by sending an  SQL string via AJAX to a PHP script.  The Applet data insertion method is  as follows:&lt;/p&gt; &lt;p&gt;&lt;code&gt;private void addItem3(String newWord) {&lt;br /&gt;if(LIVE) {&lt;br /&gt;if(jso != null )&lt;br /&gt;try {&lt;br /&gt;jso.call("updateWebPage", new String[] {newWord});&lt;br /&gt;}&lt;br /&gt;catch (Exception ex) {&lt;br /&gt;addItem2("jso call failed... ");&lt;br /&gt;ex.printStackTrace();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Where the parameter &lt;code&gt;newWord&lt;/code&gt; being passed to that method might look like:&lt;/p&gt; &lt;p&gt;&lt;code&gt;INSERT INTO mytable (Partid, OpCode, ItemLeft, ItemRight, Raw, Rate)  VALUES (684, 1, 2, 5, 1, 34)&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The JavaScript function updateWebPage and the PHP script were given in my  &lt;a href="http://jhippjava.blogspot.com/2011/09/applet-to-javascript-to-php-post-to.html"&gt;previous post&lt;/a&gt;, so I won't repeat them here.&lt;/p&gt; &lt;p&gt;The thing is, even a single instance of the Applet can generate new lines  very quickly, sometimes once a second.  So a classroom of 25 students might  generate 25 lines a second.  How will my ISP server react to all these  requests to open a connection, insert a single line of data, and close the  connection.  &lt;/p&gt; &lt;p&gt;In my experience, a typical eCommerce interaction involves a fairly long data  reading session (browsing a catalogue) and then at the end, perhaps the  insertion of a single line of data into a purchase order table.  And from  forum browsing, most Applet games seem to download some data at the start of the  game, and then perhaps upload a line of data at the the end of the game.   And if it is a game like Pacman, it might last for 10 or 15 minutes, or longer.   So I am inclined to believe that your average eCommerce server, and certainly  not a budget one like the one I use, is not designed to cope with such frequent  data updates from a single source.&lt;/p&gt;  &lt;p&gt;This blog is intended for theory questions and problems.  Practical  implementation thoughts and solutions are the domain of my &lt;a href="http://rasch-itembank.blogspot.com/"&gt;Rasch blog&lt;/a&gt;, so I think I'll  transfer this one over there.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-2420597751166191029?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/2420597751166191029/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=2420597751166191029' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/2420597751166191029'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/2420597751166191029'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/applet-to-ajax-to-php-methodology.html' title='Applet to AJAX to PHP methodology'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-5091132262465922149</id><published>2011-09-20T00:09:00.000-07:00</published><updated>2011-09-20T00:17:28.766-07:00</updated><title type='text'>Applet to JavaScript to PHP post to Database</title><content type='html'>This post brings together the  &lt;a href="http://jhippjava.blogspot.com/2011/09/pass-sql-command-from-applet-to.html"&gt;previous&lt;/a&gt; two.   In the &lt;a href="http://jhippjava.blogspot.com/2011/09/php-and-javascriptajax-database-query.html"&gt; first&lt;/a&gt;, I called PHP code from a JavaScript function using an AJAX command.   In the &lt;a href="http://jhippjava.blogspot.com/2011/09/pass-sql-command-from-applet-to.html"&gt; second&lt;/a&gt;, I passed an SQL command to a JavaScript function.  In this post  I describe bringing the two together.  Instead of simply displaying the SQL  in a text box on the web page, passing it to a PHP file.  &lt;p&gt;The applet code was unchanged, but the JavaScript function was extended from:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;function updateWebPage(myArg)&lt;br /&gt;{&lt;br /&gt;document.getElementById("txt1").innerHTML=myArg;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;to:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;function updateWebPage(myArg)&lt;br /&gt;{&lt;br /&gt;document.getElementById("txt1").innerHTML=myArg;&lt;br /&gt;if (myArg=="")&lt;br /&gt;{&lt;br /&gt;document.getElementById("cbxItem").innerHTML="";&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;if (window.XMLHttpRequest)&lt;br /&gt;{// code for IE7+, Firefox, Chrome, Opera, Safari&lt;br /&gt;xmlhttp=new XMLHttpRequest();&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{// code for IE6, IE5&lt;br /&gt;xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");&lt;br /&gt;}&lt;br /&gt;xmlhttp.onreadystatechange=function()&lt;br /&gt;{&lt;br /&gt;if (xmlhttp.readyState==4 &amp;amp;&amp;amp; xmlhttp.status==200)&lt;br /&gt;{&lt;br /&gt;document.getElementById("cbxItem").innerHTML=xmlhttp.responseText;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;xmlhttp.open("GET","putitem.php?id="+myArg,true);&lt;br /&gt;xmlhttp.send();&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;And the HTML table had an extra couple of cells added:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;table border=1 align='center' cellpadding=0 cellspacing=0 &amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td style='text-align:center; background-color:#C0C0C0'&amp;gt;Compiled Java  Applet&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;applet code="JSHelloWorld2.class"&lt;br /&gt;width="500" height="80" MAYSCRIPT style="border-width:0;" name="jsap" id="jsap"&amp;gt;&lt;br /&gt;&amp;lt;/applet&amp;gt; &amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td style='text-align:center; background-color:#C0C0C0'&amp;gt;HTML Textbox filled  by JavaScript&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;textarea style='width:500px; height:50px' name='txt1' id='txt1'&amp;gt;Query  goes here&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td style='text-align:center; background-color:#C0C0C0'&amp;gt;HTML diagnostic  messages rendered by PHP script&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;div id="cbxItem"&amp;gt;PHP info will populate this space&amp;lt;/div&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;The PH script was:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;$id = $_GET['id'];&lt;br /&gt;include('dbinfo.php');// collect database variables and connect.&lt;br /&gt;$con = mysql_connect( $dbhost, $dbuser, $dbpass );&lt;br /&gt;if (!$con)&lt;br /&gt;{&lt;br /&gt;die('Could not connect: ' . mysql_error());&lt;br /&gt;}&lt;br /&gt;mysql_select_db($dbname, $con);&lt;br /&gt;// first use encodeURIComponent on javascript to encode the string&lt;br /&gt;// receive json string and prepare it to json_decode&lt;br /&gt;$jsonStr = stripslashes ($id);&lt;br /&gt;$query = $jsonStr;&lt;br /&gt;$result = mysql_query($query) or die(mysql_error());&lt;br /&gt;echo"&amp;lt;p&amp;gt;The query is: $query &amp;lt;/p&amp;gt;";&lt;br /&gt;echo"&amp;lt;p&amp;gt;The result is: $result &amp;lt;/p&amp;gt;";&lt;br /&gt;mysql_close($con);&lt;/code&gt;&lt;br /&gt;?&amp;gt;&lt;/p&gt;  &lt;p&gt;I hate it when people put obscure references in code, so for anyone who has  not been following this blog, the &lt;code&gt;dbinfo.php&lt;/code&gt; structure was given in  the &lt;a href="http://jhippjava.blogspot.com/2011/09/simple-web-application-data-display.html"&gt; Simple Web Application – Data Display page&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;On opening, the web page looked as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-QKnWLknBYqc/Tng8pbt2-cI/AAAAAAAAALs/mqp22RiNnn4/s1600/pic61.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 219px;" src="http://2.bp.blogspot.com/-QKnWLknBYqc/Tng8pbt2-cI/AAAAAAAAALs/mqp22RiNnn4/s320/pic61.jpg" alt="" id="BLOGGER_PHOTO_ID_5654336014676064706" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And after clicking the button on the applet, it was as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-WjJI8z-GFZs/Tng8pvWFtYI/AAAAAAAAAL0/q6wIBtY94uQ/s1600/pic62.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 270px;" src="http://2.bp.blogspot.com/-WjJI8z-GFZs/Tng8pvWFtYI/AAAAAAAAAL0/q6wIBtY94uQ/s320/pic62.jpg" alt="" id="BLOGGER_PHOTO_ID_5654336019945076098" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The result of 1 (or true) returned by the query indicated that a line had  been successfully inserted.  Inspection of the database using the  &lt;a href="http://jhippjava.blogspot.com/2011/09/simple-web-application-data-display.html"&gt; Simple Web App&lt;/a&gt;, confirmed that this was the case.  The only minor  problem was the loss of the plus sign in "Itemdet", but that can be fixed.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-5091132262465922149?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/5091132262465922149/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=5091132262465922149' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5091132262465922149'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5091132262465922149'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/applet-to-javascript-to-php-post-to.html' title='Applet to JavaScript to PHP post to Database'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-QKnWLknBYqc/Tng8pbt2-cI/AAAAAAAAALs/mqp22RiNnn4/s72-c/pic61.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-15687084298502148</id><published>2011-09-19T21:11:00.000-07:00</published><updated>2011-09-19T21:18:38.593-07:00</updated><title type='text'>Pass SQL command from Applet to JavaScript function</title><content type='html'>My last post recorded an important milestone for me, because I managed to  call PHP code from a JavaScript function. &lt;p&gt;On an earlier occasion, I had managed to call a JavaScript  function from an Applet.&lt;/p&gt; &lt;p&gt;My next task was to put the two together, and I did this in two steps the  first of which (reported in the current post) was to adapt the previous &lt;a href="http://jhippjava.blogspot.com/2011/09/applet-to-javascript-communication.html"&gt; Applet to JavaScript&lt;/a&gt; example to display an SQL command.  This was  essentially a cosmetic exercise, but it acted as a refresher on the code.&lt;/p&gt;  &lt;p&gt;The only change to the Applet code was to replace "Hello World" with an SQL  string.  There is no need to reprint that here as it was given in  &lt;a href="http://jhippjava.blogspot.com/2011/09/applet-to-javascript-communication.html"&gt; my  previous post&lt;/a&gt; on the topic.&lt;/p&gt;  &lt;p&gt;In the HTML, I modified the table to display the Applet above the text box,  and I widened them both.  I also removed the update Applet function, as it  was not required for the current exercise.  It was then as follows:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;function updateWebPage(myArg)&lt;br /&gt;{&lt;br /&gt;document.getElementById("txt1").innerHTML=myArg;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;form&amp;gt;&lt;br /&gt;&amp;lt;table border=0 align='center' cellpadding=0 cellspacing=0 &amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&lt;br /&gt;&amp;lt;td valign='top'&amp;gt;&lt;br /&gt;&amp;lt;table&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td style='text-align:center; background-color:#EEEEEE'&amp;gt;Applet&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&lt;br /&gt;&amp;lt;applet code="JSHelloWorld2.class"&lt;br /&gt;width="500" height="80" MAYSCRIPT style="border-width:0;" name="jsap" id="jsap"&amp;gt;&lt;br /&gt;&amp;lt;/applet&amp;gt; &amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td style='text-align:center; background-color:#EEEEEE'&amp;gt;JavaScript&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;textarea style='width:500px; height:50px' name='txt1' id='txt1'&amp;gt;Query  goes here&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;It came up initially as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-Pyotws-EFtc/TngTsVUXTGI/AAAAAAAAALU/YlDNm46F1x8/s1600/pic51.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 180px;" src="http://3.bp.blogspot.com/-Pyotws-EFtc/TngTsVUXTGI/AAAAAAAAALU/YlDNm46F1x8/s320/pic51.jpg" alt="" id="BLOGGER_PHOTO_ID_5654290984521387106" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;After clicking the Applet button it was then as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-WVAr3yCjMR4/TngTsicyAvI/AAAAAAAAALk/M0AyRI9rL34/s1600/pic52.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 180px;" src="http://3.bp.blogspot.com/-WVAr3yCjMR4/TngTsicyAvI/AAAAAAAAALk/M0AyRI9rL34/s320/pic52.jpg" alt="" id="BLOGGER_PHOTO_ID_5654290988046353138" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And to my amazement, I could modify the text (see below) as many times as I  liked, and the modified text was transferred across every time.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-KVXaw_b5n2A/TngTsTTP9lI/AAAAAAAAALc/ad_DimwUwcQ/s1600/pic53.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 180px;" src="http://3.bp.blogspot.com/-KVXaw_b5n2A/TngTsTTP9lI/AAAAAAAAALc/ad_DimwUwcQ/s320/pic53.jpg" alt="" id="BLOGGER_PHOTO_ID_5654290983979841106" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-15687084298502148?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/15687084298502148/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=15687084298502148' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/15687084298502148'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/15687084298502148'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/pass-sql-command-from-applet-to.html' title='Pass SQL command from Applet to JavaScript function'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-Pyotws-EFtc/TngTsVUXTGI/AAAAAAAAALU/YlDNm46F1x8/s72-c/pic51.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-7610151307421164138</id><published>2011-09-18T00:37:00.000-07:00</published><updated>2011-10-25T23:06:09.417-07:00</updated><title type='text'>PHP and JavaScript/AJAX database query</title><content type='html'>Including the term JavaScript here is tautologous really because AJAX written  out in full is Asynchronous JavaScript and XML.  But as combining PHP and  JavaScript has become something of a holy grail for me, I thought I'd include it  anyway.  In fact my &lt;a href="http://jhippjava.blogspot.com/2011/09/javascript-and-php.html"&gt; September 9 blog entry&lt;/a&gt; was originally posted under the title PHP and  JavaScript (so keen was I to use it), until I reflected on the text overnight  and realised there was actually nothing about JavaScript in the post. &lt;p&gt;I have been running around in circles a bit over the last couple of months,  but they have been good circles, because they have enriched my understanding of  a number of web related topics.  And my current circle has taken me back to  the generally excellent and easy to follow &lt;a href="http://www.w3schools.com/default.asp"&gt;W3Schools&lt;/a&gt; website.  In &lt;a href="http://jhippjava.blogspot.com/2011/08/asynchronous-javascript-and-xml-ajax.html"&gt; my post&lt;/a&gt; on their &lt;a href="http://www.w3schools.com/ajax/default.asp"&gt;AJAX&lt;/a&gt;  tutorial, I bemoaned that fact that their &lt;i&gt;exchanging data with a server&lt;/i&gt;  example only read data from a "measly old text file", rather than a database.   However, had I dug deeper in my first post on PHP, I might have noticed that the &lt;a href="http://www.w3schools.com/PHP/default.asp"&gt;w3schools tutorial on the  topic&lt;/a&gt; gives an example of communicating with a database, using AJAX and PHP, in  &lt;a href="http://www.w3schools.com/php/php_ajax_database.asp"&gt;one of the advanced sections&lt;/a&gt;.   I shall now work through that example.&lt;/p&gt;  &lt;p&gt;My first step is to cut and paste their exact web code to see if it works.   Should I post it here?  When I first began this blog, I posted almost no  code, but included an array of links to sources.  A couple of years later,  when I went back to reread some of my early posts, I found that many of my  sources had changed their URL or disappeared altogether.  So I started  posting code.  But the question then arises, should the full 30 or more  line copyright notice be included with every code snippet.  I think not.   That would render the blog unreadable.  "Fair Practice Law" in most  countries allows you to copy snippets, certainly from literature, as long as you  acknowledge your source.  Would that apply to a full working web page?   Possibly not.  I shall refrain from quoting it, and apologise if the source  subsequently disappears.&lt;/p&gt;  &lt;p&gt;Of course I have posted code for some working web pages in my &lt;a href="http://jhippjava.blogspot.com/2011/09/simple-web-application-data-display.html"&gt; last few entries&lt;/a&gt;, (and in fact below) but I think one, of a couple of  important questions, is did I copy something and  change it, or did I write something of my own and draw inspiration from a  source.  It is something of a moot point, but I think there are a couple of  things to bear in mind.  Did I begin with a downloaded file, or did I begin  with a clean sheet of paper?  In this case I began clean, because of the  database communication differences.  A second important question is did I use a single  source for inspiration?  Again, I used more than one source, for practical  and cosmetic reasons.&lt;/p&gt; &lt;p&gt;Meanwhile, back in reality, I have cut and pasted the HTML, and it works.  And while I am not posting the  HTML, I shall post a screen  shot (below), because on an empty page it looks a bit different.  But it certainly works.  I had a quick look at the dropdown box, and  the names were all there as in  &lt;a href="http://www.w3schools.com/PHP/default.asp"&gt;the tutorial&lt;/a&gt;.  Obviously  I refrained from selecting one because I haven't written a PHP file.  And  this is where I have to put my thinking cap on, because for this to be useful to  me, it has to work with my data, and there are no "names" in my database.&lt;/p&gt; &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-KVIl0lKsRGk/TnWgi9qa7-I/AAAAAAAAAK4/Dh4sy4nybEE/s1600/pic41.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 249px; height: 233px;" src="http://1.bp.blogspot.com/-KVIl0lKsRGk/TnWgi9qa7-I/AAAAAAAAAK4/Dh4sy4nybEE/s320/pic41.jpg" alt="" id="BLOGGER_PHOTO_ID_5653601429762011106" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Getting it to work for me involved one major change to the HTML, and a few  cosmetic changes.  The major change was to rewrite the dropdown box from  scratch to make it meaningful for my data.  The cosmetic changes were to  variable names - not strictly necessary, but they always say variable names  should try to reflect what they contain.&lt;/p&gt; &lt;p&gt;An important point to note here, for the unwary, is that parameters passed by  AJAX seem to in the form of strings.  The index field in my database is an  integer, so I was tempted to try and pass an integer through AJAX.  But  from &lt;a href="http://jhippjava.blogspot.com/2011/08/asynchronous-javascript-and-xml-ajax.html"&gt;my notes on AJAX&lt;/a&gt; the syntax of the open method is:&lt;/p&gt; &lt;p&gt;&lt;code&gt;xmlhttp.open("METHOD","URL",async); &lt;/code&gt;&lt;/p&gt; &lt;p&gt;Where &lt;code&gt;URL&lt;/code&gt; is, and will always be a string.  So in my code  (shown below), my attempts to change the idx variable (in the function, and in  the dropdown box) to a number were futile, and had to be abandoned.  The  variable was passed as a string, but the character was included in the SQL  statement (shown further below) as a number.&lt;/p&gt; &lt;p&gt;A final point is that I included some diagnostic lines, but these were pretty  redundant as PHP errors were picked up in the parse, and SQL errors were also  caught by an error trap in the code.  After all this, my HTML was:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;AJAXPHPexpt1&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;function showItem(idx)&lt;br /&gt;{&lt;br /&gt;if (idx=="")&lt;br /&gt;{&lt;br /&gt;document.getElementById("cbxItem").innerHTML="";&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;if (window.XMLHttpRequest)&lt;br /&gt;{// code for IE7+, Firefox, Chrome, Opera, Safari&lt;br /&gt;xmlhttp=new XMLHttpRequest();&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{// code for IE6, IE5&lt;br /&gt;xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");&lt;br /&gt;}&lt;br /&gt;xmlhttp.onreadystatechange=function()&lt;br /&gt;{&lt;br /&gt;if (xmlhttp.readyState==4 &amp;amp;&amp;amp; xmlhttp.status==200)&lt;br /&gt;{&lt;br /&gt;document.getElementById("cbxItem").innerHTML=xmlhttp.responseText;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;xmlhttp.open("GET","getitem.php?id="+idx,true);&lt;br /&gt;xmlhttp.send();&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;form&amp;gt;&lt;br /&gt;&amp;lt;select name="itemselection" onchange="showItem(this.value)"&amp;gt;&lt;br /&gt;&amp;lt;option value=""&amp;gt;Select an item:&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;option value="2"&amp;gt;2+2=&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;option value="4"&amp;gt;2+3=&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;option value="7"&amp;gt;4+3=&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;/select&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;div id="cbxItem"&amp;gt;&amp;lt;b&amp;gt;Item info will be listed here.&amp;lt;/b&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt; &lt;/code&gt;&lt;/p&gt; &lt;p&gt;And my PHP code was:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;$id = $_GET['id'];&lt;br /&gt;include('dbinfo.php');// collect database variables and connect.&lt;br /&gt;$con = mysql_connect( $dbhost, $dbuser, $dbpass );&lt;br /&gt;if (!$con)&lt;br /&gt;{&lt;br /&gt;die('Could not connect: ' . mysql_error());&lt;br /&gt;}&lt;br /&gt;mysql_select_db($dbname, $con);&lt;br /&gt;$query = "SELECT * FROM mytable WHERE Itemid=".$id;&lt;br /&gt;$result = mysql_query($query) or die(mysql_error());&lt;br /&gt;echo"&amp;lt;p&amp;gt;The item id is now: $id &amp;lt;/p&amp;gt;";&lt;br /&gt;echo"&amp;lt;p&amp;gt;The query is: $query &amp;lt;/p&amp;gt;";&lt;br /&gt;echo&lt;br /&gt;'&amp;lt;table style="text-align:center;"&amp;gt;&lt;br /&gt;&amp;lt;tr bgcolor="#CCCCCC"&amp;gt;&lt;br /&gt;&amp;lt;td width="60"&amp;gt;&amp;lt;strong&amp;gt;Itemid&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td width="60"&amp;gt;&amp;lt;strong&amp;gt;Partid&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td width="60"&amp;gt;&amp;lt;strong&amp;gt;OpCode&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td width="60"&amp;gt;&amp;lt;strong&amp;gt;Itemdet&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td width="60"&amp;gt;&amp;lt;strong&amp;gt;Raw&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td width="60"&amp;gt;&amp;lt;strong&amp;gt;Rate&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;/tr&amp;gt;';&lt;br /&gt;while($row = mysql_fetch_array($result))&lt;br /&gt;{&lt;br /&gt;echo "&amp;lt;tr&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['Itemid'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['OpCode'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['Partid'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['Itemdet'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['Raw'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['Rate'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;/tr&amp;gt;";&lt;br /&gt;}&lt;br /&gt;mysql_close($con);&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;And after selecting an item, the page was as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-ZHBLXq4Vdug/TnWgi3GYJNI/AAAAAAAAALA/xfcE-RiXJn4/s1600/pic42.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 272px;" src="http://3.bp.blogspot.com/-ZHBLXq4Vdug/TnWgi3GYJNI/AAAAAAAAALA/xfcE-RiXJn4/s320/pic42.jpg" alt="" id="BLOGGER_PHOTO_ID_5653601428000220370" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-7610151307421164138?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/7610151307421164138/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=7610151307421164138' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/7610151307421164138'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/7610151307421164138'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/php-and-javascriptajax-database-query.html' title='PHP and JavaScript/AJAX database query'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-KVIl0lKsRGk/TnWgi9qa7-I/AAAAAAAAAK4/Dh4sy4nybEE/s72-c/pic41.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-731996261592598588</id><published>2011-09-17T00:22:00.000-07:00</published><updated>2011-10-25T23:03:48.157-07:00</updated><title type='text'>Simple Web Application – Delete Data line</title><content type='html'>Once again I should like to acknowledge the &lt;a href="http://www.vt.edu/"&gt;Virginia Tech&lt;/a&gt; &lt;a href="http://www.hosting.vt.edu/tutorials/phpmysql/#exampleapp"&gt;Simple Web Application&lt;/a&gt;  sample code, which provided a template for this little project, which has really helped  to improve my practical understanding of PHP.&lt;p&gt; Having said that, the code, required to delete lines from the database, is  pretty slim. Once again I bloated it out with some diagnostic HTML, just to check the query.  I hate running blind.&lt;/p&gt;&lt;p&gt; The bloated code was as follows:&lt;/p&gt;&lt;p&gt; &lt;code&gt;&amp;lt;?php&lt;br /&gt;$id = $_GET['id'];&lt;br /&gt;if (empty($id)) {&lt;br /&gt;Header("Location: listcontacts.php");&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;include('dbinfo.php');// collect database variables and connect.&lt;br /&gt;$con = mysql_connect( $dbhost, $dbuser, $dbpass );&lt;br /&gt;if (!$con)&lt;br /&gt;{&lt;br /&gt;die('Could not connect: ' . mysql_error());&lt;br /&gt;}&lt;br /&gt;mysql_select_db($dbname, $con);&lt;br /&gt;$query = "DELETE FROM mytable WHERE Itemid=".$id;&lt;br /&gt;$result = mysql_query($query) or die(mysql_error());&lt;br /&gt;mysql_close($con); //close connection because job finished&lt;br /&gt;// Header("Location: jsphp4.php"); //return to main display form&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;Delete item diagnostics&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;h1&amp;gt;Delete Item&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;The item id is now: &amp;lt;?php echo $id ?&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;The query is: &amp;lt;?php echo $query ?&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt; And the page was as shown below:&lt;/p&gt;&lt;p&gt; &lt;a href="http://4.bp.blogspot.com/-NSvKoDtc_vY/TnRLrD0R2eI/AAAAAAAAAKw/FizwT6qxvjw/s1600/pic31.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 249px;" src="http://4.bp.blogspot.com/-NSvKoDtc_vY/TnRLrD0R2eI/AAAAAAAAAKw/FizwT6qxvjw/s320/pic31.jpg" alt="" id="BLOGGER_PHOTO_ID_5653226635387853282" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt; After checking the query, the slimmed down “production” code was:&lt;/p&gt;&lt;p&gt; &lt;code&gt;&amp;lt;?php&lt;br /&gt;$id = $_GET['id'];&lt;br /&gt;if (empty($id)) {&lt;br /&gt;Header("Location: listcontacts.php");&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;include('dbinfo.php');// collect database variables and connect.&lt;br /&gt;$con = mysql_connect( $dbhost, $dbuser, $dbpass );&lt;br /&gt;if (!$con)&lt;br /&gt;{&lt;br /&gt;die('Could not connect: ' . mysql_error());&lt;br /&gt;}&lt;br /&gt;mysql_select_db($dbname, $con);&lt;br /&gt;$query = "DELETE FROM mytable WHERE Itemid=".$id;&lt;br /&gt;$result = mysql_query($query) or die(mysql_error());&lt;br /&gt;mysql_close($con); //close connection because job finished&lt;br /&gt;Header("Location: jsphp4.php"); //return to main display form&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt; And of course there is no pic to show, because after the delete code has run we  are returned to  the main page.  &lt;/p&gt;&lt;p&gt; In fact this whole exercise derived from a desire to check how that is done -  modifying data in a database while (having the illusion of) remaining on the  same page.&lt;/p&gt; &lt;p&gt;So now I have called a JavaScript function from an Applet, and I have called  a PHP script, which has modified data in a database, from a button on a web  page.  &lt;/p&gt; &lt;p&gt;My next step is to call a PHP script from an Applet.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-731996261592598588?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/731996261592598588/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=731996261592598588' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/731996261592598588'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/731996261592598588'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/simple-web-application-delete-data-line.html' title='Simple Web Application – Delete Data line'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-NSvKoDtc_vY/TnRLrD0R2eI/AAAAAAAAAKw/FizwT6qxvjw/s72-c/pic31.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-7188249697839064233</id><published>2011-09-16T01:06:00.000-07:00</published><updated>2011-10-25T23:02:44.510-07:00</updated><title type='text'>Simple Web Application – Add Data Form</title><content type='html'>While I must still acknowledge the &lt;a href="http://www.vt.edu/"&gt;Virginia Tech&lt;/a&gt; &lt;a href="http://www.hosting.vt.edu/tutorials/phpmysql/#exampleapp"&gt;Simple Web Application&lt;/a&gt;  sample  code, at this stage in the project I was primarily cutting and pasting from the  code shown in my  &lt;a href="http://jhippjava.blogspot.com/2011/09/simple-web-application-data-edit-form.html"&gt;previous posts&lt;/a&gt;, and manually making a few small changes from  the sample code.&lt;p&gt; The code used in the Add data line form is very similar to that for the Edit  data line form, except that there is no existing data to display, and the SQL  command is INSERT rather than UPDATE.  &lt;/p&gt;&lt;p&gt; I also removed the input validation code.  Any data entered manually into  my database is bogus and must be deleted after this exercise has finished, so it  really doesn't matter what fields are filled or left empty.&lt;/p&gt;&lt;p&gt; With no data to display, there no need to confirm that a data line was being  correctly passed from the main display form, and no need to confirm that the  line was being correctly read. I therefore left in just a couple of diagnostic  messages at the top of the form:&lt;/p&gt;&lt;p&gt; &lt;code&gt;&amp;lt;p&amp;gt;The query is: &amp;lt;?php echo $query ?&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;Status is: &amp;lt;?php echo $jonathan ?&amp;gt; &amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt; Of course to view these lines after clicking the add button, it is necessary to  comment out the instruction to return to the main form right after adding data  as follows:&lt;/p&gt;&lt;p&gt; &lt;code&gt;// Header("Location: jsphp4.php"); //return to main display form&lt;/code&gt;&lt;/p&gt;&lt;p&gt; When everything is working the comment strokes (on the left) can be removed, and    the diagnostic lines can be removed from the HTML.&lt;/p&gt;&lt;p&gt; My working (diagnostic) code was as follows:&lt;/p&gt; &lt;p&gt; &lt;code&gt;&amp;lt;?php&lt;br /&gt;include('dbinfo.php');// collect database variables and connect.&lt;br /&gt;$con = mysql_connect( $dbhost, $dbuser, $dbpass );&lt;br /&gt;if (!$con)&lt;br /&gt;{&lt;br /&gt;die('Could not connect: ' . mysql_error());&lt;br /&gt;}&lt;br /&gt;mysql_select_db($dbname, $con);&lt;br /&gt;if (isset($_POST['addcontact'])) { // run this when the user hits the "Add  Contact" button&lt;br /&gt;$jonathan="Add loop";&lt;br /&gt;$Partid = $_POST['Partid'];&lt;br /&gt;$OpCode = $_POST['OpCode'];&lt;br /&gt;$Itemdet = $_POST['Itemdet'];&lt;br /&gt;$Raw = $_POST['Raw'];&lt;br /&gt;$Rate = $_POST['Rate']; // input validation removed from under here&lt;br /&gt;$query = "INSERT INTO mytable (Partid, OpCode, Itemdet, Raw, Rate) VALUES (".$Partid.",".$OpCode.",'".$Itemdet."',".$Raw.",".$Rate.")";&lt;br /&gt;$result = mysql_query($query) or die(mysql_error()); //adds form inputs&lt;br /&gt;mysql_close($con); //close connection because job finished&lt;br /&gt;Header("Location: jsphp4.php"); //return to main display form&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;Add a Line&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;h1&amp;gt;Add a Line&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;The query is: &amp;lt;?php echo $query ?&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;Status is: &amp;lt;?php echo $jonathan ?&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;form name="form1" method="post" action="&amp;lt;?php echo $_SERVER['PHP_SELF']; ?&amp;gt;"&amp;gt;&lt;br /&gt;&amp;lt;table style="text-align:right;"&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Partid:&amp;lt;input name="Partid" type="text" value="&amp;lt;?php echo $Partid;  ?&amp;gt;"&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Opcode:&amp;lt;input name="OpCode" type="text" value="&amp;lt;?php echo $OpCode;  ?&amp;gt;"&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Itemdet:&amp;lt;input name="Itemdet" type="text" value="&amp;lt;?php echo $Itemdet;  ?&amp;gt;"&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Raw:&amp;lt;input name="Raw" type="text" value="&amp;lt;?php echo $Raw; ?&amp;gt;"&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Rate:&amp;lt;input name="Rate" type="text" value="&amp;lt;?php echo $Rate;  ?&amp;gt;"&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;input type="submit" name="addcontact"  value="Add Line"&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;&amp;lt;a href="jsphp4.php"&amp;gt;Click here to return to List&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;And after clicking the Add Line button, the page, with diagnostic code, was as shown below:&lt;/p&gt; &lt;p&gt; &lt;a href="http://2.bp.blogspot.com/-OPjIAHB1_4Q/TnMEnRaTW7I/AAAAAAAAAKo/93_Qtpsi3Lg/s1600/pic21.jpg"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 260px; height: 356px;" src="http://2.bp.blogspot.com/-OPjIAHB1_4Q/TnMEnRaTW7I/AAAAAAAAAKo/93_Qtpsi3Lg/s320/pic21.jpg" alt="" id="BLOGGER_PHOTO_ID_5652867030015237042" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt; After removing the diagnostic code the page came up as shown below:&lt;/p&gt;&lt;p&gt; &lt;a href="http://1.bp.blogspot.com/-ZZgXZQTdB9Q/TnMEnHsrfJI/AAAAAAAAAKg/QQ_zv0gg7U4/s1600/pic22.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 257px; height: 320px;" src="http://1.bp.blogspot.com/-ZZgXZQTdB9Q/TnMEnHsrfJI/AAAAAAAAAKg/QQ_zv0gg7U4/s320/pic22.jpg" alt="" id="BLOGGER_PHOTO_ID_5652867027407961234" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-7188249697839064233?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/7188249697839064233/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=7188249697839064233' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/7188249697839064233'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/7188249697839064233'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/simple-web-application-add-data-form.html' title='Simple Web Application – Add Data Form'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-OPjIAHB1_4Q/TnMEnRaTW7I/AAAAAAAAAKo/93_Qtpsi3Lg/s72-c/pic21.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-4534308480907680426</id><published>2011-09-15T18:13:00.001-07:00</published><updated>2011-10-25T23:02:06.199-07:00</updated><title type='text'>Simple Web Application – Data edit form</title><content type='html'>The &lt;a href="http://www.vt.edu/"&gt;Virginia Tech&lt;/a&gt; &lt;a href="http://www.hosting.vt.edu/tutorials/phpmysql/#exampleapp"&gt;Simple Web Application&lt;/a&gt; sample code works perfectly on their  server, but as I reported in my previous post, getting something similar to run  with my own database has been a fairly long and frustrating task.&lt;p&gt; I said in &lt;a href="http://jhippjava.blogspot.com/2011/09/simple-web-application-data-display.html"&gt;my last post&lt;/a&gt; that I constructed my own  &lt;a href="http://www.phpbuilder.com/columns/allan20010115.php3"&gt;PHP PEAR database layer&lt;/a&gt;, as a  result of which, my code and the sample code diverged from an early point.  Specifically:&lt;/p&gt;&lt;code&gt; include('dbconnect.php');&lt;/code&gt;&lt;p&gt; was stretched out to:&lt;/p&gt;&lt;p&gt; &lt;code&gt;include('dbinfo.php');&lt;br /&gt;$con = mysql_connect( $dbhost, $dbuser, $dbpass );&lt;br /&gt;if (!$con)&lt;br /&gt;{&lt;br /&gt;die('Could not connect: ' . mysql_error());&lt;br /&gt;}&lt;br /&gt;mysql_select_db($dbname, $con);&lt;/code&gt;&lt;/p&gt;&lt;p&gt; I had some specific problems with certain lines of the sample code. One was:&lt;/p&gt;&lt;p&gt; &lt;code&gt;$result = $database-&amp;gt;query($query);&lt;/code&gt;&lt;/p&gt;&lt;p&gt; I didn’t understand the funny little &lt;code&gt;-&amp;gt;&lt;/code&gt; in this line (I think it might have  something to do with Perl, which takes it beyond the scope of this post), nor  the general syntax, so I replaced it with:&lt;/p&gt;&lt;p&gt; &lt;code&gt;$result = mysql_query($query) or die(mysql_error());&lt;/code&gt;&lt;/p&gt;&lt;p&gt; Another example was&lt;/p&gt;&lt;p&gt; &lt;code&gt;$contact = $result-&amp;gt;fetchRow(DB_FETCHMODE_ASSOC,0);&lt;/code&gt;&lt;/p&gt;&lt;p&gt; Which I replaced with&lt;/p&gt;&lt;p&gt; &lt;code&gt;$contact = mysql_fetch_row($result);&lt;/code&gt;&lt;/p&gt;&lt;p&gt; I also replaced the text references to array members:&lt;/p&gt;&lt;p&gt; &lt;code&gt;$Itemid = $contact['Itemid'];&lt;/code&gt;&lt;/p&gt;&lt;p&gt; With array member indices:&lt;/p&gt;&lt;p&gt; &lt;code&gt;$Itemid = $contact[0];&lt;/code&gt;&lt;/p&gt;&lt;p&gt; Getting the form to work at all was a long slow process, so I added a series of  diagnostic variables displayed in notes above the form. For example:&lt;/p&gt;&lt;p&gt; &lt;code&gt;$jonathan="Default loop";&lt;/code&gt;&lt;/p&gt;&lt;p&gt; These enabled me to track which branches of code were executing, and which  variables were being properly filled.&lt;/p&gt;&lt;p&gt; Further divergence derived from differences in the style of the data. The sample  code set out to teach among other things the different methods of entering  personal data on a form (radio buttons etc.), whereas my data is mainly numeric.  This first required me modify the SQL to accommodate my data types. And on the  cosmetic side, because my data is uniform in style, I wanted a uniform look. I  therefore put my data entry fields into a table, whereas the sample code used a  lot of line breaks.&lt;/p&gt;&lt;p&gt; After all this, my code was as follows:&lt;/p&gt; &lt;p&gt; &lt;code&gt;&amp;lt;?php&lt;br /&gt;// get contact id&lt;br /&gt;$id = $_GET['id'];&lt;br /&gt;if (!empty($id)) { $_SESSION['recordId']=$id; }&lt;br /&gt;else { $id = $_SESSION['recordId']; }&lt;br /&gt;// if the script has been called without ID or the user hit "Cancel" just return  to listing&lt;br /&gt;if (empty($id) || isset($_POST['cancel'])) {&lt;br /&gt;Header("Location: jsphp4.php");&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;include('dbinfo.php');&lt;br /&gt;$con = mysql_connect( $dbhost, $dbuser, $dbpass );&lt;br /&gt;if (!$con)&lt;br /&gt;{&lt;br /&gt;die('Could not connect: ' . mysql_error());&lt;br /&gt;}&lt;br /&gt;mysql_select_db($dbname, $con);&lt;br /&gt;$query = "SELECT * FROM mytable WHERE Itemid=".$id;&lt;br /&gt;$result = mysql_query($query) or die(mysql_error());&lt;br /&gt;$contact = mysql_fetch_row($result);&lt;br /&gt;$Itemid = $contact[0];&lt;br /&gt;$OpCode = $contact[1];&lt;br /&gt;$Partid = $contact[2];&lt;br /&gt;$Itemdet = $contact[3];&lt;br /&gt;$Raw = $contact[4];&lt;br /&gt;$Rate = $contact[5];&lt;br /&gt;mysql_close($con);&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;Edit Items Table&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;a href="jsphp4.php"&amp;gt;Add a Line&amp;lt;/a&amp;gt; | &amp;lt;a href="jsphp4.php"&amp;gt;Session Data&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;h1&amp;gt;Edit Item&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;The item id is now: &amp;lt;?php echo $id ?&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;The query is: &amp;lt;?php echo $query ?&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;The op code is: &amp;lt;?php echo $query ?&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;form name="form1" method="post" action="&amp;lt;?php echo $_SERVER['PHP_SELF']; ?&amp;gt;"&amp;gt;&lt;br /&gt;&amp;lt;table style="text-align:right;"&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Itemid:&amp;lt;input name="Itemid" type="text" value="&amp;lt;?php echo $Itemid;  ?&amp;gt;"&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Opcode:&amp;lt;input name="OpCode" type="text" value="&amp;lt;?php echo $OpCode;  ?&amp;gt;"&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Partid:&amp;lt;input name="Partid" type="text" value="&amp;lt;?php echo $Partid;  ?&amp;gt;"&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Itemdet:&amp;lt;input name="Itemdet" type="text" value="&amp;lt;?php echo $Itemdet;  ?&amp;gt;"&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Raw:&amp;lt;input name="Raw" type="text" value="&amp;lt;?php echo $Raw; ?&amp;gt;"&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Rate:&amp;lt;input name="Rate" type="text" value="&amp;lt;?php echo $Rate;  ?&amp;gt;"&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;input type="hidden" name="id" value="&amp;lt;?php echo $id; ?&amp;gt;"&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;input type="submit" name="ok" value=" OK "&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;input type="submit" name="cancel" value="Cancel"&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;And it looked like this:&lt;/p&gt;&lt;p&gt; &lt;a href="http://1.bp.blogspot.com/-KYR3uJapAHA/TnKi4xhxsaI/AAAAAAAAAKY/JE1OwwjRjec/s1600/pic11.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 206px; height: 320px;" src="http://1.bp.blogspot.com/-KYR3uJapAHA/TnKi4xhxsaI/AAAAAAAAAKY/JE1OwwjRjec/s320/pic11.jpg" alt="" id="BLOGGER_PHOTO_ID_5652759578554773922" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-4534308480907680426?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/4534308480907680426/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=4534308480907680426' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4534308480907680426'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4534308480907680426'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/simple-web-application-data-edit-form.html' title='Simple Web Application – Data edit form'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-KYR3uJapAHA/TnKi4xhxsaI/AAAAAAAAAKY/JE1OwwjRjec/s72-c/pic11.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-3765960101092245701</id><published>2011-09-14T19:18:00.000-07:00</published><updated>2011-10-25T23:01:04.497-07:00</updated><title type='text'>Simple Web Application – Data Display page</title><content type='html'>I can read tutorials 'til I'm blue in the face, but unless I try to adapt the  sample code to do something completely different, I don't retain anything. The  live "&lt;a href="http://www.w3schools.com/html/default.asp"&gt;Try it yourself&lt;/a&gt;"  windows are quite fun, but unless I can get code running on my own or my ISP's  server, I can't expose my misunderstandings or the gaps in my knowledge. &lt;p&gt;The &lt;a href="http://www.hosting.vt.edu/tutorials/phpmysql/#exampleapp"&gt; Virginia Tech simple web application&lt;/a&gt; sample code works perfectly on their  server, but recreating something to perform similar functions with my own  database on my own server has been a fairly long and frustrating job.&lt;/p&gt; &lt;p&gt;I said in my last post that I could not see any gaps in the sample code. On  closer inspection, I have found a couple, of which the most important was their  connection code. They refer to a &lt;a href="http://www.phpbuilder.com/columns/allan20010115.php3"&gt;PHP PEAR database  layer&lt;/a&gt; in the text and a file called DB.php in their code, but they don’t  show what is in the file. So I followed the PHP PEAR link and constructed my own  file based on the template given there:&lt;/p&gt; &lt;p&gt; &lt;code&gt;&amp;lt;?php&lt;br /&gt;$dbhost = 'localhost';&lt;br /&gt;$dbuser = 'theuser';&lt;br /&gt;$dbpass = 'thepassword';&lt;br /&gt;$dbname = 'phptst';&lt;br /&gt;?&amp;gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;This meant that my code and the sample code were beginning to diverge from a  fundamental point. Because my PHP PEAR database layer was different, my  connection code in the main page was different. Because of that, my query code  had to be different, and because of that, my display code had to be different.  In fact in the end I based the whole thing on the example previously quoted on  my &lt;a href="http://jhippjava.blogspot.com/2011/08/playing-with-php.html"&gt;Playing  with PHP&lt;/a&gt; entry.&lt;/p&gt; &lt;p&gt;In the end, the code in my display table was like the inverse, or a mirror  image of the &lt;a href="http://www.hosting.vt.edu/tutorials/phpmysql/#exampleapp"&gt; sample code&lt;/a&gt;. Their display table was written in HTML, peppered with PHP  variables. My display table was a long PHP statement, peppered with HTML  strings.&lt;/p&gt; &lt;p&gt;My code was as shown below:&lt;/p&gt; &lt;p&gt; &lt;code&gt;&amp;lt;?php&lt;br /&gt;// if the user hasn't specified any "sort" the default is "Partid"&lt;br /&gt;if ( isset($_GET['sort']) &amp;amp;&amp;amp; $_GET['sort']=='OpCode' ) { $_SESSION['sort'] = 'OpCode';  }&lt;br /&gt;else { $_SESSION['sort'] = 'Partid'; }&lt;br /&gt;include('dbinfo.php');&lt;br /&gt;$con = mysql_connect( $dbhost, $dbuser, $dbpass );&lt;br /&gt;if (!$con)&lt;br /&gt;{&lt;br /&gt;die('Could not connect: ' . mysql_error());&lt;br /&gt;}&lt;br /&gt;mysql_select_db($dbname, $con);&lt;br /&gt;$result = mysql_query("SELECT * FROM mytable") or die(mysql_error());&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;Session Data&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;script language="JavaScript"&amp;gt;&lt;br /&gt;&amp;lt;!--&lt;br /&gt;function confirmdelete(id)&lt;br /&gt;{&lt;br /&gt;var c = confirm("Do you really want to delete this line?");&lt;br /&gt;if (c) {&lt;br /&gt;window.location="deletecontact.php?id="+id;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;//--&amp;gt;&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;a href="addcontact.php"&amp;gt;Add a Line&amp;lt;/a&amp;gt; | My Items&lt;br /&gt;&amp;lt;h1&amp;gt;Session Data&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;table style="text-align:center;"&amp;gt;&lt;br /&gt;&amp;lt;tr bgcolor="#CCCCCC"&amp;gt;&lt;br /&gt;&amp;lt;td width="70"&amp;gt;&amp;lt;strong&amp;gt;Itemid&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td width="70"&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;?php if ($_SESSION['sort']!='OpCode') {  echo '&amp;lt;a href="',$_SERVER['PHP_SELF'],'?sort=OpCode"&amp;gt;Partid&amp;lt;/a&amp;gt;'; }  else { echo 'OpCode ↓'; } ?&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td width="70"&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;?php if ($_SESSION['sort']!='Partid') {  echo '&amp;lt;a href="',$_SERVER['PHP_SELF'],'?sort=Partid"&amp;gt;OpCode&amp;lt;/a&amp;gt;'; }  else { echo 'OpCode ↓'; } ?&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td width="70"&amp;gt;&amp;lt;strong&amp;gt;Itemdet&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td width="70"&amp;gt;&amp;lt;strong&amp;gt;Raw&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td width="70"&amp;gt;&amp;lt;strong&amp;gt;Rate&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td width="70"&amp;gt;&amp;lt;strong&amp;gt;Edit&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td width="70"&amp;gt;&amp;lt;strong&amp;gt;Delete&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;while($row = mysql_fetch_array($result))&lt;br /&gt;{&lt;br /&gt;echo "&amp;lt;tr&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['Itemid'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['OpCode'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['Partid'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['Itemdet'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['Raw'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['Rate'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo '&amp;lt;td&amp;gt;&amp;lt;a href="editcontact.php?id=' . $row['Itemid'] . '"&amp;gt;edit&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;';&lt;br /&gt;echo '&amp;lt;td&amp;gt;&amp;lt;a href="deletecontact.php?id=' . $row['Itemid'] . '"&amp;gt;delete&amp;lt;/td&amp;gt;';&lt;br /&gt;echo "&amp;lt;/tr&amp;gt;";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;And the page looked like this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-FnFbv7A66mI/TnFg6DHpYWI/AAAAAAAAAKQ/fCLBUEB-4dM/s1600/pic01.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 214px;" src="http://1.bp.blogspot.com/-FnFbv7A66mI/TnFg6DHpYWI/AAAAAAAAAKQ/fCLBUEB-4dM/s320/pic01.jpg" alt="" id="BLOGGER_PHOTO_ID_5652405557712740706" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-3765960101092245701?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/3765960101092245701/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=3765960101092245701' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3765960101092245701'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3765960101092245701'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/simple-web-application-data-display.html' title='Simple Web Application – Data Display page'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-FnFbv7A66mI/TnFg6DHpYWI/AAAAAAAAAKQ/fCLBUEB-4dM/s72-c/pic01.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-4915037511992317654</id><published>2011-09-09T13:14:00.000-07:00</published><updated>2011-09-16T02:55:07.221-07:00</updated><title type='text'>A closer look at PHP database update options</title><content type='html'>&lt;p&gt;A frustration I've had with most tutorials on using JavaScript with PHP to  update a database is that the "add data" function nearly always calls a new  page. In &lt;a href="http://www.interactived.com/jartest.htm"&gt;my application&lt;/a&gt;, I  want data added to a database quietly in the background, and I certainly don't  want the user dragged away from &lt;a href="http://www.interactived.com/jartest.htm"&gt;the Applet page&lt;/a&gt; every time  a line is added to the database.&lt;/p&gt;&lt;p&gt; After much searching, and searches excluding terms such as "forum", (forum  questions seem to dominate this topic in Google), I found &lt;a href="http://www.hosting.vt.edu/tutorials/phpmysql/"&gt;an excellent page&lt;/a&gt;  hosted by &lt;a href="http://www.vt.edu/"&gt;Virginia Tech&lt;/a&gt;. This is a really good  single page tutorial, which takes the reader through all the basics of PHP, from &lt;code&gt;echo "Hello World!";&lt;/code&gt; to a &lt;a href="http://www.hosting.vt.edu/tutorials/phpmysql/#exampleapp"&gt;simple web  application&lt;/a&gt;, which includes all the essential functions of adding data,  displaying data, editing data and deleting records. Better still, for each task,  it includes the PHP source code, produced HTML, and rendered HTML. There are no  zip files to download, and certainly at first glance, no holes or gaps in the  code.&lt;/p&gt;&lt;p&gt; Most importantly, for me, &lt;a href="http://www.hosting.vt.edu/tutorials/phpmysql/"&gt;the tutorial&lt;/a&gt; makes  explicitly clear the code required to stay on the same page while information is  being posted from a form. So if information is entered on an ordinary HTML page  (with a name and extension like myForm.htm) and is to be processed by a page  called myCode.php, the opening form tag should look like this:&lt;/p&gt;&lt;p&gt; &lt;code&gt;&amp;lt;form method="post" action="myCode.php"&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt; But if the posting is to be handled on a form containing the processing code  (which will need the extension .php - so it might be called something like  myCodedForm.php), the opening form tag should look like this:&lt;/p&gt;&lt;p&gt; &lt;code&gt;&amp;lt;form method="post" action="&amp;lt;?php echo $_SERVER['PHP_SELF']; ?&amp;gt;"&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt; Alternatively it might look like this:&lt;/p&gt;&lt;p&gt; &lt;code&gt;&amp;lt;form method="post" action="myCodedForm.php"&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt; My plan is to adapt the examples in &lt;a href="http://www.hosting.vt.edu/tutorials/phpmysql/"&gt;this tutorial&lt;/a&gt; to the  creation of a dummy application, which adds lines to my own database, and to  describe my progress here. I shall skip the database creation steps, because  that has already been described &lt;a href="http://jhippjava.blogspot.com/2011/07/creating-mysql-database-for-gui-applet.html"&gt; here&lt;/a&gt;. That was for a Derby database, but I also described connecting to a  MySQL version with PHP &lt;a href="http://jhippjava.blogspot.com/2011/08/playing-with-php.html"&gt;here&lt;/a&gt;.  I shall focus on the code used to add lines, to view the table contents, and to  delete lines.&lt;/p&gt;&lt;p&gt; My progress may be a little slow. I have read a couple of tutorials on  JavaScript and PHP, but my practical working knowledge is currently very  limited. I shall fiddle away, and post any interesting results as they arise.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-4915037511992317654?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/4915037511992317654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=4915037511992317654' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4915037511992317654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4915037511992317654'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/javascript-and-php.html' title='A closer look at PHP database update options'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-8205549733283933767</id><published>2011-09-06T01:25:00.000-07:00</published><updated>2011-09-06T01:32:17.675-07:00</updated><title type='text'>Applet to JavaScript Communication</title><content type='html'>The &lt;a href="http://www.raditha.com/java/alert.php"&gt;raditha.com&lt;/a&gt; site, to  which I referred in my &lt;a href="http://jhippjava.blogspot.com/2011/09/javascript-to-applet-communication.html"&gt;Javascript to Applet Communication - Example 2&lt;/a&gt;  entry, also includes a page on &lt;a href="http://www.raditha.com/java/mayscript.php"&gt;Applet to JavaScript  Communication&lt;/a&gt;, but I could not find the required HTML/JavaScript, either on the  page or in the &lt;a href="http://www.raditha.com/java/jsalert.zip"&gt;code files&lt;/a&gt;  included at the end of the page.  This was disappointing because overall it  is the best site I have found on what &lt;a href="https://developer.mozilla.org/en/LiveConnect"&gt;Mozilla&lt;/a&gt; calls &lt;a href="http://jhippjava.blogspot.com/2011/09/liveconnect-and-javascript-wrappers.html"&gt; LiveConnect&lt;/a&gt;. &lt;p&gt;The Java code works, and I shall cite a simplified (less graphics) version  here:&lt;/p&gt; &lt;p&gt;&lt;code&gt;import javax.swing.*;&lt;br /&gt;import netscape.javascript.JSObject;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;public class JSHelloWorld2 extends JApplet {&lt;br /&gt;JTextArea txt = new JTextArea(100,100);&lt;br /&gt;JButton btn = new JButton("Update Page");&lt;br /&gt;JSObject jso;&lt;br /&gt;public JSHelloWorld2() {&lt;br /&gt;txt.setText("Hello World");&lt;br /&gt;getContentPane().setLayout(new BorderLayout());&lt;br /&gt;getContentPane().add(txt);&lt;br /&gt;getContentPane().add(btn,BorderLayout.SOUTH);&lt;br /&gt;btn.addActionListener(new ActionListener() {&lt;br /&gt;public void actionPerformed(ActionEvent e) {&lt;br /&gt;if(jso != null )&lt;br /&gt;try {&lt;br /&gt;jso.call("updateWebPage", new String[] {txt.getText()});&lt;br /&gt;}&lt;br /&gt;catch (Exception ex) {&lt;br /&gt;ex.printStackTrace();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;});&lt;br /&gt;}&lt;br /&gt;public void init()&lt;br /&gt;{&lt;br /&gt;jso = JSObject.getWindow(this);&lt;br /&gt;}&lt;br /&gt;public void setText(String s)&lt;br /&gt;{&lt;br /&gt;txt.setText(s);&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And the HTML/JavaScript I used was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;function updateApplet()&lt;br /&gt;{&lt;br /&gt;document.jsap.setText(document.forms[0].txt1.value);&lt;br /&gt;}&lt;br /&gt;function updateWebPage(myArg)&lt;br /&gt;{&lt;br /&gt;document.getElementById("txt1").innerHTML=myArg;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;form&amp;gt;&lt;br /&gt;&amp;lt;table border=0 align='center' cellpadding=0 cellspacing=0 &amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&lt;br /&gt;&amp;lt;td valign='top' width=180&amp;gt;&lt;br /&gt;&amp;lt;table&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td style='text-align:center; background-color:#EEEEEE'&amp;gt;Applet&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&lt;br /&gt;&amp;lt;applet code="JSHelloWorld2.class"&lt;br /&gt;width="180" height="180" MAYSCRIPT style="border-width:0;" name="jsap" id="jsap"&amp;gt;&lt;br /&gt;&amp;lt;/applet&amp;gt; &amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;td valign='top' width=180&amp;gt;&lt;br /&gt;&amp;lt;table width=180&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td style='text-align:center; background-color:#EEEEEE'&amp;gt;JavaScript&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;textarea style='width:180px; height:150px' name='txt1' id='txt1'&amp;gt;Type  and click!&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td align='center'&amp;gt;&amp;lt;input type=button value='Update applet' onClick='updateApplet()'&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The &lt;code&gt;updateWebPage&lt;/code&gt; function is referred to in the Java code, but  I had to add the function to the web page, which when it first loads comes up as  shown below.&lt;/p&gt; &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-8Dgt0Dm3fOc/TmXZNZMBI-I/AAAAAAAAAKA/g7SH7554E7k/s1600/pic31.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 311px;" src="http://2.bp.blogspot.com/-8Dgt0Dm3fOc/TmXZNZMBI-I/AAAAAAAAAKA/g7SH7554E7k/s320/pic31.JPG" alt="" id="BLOGGER_PHOTO_ID_5649160131728974818" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is very similar to the page used to demonstrate &lt;a href="http://jhippjava.blogspot.com/2011/09/javascript-to-applet-communication.html"&gt; Javascript to Applet Communication&lt;/a&gt; except that there is an extra button in  the applet.  Clicking the button on the page has the same effect as before.   The text in the page text box is copied across to the applet.  But now if  you click the button on the Applet, the text from there is copied across to the  box on the page (see below).&lt;/p&gt; &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-zUyHZCccMhg/TmXZNT0mlUI/AAAAAAAAAKI/XJZo3x3xgSY/s1600/pic32.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 311px;" src="http://3.bp.blogspot.com/-zUyHZCccMhg/TmXZNT0mlUI/AAAAAAAAAKI/XJZo3x3xgSY/s320/pic32.JPG" alt="" id="BLOGGER_PHOTO_ID_5649160130288588098" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I could only get it to work once for every page load, but the fact that it  works at all is a major step forward for me.  I have at last succeeded in  calling a JavaScript function from within an applet.&lt;/p&gt; &lt;p&gt;My next step is to learn how to combine JavaScript with PHP to add lines to  my database.  Build this into a function, and I should be able to call it  from within &lt;a href="http://www.interactived.com/jartest.htm"&gt;my own applet&lt;/a&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-8205549733283933767?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/8205549733283933767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=8205549733283933767' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8205549733283933767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8205549733283933767'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/applet-to-javascript-communication.html' title='Applet to JavaScript Communication'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-8Dgt0Dm3fOc/TmXZNZMBI-I/AAAAAAAAAKA/g7SH7554E7k/s72-c/pic31.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-2235173039829983086</id><published>2011-09-05T21:45:00.001-07:00</published><updated>2011-09-05T21:45:44.339-07:00</updated><title type='text'>LiveConnect and JavaScript Wrappers</title><content type='html'>&lt;p&gt;From the &lt;a href="https://developer.mozilla.org/en/LiveConnect"&gt;LiveConnect page on the Mozilla web  site&lt;/a&gt;:&lt;/p&gt; &lt;p&gt; &lt;cite&gt;LiveConnect is the name of an application programming interface that provides  JavaScript with the ability to call methods of Java classes and vice-versa using  the existing Java infrastructure. &lt;/cite&gt; &lt;/p&gt; &lt;p&gt;&lt;cite&gt;LiveConnect use by applets is enabled via the use of the "MAYSCRIPT"  attribute in applet tags on an HTML page, following which the applet may refer  to classes in the netscape.javascript package to access Javascript objects, and  scripts may directly call applet methods (using the syntax  &lt;code&gt;document.applets.name.methodName()&lt;/code&gt;).&lt;/cite&gt;&lt;/p&gt; &lt;p&gt;From the  &lt;a href="https://developer.mozilla.org/en/JavaScript/Guide/LiveConnect_Overview"&gt; LiveConnect Overview page&lt;/a&gt; on the same site:&lt;/p&gt; &lt;div id="section_1"&gt;   &lt;cite&gt;In JavaScript, a wrapper is an object of the target language data    type that encloses an object of the source language. When programming in    JavaScript, you can use a wrapper object to access methods and fields of the    Java object; calling a method or accessing a property on the wrapper results    in a call on the Java object. On the Java side, JavaScript objects are wrapped    in an instance of the class &lt;code&gt;netscape.javascript.JSObject&lt;/code&gt; and    passed to Java.&lt;/cite&gt;&lt;p&gt;&lt;cite&gt;When a JavaScript object is sent to Java, the runtime engine    creates a Java wrapper of type &lt;code&gt;JSObject&lt;/code&gt;; when a &lt;code&gt;JSObject&lt;/code&gt;    is sent from Java to JavaScript, the runtime engine unwraps it to its original    JavaScript object type. The &lt;code&gt;JSObject&lt;/code&gt; class provides an interface    for invoking JavaScript methods and examining JavaScript properties.&lt;/cite&gt;&lt;/p&gt;&lt;/div&gt; &lt;p&gt;The &lt;a href="https://developer.mozilla.org/en/LiveConnect"&gt;LiveConnect page&lt;/a&gt;  has a number of dead links, including one called "LiveConnect Testcases", which  sounded interesting, and another called "Core JavaScript 1.5 Reference:  LiveConnect".  I found a current &lt;a href="https://developer.mozilla.org/en/JavaScript/Reference"&gt;JavaScript  Reference&lt;/a&gt; page, but I could find no reference to LiveConnect on the page.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-2235173039829983086?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/2235173039829983086/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=2235173039829983086' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/2235173039829983086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/2235173039829983086'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/liveconnect-and-javascript-wrappers.html' title='LiveConnect and JavaScript Wrappers'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-3388776467095642466</id><published>2011-09-04T21:25:00.000-07:00</published><updated>2011-09-04T21:41:50.483-07:00</updated><title type='text'>Javascript to Applet Communication - Example 2</title><content type='html'>I have found &lt;a href="http://www.raditha.com/java/alert.php"&gt;another article&lt;/a&gt;  on this topic where the code works and I shall cite it here because the Java  code is simpler and therefore perhaps more elegant than the &lt;a href="http://jhippjava.blogspot.com/2011/09/java-appletjavascript-communication.html"&gt; previous one&lt;/a&gt;.  &lt;p&gt;  &lt;code&gt;import javax.swing.*;&lt;br /&gt;import netscape.javascript.JSObject;&lt;br /&gt;&lt;br /&gt;public class JSHelloWorld extends JApplet {&lt;br /&gt;JTextArea txt = new JTextArea(100,100);&lt;br /&gt;public JSHelloWorld() {&lt;br /&gt;txt.setText("Hello World");&lt;br /&gt;getContentPane().add(txt);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void setText(String s)&lt;br /&gt;{&lt;br /&gt;txt.setText(s);&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The HTML, on the other hand is a bit more wordy, because the Applet and the  JavaScript form are laid out side by side, but I like it:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;function updateApplet()&lt;br /&gt;{&lt;br /&gt;document.jsap.setText(document.forms[0].txt1.value);&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;form&amp;gt;&lt;br /&gt;&amp;lt;table border=0 align='center' cellpadding=0 cellspacing=0 &amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td valign='top' width=180&amp;gt;&lt;br /&gt;&amp;lt;table&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td style='text-align:center; background-color:#EEEEEE'&amp;gt;Applet&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;applet code="JSHelloWorld.class"&lt;br /&gt;width="180" height="180" MAYSCRIPT style="border-width:0;" name="jsap" id="jsap"&amp;gt;&lt;br /&gt;&amp;lt;/applet&amp;gt; &amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/td&amp;gt;&amp;lt;td valign='top' width=180&amp;gt;&lt;br /&gt;&amp;lt;table width=180&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td style='text-align:center; background-color:#EEEEEE'&amp;gt;JavaScript&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;textarea style='width:180px; height:150px' name='txt1'&amp;gt;Type  and click!&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&amp;lt;td align='center'&amp;gt;&amp;lt;input type=button value='Update applet'  onClick='updateApplet()'&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt; This comes up as shown below.&lt;/p&gt; &lt;p&gt;&lt;a href="http://4.bp.blogspot.com/-f-7_lBuhI9Y/TmRPx84a1eI/AAAAAAAAAJw/lkpCc52rSEY/s1600/pic21.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 311px;" src="http://4.bp.blogspot.com/-f-7_lBuhI9Y/TmRPx84a1eI/AAAAAAAAAJw/lkpCc52rSEY/s320/pic21.JPG" alt="" id="BLOGGER_PHOTO_ID_5648727552204396002" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You can then type something into the box on the form, or you can leave it as  it is and click the button.  It then becomes as shown below.&lt;/p&gt; &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-LxhAnwLaWl4/TmRPx8GQNNI/AAAAAAAAAJ4/P2HJNLt4gWs/s1600/pic22.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 311px;" src="http://2.bp.blogspot.com/-LxhAnwLaWl4/TmRPx8GQNNI/AAAAAAAAAJ4/P2HJNLt4gWs/s320/pic22.JPG" alt="" id="BLOGGER_PHOTO_ID_5648727551993984210" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Full original versions of the code can be downloaded from &lt;a href="http://www.raditha.com/java/mayscript.php"&gt;this page&lt;/a&gt;.&lt;/p&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-3388776467095642466?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/3388776467095642466/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=3388776467095642466' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3388776467095642466'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3388776467095642466'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/javascript-to-applet-communication.html' title='Javascript to Applet Communication - Example 2'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-f-7_lBuhI9Y/TmRPx84a1eI/AAAAAAAAAJw/lkpCc52rSEY/s72-c/pic21.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-6459620454663743608</id><published>2011-09-02T12:43:00.000-07:00</published><updated>2011-09-02T12:59:00.668-07:00</updated><title type='text'>Java Applet/Javascript Communication</title><content type='html'>So I have established that for the last decade, not many people have used  Applets in web pages.  The resulting paucity tutorials or recent examples  made it very difficult even to scratch the surface of how to do this.  I  know when I write notes here, I often skip steps, which seem too obvious or easy,  so that when I revisit an entry written two years ago, even I find it hard to  follow.  So I can't criticize others for being cryptic, or telling only  half the story.  But it has been frustrating wading through articles with  gaps, or code that doesn't work.  &lt;p&gt;But where to begin with an attempt at a full story?  I think a revisit  to paths and class paths.  &lt;/p&gt; &lt;p&gt;In order to compile and run java classes, you need to set a path to the JDK  binaries folder.  This can be done once at the start of a command window  session, or even as a Windows environment variable.&lt;/p&gt; &lt;p&gt;In order to run classes which connect to a database, you need set a "class"  path to a special .jar package containing classes pertaining to communication  with the database, &lt;i&gt;every time&lt;/i&gt; you run the class.&lt;/p&gt; &lt;p&gt;Java Applet/Javascript Communication requires yet another variant.  In  order to compile a class which will communicate with Javascript, you have to set  a class path, every time you compile the class, to a .jar package with the  all-informative name of plugin.jar.  This contains the classes needed for  an applet to call javascript functions.  It can be found in /lib directory  of the JRE installation (e.g. C:\Program Files\Java\jre7\lib).  The command  to compile the class &lt;code&gt;myClass&lt;/code&gt; then becomes:&lt;/p&gt; &lt;p&gt; &lt;code&gt;javac -classpath "C:\Program Files\Java\jre7\lib\plugin.jar" myClass.java&lt;/code&gt; &lt;/p&gt; &lt;p&gt;I wasted a lot of time adding plugin.jar to the JDK binaries folder, and to  my code folder, and couldn't think why sample code cut and pasted from web pages  wouldn't compile.  It doesn't matter where the .jar file is, as long as a  path to it is included with every compile command.&lt;/p&gt;  &lt;p&gt;The second step included in all the articles on java applet to  javascript communication is to add the import:&lt;/p&gt;  &lt;p&gt;  &lt;code&gt;import netscape.javascript.*;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;If you don't include a class path to plugin.jar in your compile command, this  line will generate the first of many compile errors.&lt;/p&gt; &lt;p&gt;The third step is to write some code in the java applet which actually works.   I hunted and hunted for this.  The best example I found was on &lt;a href="http://www.java2s.com/Code/JavaScript/Development/UsingJavaScriptinanApplet.htm"&gt; this&lt;/a&gt; web page.  I should like give them credit for showing me a  solution, but I have modified the code to look more like my &lt;a href="http://jhippjava.blogspot.com/2011/08/java-applet-revision.html"&gt; earlier Hello World example&lt;/a&gt;.  The applet code is:&lt;/p&gt; &lt;p&gt;&lt;code&gt;import java.applet.*;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import netscape.javascript.*;&lt;br /&gt;&lt;br /&gt;public class HelloWorldB extends Applet {&lt;br /&gt;String text="Hello world!";&lt;br /&gt;JSObject win, doc, form, textField;&lt;br /&gt;&lt;br /&gt;public void init() {&lt;br /&gt;win = JSObject.getWindow(this);&lt;br /&gt;doc = (JSObject) win.getMember("document");&lt;br /&gt;form = (JSObject) doc.getMember("textForm");&lt;br /&gt;textField = (JSObject) form.getMember("textField");&lt;br /&gt;setLayout(new BorderLayout());&lt;br /&gt;Panel buttons = new Panel();&lt;br /&gt;Button displayTextButton = new Button("Display Text");&lt;br /&gt;displayTextButton.addActionListener(new ButtonEventHandler());&lt;br /&gt;buttons.add(displayTextButton);&lt;br /&gt;add("South",buttons);&lt;br /&gt;}&lt;br /&gt;public void paint(Graphics g) {&lt;br /&gt;g.drawString(text,30,30);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class ButtonEventHandler implements ActionListener {&lt;br /&gt;public void actionPerformed(ActionEvent e){&lt;br /&gt;String s = e.getActionCommand();&lt;br /&gt;if("Display Text".equals(s)) {&lt;br /&gt;text= (String) textField.getMember("value");&lt;br /&gt;repaint();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The fourth step included in the articles on java applet to javascript  communication is to add "MAYSCRIPT" to the Applet tag.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The web code is then:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;applet code="HelloWorldB.class"&lt;br /&gt;WIDTH=200 HEIGHT=70 MAYSCRIPT&amp;gt;&lt;br /&gt;&amp;lt;/applet&amp;gt;&lt;br /&gt;&amp;lt;form NAME="textForm"&amp;gt;&lt;br /&gt;&amp;lt;P&amp;gt;Enter text and click button:&amp;lt;br&amp;gt;&lt;br /&gt;&amp;lt;INPUT TYPE="text" NAME="textField" SIZE="20"&amp;gt;&amp;lt;/P&amp;gt;&lt;br /&gt;&amp;lt;/FORM&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This comes up as shown below: &lt;/p&gt;&lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-IoqWCIvgui0/TmEzON63_uI/AAAAAAAAAJY/hzsFg1_cvN8/s1600/pic11.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 230px; height: 290px;" src="http://3.bp.blogspot.com/-IoqWCIvgui0/TmEzON63_uI/AAAAAAAAAJY/hzsFg1_cvN8/s320/pic11.JPG" alt="" id="BLOGGER_PHOTO_ID_5647851727047098082" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Then you add text as shown below:&lt;/p&gt; &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-VHsGtYJrzuY/TmEzOK8fE0I/AAAAAAAAAJg/84Wp8vgJrVo/s1600/pic12.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 230px; height: 290px;" src="http://3.bp.blogspot.com/-VHsGtYJrzuY/TmEzOK8fE0I/AAAAAAAAAJg/84Wp8vgJrVo/s320/pic12.JPG" alt="" id="BLOGGER_PHOTO_ID_5647851726248547138" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And when you click the button it come up as:&lt;/p&gt; &lt;p&gt;&lt;a href="http://4.bp.blogspot.com/-kw1bWoD5bm0/TmEzOd5bupI/AAAAAAAAAJo/HcWUmObkP3A/s1600/pic14.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 230px; height: 290px;" src="http://4.bp.blogspot.com/-kw1bWoD5bm0/TmEzOd5bupI/AAAAAAAAAJo/HcWUmObkP3A/s320/pic14.JPG" alt="" id="BLOGGER_PHOTO_ID_5647851731336018578" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This example takes information from a web page and displays it in an applet.   I am actually hoping to do the reverse, but it is a step in the right direction.&lt;/p&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-6459620454663743608?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/6459620454663743608/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=6459620454663743608' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6459620454663743608'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6459620454663743608'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/09/java-appletjavascript-communication.html' title='Java Applet/Javascript Communication'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-IoqWCIvgui0/TmEzON63_uI/AAAAAAAAAJY/hzsFg1_cvN8/s72-c/pic11.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-7600443995976343390</id><published>2011-08-31T06:46:00.000-07:00</published><updated>2011-08-31T06:47:52.821-07:00</updated><title type='text'>An Historical History of Java Applets</title><content type='html'>&lt;p&gt;I have stumbled across &lt;a href="http://www.codeproject.com/KB/scripting/javatojs.aspx"&gt;an eleven year  old (2000 vintage) article&lt;/a&gt;, which already describes Applets as if they were "has been"  technology.  I quote:&lt;/p&gt; &lt;p&gt; &lt;cite&gt;SUN Microsystems introduced Java applets with much fanfare back in 1995.  Applets immediately took the web world by storm because they added the ability  to display dynamic web content within browsers in what was essentially a static  HTML world.&lt;br /&gt;&lt;br /&gt;During those initial days, it appeared that using Java applets was the best way  to add dynamic content to web pages [but when] Dynamic HTML finally started  taking shape, things changed drastically. The Document Object Model (DOM)  exposes elements within a web page as programmable components with their own set  of properties and methods ... Applets suddenly started to look old and  primitive. The W3C’s endorsement of Dynamic HTML finally set the tone for the  new breed of sophisticated, dynamic web pages.&lt;/cite&gt; &lt;/p&gt; &lt;p&gt;Oh dear!&lt;/p&gt; &lt;p&gt;The author does mention some advantages to Applets.  I shall cite just a  couple, relevant to me:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;cite&gt;The JDK comes with many useful classes that are typically found only    in a high-level class library.&lt;/cite&gt;&lt;/li&gt;&lt;li&gt;&lt;cite&gt;Applets can communicate back to the web server for sending    customized messages, uploading / downloading [data].&lt;/cite&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;The shuffling function I use in my Applet.  I'm sure that would not be  available in JavaScript.  And there are other fairly complex calculations I  intend to build in, which I am sure would be better run in compiled code than in  a script.&lt;/p&gt; &lt;p&gt;And Applets are supposed to communicate with a server, which is what I am  trying to do.&lt;/p&gt; &lt;p&gt;Yet almost all the material at least on the top page of a web search is as  old as the article I am citing today.&lt;/p&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-7600443995976343390?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/7600443995976343390/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=7600443995976343390' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/7600443995976343390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/7600443995976343390'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/historical-history-of-java-applets.html' title='An Historical History of Java Applets'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-6338303657602726104</id><published>2011-08-30T19:32:00.000-07:00</published><updated>2011-08-30T19:35:39.360-07:00</updated><title type='text'>Java Applet Revision</title><content type='html'>&lt;p&gt;I first posted an entry on this topic back in &lt;a href="http://jhippjava.blogspot.com/2009/02/hello-world-applet.html"&gt;February  2009&lt;/a&gt;.  To refresh my memory, I'll just run through the steps of adding  a very simple applet to a web page again.  The code for the simple applet  is as follows:&lt;/p&gt; &lt;p&gt; &lt;code&gt;import javax.swing.JApplet;&lt;br /&gt;import java.awt.Graphics;&lt;br /&gt;&lt;br /&gt;public class HelloWorld extends JApplet {&lt;br /&gt;public void paint(Graphics g) {&lt;br /&gt;g.drawRect(0, 0,&lt;br /&gt;getSize().width - 1,&lt;br /&gt;getSize().height - 1);&lt;br /&gt;g.drawString("Hello world!", 5, 15);&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt; &lt;/p&gt; &lt;p&gt;This was borrowed from the old (pre-Oracle) Java tutorial.  A slightly  more sophisticated version is offered in the &lt;a href="http://download.oracle.com/javase/tutorial/deployment/applet/getStarted.html"&gt; current Java Applet tutorial&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;The code to include the applet in a web page might be:&lt;/p&gt; &lt;p&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;applet code="HelloWorld.class"&lt;br /&gt;width="150" height="50"&amp;gt;&lt;br /&gt;&amp;lt;/applet&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/p&gt; &lt;p&gt;And the page might look like this.&lt;/p&gt; &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-yB5xI3vFvS8/Tl2dhHH3ZqI/AAAAAAAAAJQ/jcmTPbwDs3g/s1600/pic01.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 231px; height: 222px;" src="http://3.bp.blogspot.com/-yB5xI3vFvS8/Tl2dhHH3ZqI/AAAAAAAAAJQ/jcmTPbwDs3g/s320/pic01.JPG" alt="" id="BLOGGER_PHOTO_ID_5646842699965752994" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-6338303657602726104?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/6338303657602726104/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=6338303657602726104' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6338303657602726104'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6338303657602726104'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/java-applet-revision.html' title='Java Applet Revision'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-yB5xI3vFvS8/Tl2dhHH3ZqI/AAAAAAAAAJQ/jcmTPbwDs3g/s72-c/pic01.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-4996047471090984632</id><published>2011-08-29T23:12:00.000-07:00</published><updated>2011-08-30T01:16:50.735-07:00</updated><title type='text'>Asynchronous JavaScript and XML (AJAX)</title><content type='html'>I am looking at the &lt;a href="http://www.w3schools.com/default.asp"&gt;W3Schools&lt;/a&gt;  tutorial on &lt;a href="http://www.w3schools.com/ajax/default.asp"&gt;AJAX&lt;/a&gt;.   The tutorial begins with the statements: &lt;p&gt; &lt;cite&gt;AJAX is not a new programming language, but a new way to use existing  standards. AJAX is the art of exchanging data with a server, and update parts of  a web page - without reloading the whole page.&lt;/cite&gt; &lt;/p&gt; &lt;p&gt;It is the &lt;i&gt;exchanging data with a server&lt;/i&gt; phrase which interests me.  &lt;/p&gt;  &lt;p&gt;&lt;i&gt;AJAX was made popular in 2005 by Google, with Google Suggest. Google  Suggest [uses] AJAX to create a very dynamic web interface: When you start  typing in Google's search box, a JavaScript sends the letters off to a server  and the server returns a list of suggestions.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;I used the same concept in the 90's in a VB application I created for the &lt;a href="http://www.gloucesterpark.com.au/gloucester-park/"&gt;WA Trotting  Association&lt;/a&gt; to help them maintain a database of competition entrants.   So that idea is not new, but I guess doing it on a web page must be.&lt;/p&gt;  &lt;p&gt;Apparently modern browsers (IE7+, Firefox, Chrome, Safari, and Opera) support &lt;q&gt;the keystone of AJAX&lt;/q&gt;, the XMLHttpRequest  object.  Earlier versions of Internet Explorer (IE5 and IE6) use the MS  ActiveXObject.  The code examples in the  &lt;a href="http://www.w3schools.com/ajax/default.asp"&gt;tutorial&lt;/a&gt; allow for  older IE versions, but in the example quoted below, I have edited this out for  simplicity of analysis.&lt;/p&gt;  &lt;p&gt;  &lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;function loadXMLDoc()&lt;br /&gt;{&lt;br /&gt;var xmlhttp;&lt;br /&gt;xmlhttp=new XMLHttpRequest();&lt;br /&gt;xmlhttp.onreadystatechange=function()&lt;br /&gt;{&lt;br /&gt;if (xmlhttp.readyState==4 &amp;amp;&amp;amp; xmlhttp.status==200)&lt;br /&gt;{&lt;br /&gt;document.getElementById("myDiv").innerHTML=xmlhttp.responseText;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;xmlhttp.open("GET","ajax_info.txt",true);&lt;br /&gt;xmlhttp.send();&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id="myDiv"&amp;gt;&amp;lt;h2&amp;gt;Let AJAX change this text&amp;lt;/h2&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;button type="button" onclick="loadXMLDoc()"&amp;gt;Change Content&amp;lt;/button&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt; &lt;/p&gt;  &lt;p&gt;The HTML code above sets out a web page comprising a header and a button (see  below).     &lt;/p&gt;  &lt;p&gt;&lt;a href="http://4.bp.blogspot.com/-2VLAsbfzdrQ/TlycHIDhLmI/AAAAAAAAAI4/4SO-cPYlcbk/s1600/Pic01.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 306px; height: 258px;" src="http://4.bp.blogspot.com/-2VLAsbfzdrQ/TlycHIDhLmI/AAAAAAAAAI4/4SO-cPYlcbk/s320/Pic01.JPG" alt="" id="BLOGGER_PHOTO_ID_5646559679051017826" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The header is enclosed within the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag.  A &lt;code&gt; &amp;lt;div&amp;gt;&lt;/code&gt;  tag usually divides a big web page into sections.  It seems a bit redundant here, so I  tried removing it, and labeling the header instead:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;h2 id="myDiv"&amp;gt;Let AJAX change this text&amp;lt;/h2&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;It still worked, but the text, invoked by the button click, all appeared in the  header style.&lt;/p&gt;  &lt;p&gt;The JavaScript is all contained in the function  &lt;code&gt;loadXMLDoc&lt;/code&gt;, which is called by the button click event.&lt;/p&gt;  &lt;p&gt;Within the function, the variable  &lt;code&gt;xmlhttp&lt;/code&gt; is declared and set as a new  &lt;code&gt;XMLHttpRequest&lt;/code&gt; object.  I'd love to find this  &lt;code&gt;XMLHttpRequest&lt;/code&gt; object in a reference library, but I can't find it  on the &lt;a href="http://www.w3schools.com/jsref/default.asp"&gt;W3Schools  JavaScript/DOM&lt;/a&gt; reference page.  So from the  &lt;a href="http://www.w3schools.com/ajax/default.asp"&gt;tutorial&lt;/a&gt; I learn of two  methods: &lt;code&gt;open()&lt;/code&gt; and &lt;code&gt;send()&lt;/code&gt;.  The &lt;code&gt;open() &lt;/code&gt; method seems to require the following parameters:&lt;/p&gt;  &lt;ul&gt;&lt;li&gt;&lt;code&gt;method&lt;/code&gt; - the type of request: &lt;code&gt;GET&lt;/code&gt; or &lt;code&gt;POST&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code&gt;url&lt;/code&gt; - the location of the file on the server&lt;/li&gt;&lt;li&gt;&lt;code&gt;async&lt;/code&gt; - &lt;code&gt;true&lt;/code&gt; (asynchronous) or &lt;code&gt;false&lt;/code&gt; (synchronous)&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;The &lt;code&gt;send() &lt;/code&gt; method allows the following parameter:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;code&gt;string&lt;/code&gt;: Used for POST requests&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;In the code above, the &lt;code&gt;open() &lt;/code&gt; method is used with &lt;/p&gt; &lt;ul&gt;&lt;li&gt; &lt;code&gt;method =&lt;/code&gt; &lt;code&gt;"GET"&lt;/code&gt;, &lt;/li&gt;&lt;li&gt; &lt;code&gt;url&lt;/code&gt;  &lt;code&gt;= "ajax_info.txt"&lt;/code&gt; and  &lt;/li&gt;&lt;li&gt; &lt;code&gt;async = true&lt;/code&gt;.  &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The text contained in the file  &lt;code&gt;ajax_info.txt&lt;/code&gt; is:&lt;/p&gt; &lt;p&gt; &lt;code&gt;&amp;lt;p&amp;gt;AJAX is not a new programming language.&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;AJAX is a technique for creating fast and dynamic web pages.&amp;lt;/p&amp;gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;Now from the code, it seems the  &lt;code&gt;XMLHttpRequest&lt;/code&gt; object has at least 3 properties:&lt;/p&gt;  &lt;ul&gt;&lt;li&gt;  &lt;code&gt;.readyState&lt;/code&gt;&lt;/li&gt;&lt;li&gt;  &lt;code&gt;.status&lt;/code&gt;&lt;/li&gt;&lt;li&gt;  &lt;code&gt;.responseText&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Just by reading the code it is not clear whether  &lt;code&gt;.responseText&lt;/code&gt; is populated by &lt;code&gt;.open&lt;/code&gt; or &lt;code&gt;.send&lt;/code&gt;.   Intuitive logic would suggest the former, but in that case it is not clear what &lt;code&gt;.send&lt;/code&gt;  doing in there as well, although in the  &lt;a href="http://www.w3schools.com/ajax/default.asp"&gt;tutorial&lt;/a&gt; it says:&lt;/p&gt; &lt;p&gt; &lt;cite&gt;To send a request to a server, we use the open() and send() methods of the  XMLHttpRequest object&lt;/cite&gt; &lt;/p&gt; &lt;p&gt; And it shows the two methods being used one after the other, as they are in the  code.  The lesson then goes on to say a little more about the  &lt;code&gt;.responseText&lt;/code&gt; property and one more:&lt;/p&gt;  &lt;ul&gt;&lt;li&gt;  &lt;code&gt;.responseText&lt;/code&gt; - holds the response data as a string&lt;/li&gt;&lt;li&gt;  &lt;code&gt;.responseXML&lt;/code&gt; - holds the response data as a XML data&lt;/li&gt;&lt;/ul&gt; &lt;p&gt; It gives a further &lt;a href="http://www.w3schools.com/ajax/ajax_xmlhttprequest_response.asp"&gt;example  using XML&lt;/a&gt;, which I shall skip at this stage, because on the &lt;a href="http://www.w3schools.com/ajax/ajax_xmlhttprequest_onreadystatechange.asp"&gt; next page&lt;/a&gt; we get clarification on the  &lt;code&gt;.readyState&lt;/code&gt; and  &lt;code&gt;.status&lt;/code&gt; properties, together with one I had failed to notice,   &lt;code&gt;.onreadystatechange&lt;/code&gt;.  The last one appears to be both a  property and an event:&lt;/p&gt;  &lt;ul&gt;&lt;li&gt;The  &lt;code&gt;onreadystatechange &lt;/code&gt;event is triggered every time the readyState    changes.&lt;/li&gt;&lt;li&gt;The  &lt;code&gt;onreadystatechange &lt;/code&gt;property stores a function (or the name of a    function) to be called automatically each time the  &lt;code&gt;readyState&lt;/code&gt; property changes.&lt;/li&gt;&lt;li&gt;The  &lt;code&gt;readyState&lt;/code&gt; property holds the status of the XMLHttpRequest.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;I have to say this leaves a question mark over what the  &lt;code&gt;.status&lt;/code&gt; property holds - a question not answered by the  &lt;a href="http://www.w3schools.com/ajax/default.asp"&gt;tutorial&lt;/a&gt;.  What it  does give is a list of acceptable values for these properties.  For  &lt;code&gt;.readyState&lt;/code&gt; these are: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;0: request not initialized&lt;/li&gt;&lt;li&gt;1: server connection established&lt;/li&gt;&lt;li&gt;2: request received&lt;/li&gt;&lt;li&gt;3: processing request&lt;/li&gt;&lt;li&gt;4: request finished and response is ready&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;For  &lt;code&gt;.status&lt;/code&gt; these are: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;200: "OK"&lt;/li&gt;&lt;li&gt;404: Page not found&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;By my calculation the  property changes four times with every server  request, so the  &lt;code&gt;onreadystatechange&lt;/code&gt; event must be triggered four times.  I  guess that explains the conditional clause in the function:&lt;/p&gt; &lt;p&gt;  &lt;code&gt;xmlhttp.onreadystatechange=function()&lt;br /&gt;{&lt;br /&gt;if (xmlhttp.readyState==4 &amp;amp;&amp;amp; xmlhttp.status==200)&lt;br /&gt;{&lt;br /&gt;document.getElementById("myDiv").innerHTML=xmlhttp.responseText;&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This function is called four times, but it only does anything on the fourth  occasion, when "the request finished and response is ready" and the  &lt;code&gt;.status&lt;/code&gt; property is "OK".   (And on closer  reading this is mentioned in the  &lt;a href="http://www.w3schools.com/ajax/default.asp"&gt;tutorial&lt;/a&gt;.)&lt;/p&gt; &lt;p&gt;At first I was confused by the above code segment, because I didn't realize  it is an unnamed function within the function  &lt;code&gt;loadXMLDoc() &lt;/code&gt;and is called by a different event.  The  &lt;code&gt;loadXMLDoc()&lt;/code&gt; function  is called be the button click event,  while the unnamed function is both contained by the  &lt;code&gt;onreadystatechange&lt;/code&gt; property and called by the  &lt;code&gt;onreadystatechange&lt;/code&gt; event.&lt;/p&gt;  &lt;p&gt;So when the button is clicked, everything inside the tag labeled "myDiv" is  replaced with the text in the file.  In its original version this appears  as regular text (see below).  &lt;/p&gt;  &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-nDvNzod2tww/TlycHVr9lrI/AAAAAAAAAJA/s0pcMJUiIYg/s1600/Pic02.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 306px; height: 287px;" src="http://1.bp.blogspot.com/-nDvNzod2tww/TlycHVr9lrI/AAAAAAAAAJA/s0pcMJUiIYg/s320/Pic02.JPG" alt="" id="BLOGGER_PHOTO_ID_5646559682710312626" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;   &lt;p&gt;In my alternative version both paragraphs appear as headers because they both  fall within the header tag (see below).  &lt;/p&gt;  &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-Wz-b2LHfwY4/TlycHjHJczI/AAAAAAAAAJI/nTpmSM2r0VQ/s1600/Pic03.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 254px; height: 320px;" src="http://2.bp.blogspot.com/-Wz-b2LHfwY4/TlycHjHJczI/AAAAAAAAAJI/nTpmSM2r0VQ/s320/Pic03.JPG" alt="" id="BLOGGER_PHOTO_ID_5646559686313997106" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If the button is clicked again, nothing appears to happen, because the text  is replaced by identical text.  Again, I was initially confused here,  because I thought the conditional clause had something to do with what was being  displayed.&lt;/p&gt;  &lt;p&gt;Anyway, this is all a bit disappointing, because I also misunderstood the &lt;i&gt;exchanging data with a server&lt;/i&gt;  phrase to mean exchanging data &lt;i&gt;with a database&lt;/i&gt; on a server, not a measly  old text file.&lt;/p&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-4996047471090984632?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/4996047471090984632/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=4996047471090984632' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4996047471090984632'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4996047471090984632'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/asynchronous-javascript-and-xml-ajax.html' title='Asynchronous JavaScript and XML (AJAX)'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-2VLAsbfzdrQ/TlycHIDhLmI/AAAAAAAAAI4/4SO-cPYlcbk/s72-c/Pic01.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-6176264765542855766</id><published>2011-08-26T02:04:00.000-07:00</published><updated>2011-08-26T03:28:11.723-07:00</updated><title type='text'>Document Object Model (DOM)</title><content type='html'>I remember once attending a seminar by Microsoft where they were describing  themselves as the cleverest people in the world for inventing what they called  the Component Object Model (COM).  It was only years later that I learned  that they didn't really invent the idea at all, but copied it from other object  oriented programming languages. &lt;p&gt;Anyway, the Document Object Model (DOM), although it rhymes with COM, has  nothing to do with Microsoft, but is a World Wide Web Consortium (W3C) standard  defined as:&lt;/p&gt; &lt;p&gt;&lt;cite&gt;A platform and language-neutral interface that allows programs and  scripts to dynamically access and update the content, structure, and style of a  document.&lt;/cite&gt;&lt;/p&gt; &lt;p&gt;According to the &lt;a href="http://www.w3schools.com/default.asp"&gt;W3Schools&lt;/a&gt;  tutorial on &lt;a href="http://www.w3schools.com/htmldom/default.asp"&gt;DOM&lt;/a&gt;:&lt;/p&gt; &lt;p&gt;&lt;cite&gt;The DOM is separated into 3 different parts / levels:&lt;/cite&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;cite&gt;Core DOM - standard model for any structured document&lt;/cite&gt;&lt;/li&gt;&lt;li&gt;&lt;cite&gt;XML DOM - standard model for XML documents&lt;/cite&gt;&lt;/li&gt;&lt;li&gt;&lt;cite&gt;HTML DOM - standard model for HTML documents&lt;/cite&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;cite&gt;The DOM defines the objects and properties of all document elements, and the  methods (interface) to access them.  [It] is a standard for how to get,  change, add, or delete [XML/HTML] elements.&lt;/cite&gt;&lt;/p&gt;  &lt;p&gt;According to the &lt;a href="http://www.w3schools.com/htmldom/default.asp"&gt; tutorial&lt;/a&gt;:&lt;/p&gt; &lt;p&gt;&lt;cite&gt;DOM views an HTML document as a tree-structure ... called a node-tree.&lt;/cite&gt;&lt;/p&gt; &lt;p&gt;And it goes on to show a diagram of a node tree.  I'm not sure how  useful this form of representation is for me, but I'll show it below for  completeness:&lt;/p&gt; &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-gmD8aW9Km0E/TldtmtglMHI/AAAAAAAAAIQ/14RV_-oe9o0/s1600/pic01.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 177px;" src="http://1.bp.blogspot.com/-gmD8aW9Km0E/TldtmtglMHI/AAAAAAAAAIQ/14RV_-oe9o0/s320/pic01.JPG" alt="" id="BLOGGER_PHOTO_ID_5645101169750913138" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Essentially, the DOM breaks web documents into a set of objects, which it  calls nodes, and these nodes have properties which can be read or acted upon by  methods.  The &lt;a href="http://www.w3schools.com/htmldom/default.asp"&gt; Tutorial&lt;/a&gt; provides a link to a &lt;a href="http://www.w3schools.com/jsref/default.asp"&gt;reference page&lt;/a&gt; listing  DOM objects and their properties, along with JavaScript objects and Browser  objects.&lt;/p&gt; &lt;p&gt;The &lt;a href="http://www.w3schools.com/htmldom/default.asp"&gt;Tutorial&lt;/a&gt; gives  a "hello world" example, which to me illustrates the extraordinary messiness of  this language/methodology.  Before citing the example, I shall mention that  two of the objects listed on the &lt;a href="http://www.w3schools.com/jsref/default.asp"&gt;reference page&lt;/a&gt; are the  &lt;code&gt;document&lt;/code&gt; object and the &lt;code&gt;HTMLElement&lt;/code&gt; object.  One of the methods listed for  the is the &lt;code&gt;getElementById()&lt;/code&gt; method.  One of the properties  listed for the &lt;code&gt;HTMLElement&lt;/code&gt; object is &lt;code&gt;.innerHTML&lt;/code&gt;, which  in any other language would probably be &lt;code&gt;.text&lt;/code&gt;.  Another is &lt;code&gt;.id&lt;/code&gt;.  So now here is the code:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;p id="intro"&amp;gt;Hello World!&amp;lt;/p&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;txt=document.getElementById("intro").innerHTML;&lt;br /&gt;document.write("&amp;lt;p&amp;gt;The intro paragraph text is: " + txt + "&amp;lt;/p&amp;gt;");&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;So the first paragraph is assigned the id "intro" by the HTML.  Then in the  JavaScript this &lt;code&gt;HTMLElement&lt;/code&gt; object is referred to by its id, and  its &lt;code&gt;innerHTML&lt;/code&gt; property is assigned to the JavaScript variable &lt;code&gt; txt&lt;/code&gt;.  The content of this variable is then concatenated with the  text of a second paragraph created with the JavaScript &lt;code&gt;document.write&lt;/code&gt;  method.  The result is shown in the image below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-OfDhRUzByxM/TldtmhRDkeI/AAAAAAAAAIY/Zxo-ep_WgAw/s1600/pic02.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 276px; height: 241px;" src="http://3.bp.blogspot.com/-OfDhRUzByxM/TldtmhRDkeI/AAAAAAAAAIY/Zxo-ep_WgAw/s320/pic02.JPG" alt="" id="BLOGGER_PHOTO_ID_5645101166464569826" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;That seems a lot of work to achieve something fairly trivial, but at least  now I have some understanding of what DOM is all about.  It is essentially a labeling  system for HTML elements, which enables them to be changed programmatically  (usually with JavaScript).  In fact it is really just an extension of  JavaScript to embrace HTML elements and their properties.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-6176264765542855766?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/6176264765542855766/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=6176264765542855766' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6176264765542855766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6176264765542855766'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/document-object-model-dom.html' title='Document Object Model (DOM)'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-gmD8aW9Km0E/TldtmtglMHI/AAAAAAAAAIQ/14RV_-oe9o0/s72-c/pic01.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-4668130920661650606</id><published>2011-08-24T04:57:00.000-07:00</published><updated>2011-08-24T05:24:03.393-07:00</updated><title type='text'>eXtensible Markup Language (XML)</title><content type='html'>I am looking at the &lt;a href="http://www.w3schools.com/default.asp"&gt;W3Schools&lt;/a&gt;  tutorial on &lt;a href="http://www.w3schools.com/xml/default.asp"&gt;XML&lt;/a&gt;.  I  like the clarification on the roles of HTML and XML:  &lt;cite&gt;&lt;/cite&gt;&lt;ul&gt;&lt;li&gt;HTML was designed to display data, with focus on how data looks.&lt;/li&gt;&lt;li&gt;HTML truncates multiple white-space characters to one single white-space.&lt;/li&gt;&lt;li&gt;XML was designed to transport and store data, with focus on what data is.&lt;/li&gt;&lt;li&gt;White-space is Preserved in XML. XML Stores New Line as LF.&lt;/li&gt;&lt;li&gt;XML tags are not predefined. You must define your own tags.&lt;/li&gt;&lt;li&gt;XML documents must include an XML declaration and can include a DOCTYPE    declaration, which in turn refers to "system" of tags/elements, set out in    either a &lt;a href="http://www.w3schools.com/dtd/default.asp"&gt;DTD&lt;/a&gt; file or in    a &lt;a href="http://www.w3schools.com/schema/default.asp"&gt;Schema&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;XML does not DO anything other than to transport and store data.&lt;/li&gt;&lt;li&gt;XML data is stored in plain text format. This provides a software and    hardware independent way of storing data.&lt;/li&gt;&lt;li&gt;XML documents must contain a root element. This element is "the parent" of    all other elements. All elements can have sub elements (child elements).&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;The tutorial gives an example:&lt;/p&gt; &lt;p&gt; &lt;code&gt;&amp;lt;?xml version="1.0" encoding="ISO-8859-1"?&amp;gt;&lt;br /&gt;&amp;lt;bookstore&amp;gt;&lt;br /&gt;&amp;lt;book category="COOKING"&amp;gt;&lt;br /&gt;&amp;lt;title lang="en"&amp;gt;Everyday Italian&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;author&amp;gt;Giada De Laurentiis&amp;lt;/author&amp;gt;&lt;br /&gt;&amp;lt;year&amp;gt;2005&amp;lt;/year&amp;gt;&lt;br /&gt;&amp;lt;price&amp;gt;30.00&amp;lt;/price&amp;gt;&lt;br /&gt;&amp;lt;/book&amp;gt;&lt;br /&gt;&amp;lt;book category="CHILDREN"&amp;gt;&lt;br /&gt;&amp;lt;title lang="en"&amp;gt;Harry Potter&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;author&amp;gt;J K. Rowling&amp;lt;/author&amp;gt;&lt;br /&gt;&amp;lt;year&amp;gt;2005&amp;lt;/year&amp;gt;&lt;br /&gt;&amp;lt;price&amp;gt;29.99&amp;lt;/price&amp;gt;&lt;br /&gt;&amp;lt;/book&amp;gt;&lt;br /&gt;&amp;lt;book category="WEB"&amp;gt;&lt;br /&gt;&amp;lt;title lang="en"&amp;gt;Learning XML&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;author&amp;gt;Erik T. Ray&amp;lt;/author&amp;gt;&lt;br /&gt;&amp;lt;year&amp;gt;2003&amp;lt;/year&amp;gt;&lt;br /&gt;&amp;lt;price&amp;gt;39.95&amp;lt;/price&amp;gt;&lt;br /&gt;&amp;lt;/book&amp;gt;&lt;br /&gt;&amp;lt;/bookstore&amp;gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;Here first line is the &lt;code&gt;XML&lt;/code&gt; declaration and the root element is &lt;code&gt;&amp;lt;bookstore&amp;gt;&lt;/code&gt;.  The &lt;code&gt;&amp;lt;bookstore&amp;gt;&lt;/code&gt;  contains 3 &lt;code&gt;&amp;lt;book&amp;gt;&lt;/code&gt; elements, each of which had a &lt;code&gt;lang &lt;/code&gt;attribute, and in turn has 4 child elements.  It seems to  me analogous to a data table entitled "bookstore", with 6 columns and 3 rows.   I say 6 columns, because in a data table, the &lt;code&gt;lang &lt;/code&gt;attribute and the &lt;code&gt;book category&lt;/code&gt; would be stored as columns, possibly integer indices  linked to other tables.  &lt;/p&gt;  &lt;p&gt;My interpretation is confirmed in a section entitled &lt;a href="http://www.w3schools.com/xml/xml_attributes.asp"&gt;Elements vs.  Attributes&lt;/a&gt;, where the following examples are said to be equivalent:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;person sex="female"&amp;gt;&lt;br /&gt;&amp;lt;firstname&amp;gt;Anna&amp;lt;/firstname&amp;gt;&lt;br /&gt;&amp;lt;lastname&amp;gt;Smith&amp;lt;/lastname&amp;gt;&lt;br /&gt;&amp;lt;/person&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;person&amp;gt;&lt;br /&gt;&amp;lt;sex&amp;gt;female&amp;lt;/sex&amp;gt;&lt;br /&gt;&amp;lt;firstname&amp;gt;Anna&amp;lt;/firstname&amp;gt;&lt;br /&gt;&amp;lt;lastname&amp;gt;Smith&amp;lt;/lastname&amp;gt;&lt;br /&gt;&amp;lt;/person&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;Indeed the tutorial goes on to say:&lt;/p&gt;  &lt;p&gt;&lt;cite&gt;There are no rules about when to use attributes or when to use elements  [but while] attributes are handy in HTML. In XML my advice is to avoid them. Use  elements instead.&lt;/cite&gt;&lt;/p&gt;  &lt;p&gt;My first impression is that this is not an "efficient" way to store data, not  least because the row "headers" have to be repeated in every row.  But then  HTML tables are messy to look at (in HTML code) and nightmarish to produce  (manually).&lt;/p&gt;  &lt;p&gt;Interestingly, although XML does not render in a browser in the same way as  HTML, it does come up a bit like code in a code editor (see below).  So  "parent" elements can be expanded or contracted to show or hide their "child"  elements.  In the image below, the "cooking" book element has been  expanded, but the other two book elements left closed.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-lfNVI3OU-kk/TlTtR2UAQzI/AAAAAAAAAII/pY7cRNOYDUQ/s1600/pic01.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 259px; height: 320px;" src="http://2.bp.blogspot.com/-lfNVI3OU-kk/TlTtR2UAQzI/AAAAAAAAAII/pY7cRNOYDUQ/s320/pic01.JPG" alt="" id="BLOGGER_PHOTO_ID_5644397123895051058" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;It's interesting, but I am still no closer to connecting &lt;a href="http://www.interactived.com/jartest.htm"&gt;my Applet&lt;/a&gt; to a database.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-4668130920661650606?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/4668130920661650606/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=4668130920661650606' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4668130920661650606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4668130920661650606'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/extensible-markup-language-xml.html' title='eXtensible Markup Language (XML)'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-lfNVI3OU-kk/TlTtR2UAQzI/AAAAAAAAAII/pY7cRNOYDUQ/s72-c/pic01.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-918524119964087049</id><published>2011-08-22T20:39:00.000-07:00</published><updated>2011-08-22T20:41:51.953-07:00</updated><title type='text'>JavaScript by w3schools</title><content type='html'>&lt;p&gt;I was planning to slot in an entry on XML here, but I note the &lt;a href="http://www.w3schools.com/default.asp"&gt;W3Schools&lt;/a&gt;  tutorial on &lt;a href="http://www.w3schools.com/xml/default.asp"&gt;XML&lt;/a&gt; puts &lt;a href="http://www.w3schools.com/js/default.asp"&gt;JavaScript&lt;/a&gt; as required  knowledge.  As I branched into web language revision because &lt;a href="http://www.w3schools.com/html/default.asp"&gt;HTML&lt;/a&gt; and &lt;a href="http://www.w3schools.com/default.asp"&gt;XHTML&lt;/a&gt; were required knowledge  for  &lt;a href="http://www.w3schools.com/js/default.asp"&gt;JavaScript&lt;/a&gt;, I might as well start on that now.&lt;/p&gt;  &lt;p&gt;I have to say that having praised the  &lt;a href="http://www.w3schools.com/default.asp"&gt;W3Schools&lt;/a&gt;  tutorial on &lt;a href="http://www.w3schools.com/php/default.asp"&gt;PHP&lt;/a&gt;, I am a  little disappointed by &lt;a href="http://www.w3schools.com/js/default.asp"&gt;this  one&lt;/a&gt;. It is all over the place.  I came &lt;a href="http://www.w3schools.com/js/default.asp"&gt;here&lt;/a&gt; because the Mozilla &lt;a href="https://developer.mozilla.org/en/JavaScript/Getting_Started"&gt;Getting  Started with JavaScript&lt;/a&gt; page began with a "corny" example but zero  explanation of the language structure or syntax.  And now &lt;a href="http://www.w3schools.com/js/default.asp"&gt;this one&lt;/a&gt; does the same  thing:&lt;/p&gt; &lt;p&gt; &lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;function displayDate()&lt;br /&gt;{&lt;br /&gt;document.getElementById("demo").innerHTML=Date();&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;h1&amp;gt;My First Web Page&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;p id="demo"&amp;gt;This is a paragraph.&amp;lt;/p&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;button type="button" onclick="displayDate()"&amp;gt;Display  Date&amp;lt;/button&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt; &lt;/code&gt; &lt;/p&gt; &lt;p&gt;It's rubbish without a proper explanation.  If all I want to do is reverse  engineer someone else's code, I won't bother with a tutorial, I'll just search  for code examples.&lt;/p&gt; &lt;p&gt;So what do we have in the next few pages that is useful?&lt;/p&gt; &lt;p&gt; &lt;cite&gt;To insert a JavaScript into an HTML page, use the &amp;lt;script&amp;gt; tag. Inside the  &amp;lt;script&amp;gt; tag use the type attribute to define the scripting language.&lt;/cite&gt; &lt;/p&gt; &lt;p&gt;This is shown in line 3 of the code quoted above.&lt;/p&gt;  &lt;p&gt;&lt;cite&gt;The lines between the &amp;lt;script&amp;gt; and &amp;lt;/script&amp;gt; contain the JavaScript and  are executed by the browser. JavaScripts can be put in the &amp;lt;body&amp;gt; and in the  &amp;lt;head&amp;gt; sections of an HTML page. JavaScripts in an HTML page will be  executed when the page loads. This is not always what we want. Sometimes we want  to execute a JavaScript when an event occurs, such as when a user clicks a  button. When this is the case we can put the script inside a function [which is called by the event].&lt;/cite&gt;&lt;/p&gt; &lt;p&gt;This strategy is executed in line 4 of the code quoted above, where the  function &lt;code&gt;displayDate&lt;/code&gt; is defined, and in the third from last line,  where a button click is set to call the function.&lt;/p&gt;  &lt;p&gt;&lt;cite&gt;You can place an unlimited number of scripts in your document, and you  can have scripts in both the body and the head section at the same time. It is a  common practice to put all functions [either] in the head section, or at the  bottom of the page. This way they are all in one place and do not interfere with  page content.&lt;br /&gt;&lt;br /&gt;JavaScript can also be placed in external files. External JavaScript files often  contain code to be used on several different web pages. External JavaScript  files have the file extension .js. To use an external script, point to the .js  file in the "src" attribute of the &amp;lt;script&amp;gt; tag:&lt;/cite&gt;&lt;/p&gt;  &lt;p&gt;For example:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;script type="text/javascript" src="xxx.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;I thought they might give an example of a .js document, but they did not.&lt;/p&gt;  &lt;p&gt;Let's hope the &lt;a href="http://www.w3schools.com/xml/default.asp"&gt;XML&lt;/a&gt;  lesson is more interesting.&lt;/p&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-918524119964087049?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/918524119964087049/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=918524119964087049' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/918524119964087049'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/918524119964087049'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/javascript-by-w3schools.html' title='JavaScript by w3schools'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-4200932470603909837</id><published>2011-08-21T17:23:00.000-07:00</published><updated>2011-08-21T20:33:54.741-07:00</updated><title type='text'>Web language Revision</title><content type='html'>&lt;p&gt;I'm probably stretching the definition of revision here.  My only formal  tuition in web languages was in HyperText Markup Language (HTML)(1 - except there was no number then) and it  wasn't very formal.  From memory it was a free one hour lecture provided by  &lt;a href="http://www.uwa.edu.au/"&gt;UWA&lt;/a&gt; to encourage research students to use the new medium to publicize their  work.&lt;/p&gt;  &lt;p&gt;Anyway, disappointed by the Mozilla &lt;a href="https://developer.mozilla.org/en/JavaScript/Getting_Started"&gt;Getting  Started with JavaScript&lt;/a&gt; page, I went back to a Google search on "JavaScript  Tutorial" and W3Schools was on top of the list again.  Curious, I checked &lt;a href="http://en.wikipedia.org/wiki/W3Schools"&gt;Wikipedia&lt;/a&gt; to find:&lt;/p&gt;  &lt;p&gt;  &lt;cite&gt;W3Schools is not affiliated in any way with the World Wide Web Consortium  (W3C). It is created and owned by Refsnes Data, a Norwegian family-owned  software development and consulting company.&lt;/cite&gt; &lt;/p&gt;  &lt;p&gt;Affiliated with W3C or not, I liked the style of their &lt;a href="http://www.w3schools.com/PHP/default.asp"&gt;PHP tutorial&lt;/a&gt;, so I  checked out their &lt;a href="http://www.w3schools.com/js/js_intro.asp"&gt;JavaScript  tutorial&lt;/a&gt;.  Listed as required knowledge was HTML and CSS, and a link  was provided to their &lt;a href="http://www.w3schools.com/default.asp"&gt;Home Page&lt;/a&gt;,  in case of any doubt.  I followed the link, because the initials CSS meant  nothing to me.  And listed with CSS were the languages of the web - HTML,  and XHTML.  So I decided the time had come for a refresher and catch up on  what has happened in the last fifteen years.&lt;/p&gt;  &lt;p&gt;I noted a few more &lt;a href="http://www.w3schools.com/html/html_formatting.asp"&gt;formatting&lt;/a&gt; tags  than were available in the olden days - whether one really needs them all or not  is another question.  &lt;a href="http://www.w3schools.com/html/html_styles.asp"&gt;Styles&lt;/a&gt; are  completely new to me, and it looks as if I have been doing a few things wrong,  or at least, not consistently with current standards.  But at least I have  a jogged a vague recollection that CSS stands for Cascading Style Sheets.   I also noted on the &lt;a href="http://www.w3schools.com/html/html_images.asp"&gt; images&lt;/a&gt; page that the language and syntax of what used to be the ismap  attribute has changed a lot.  It's not something I use much, but I now have  an easy link to the correct form if I need it.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.w3schools.com/html/html_forms.asp"&gt;Forms&lt;/a&gt; came in well  after my time.  I've cribbed other people's code, but it's nice to see it  all laid out properly.  &lt;a href="http://www.w3schools.com/html/html_frames.asp"&gt;Frames&lt;/a&gt; came a little  after my time (HTML2 I think) and I never liked them.  I was pleased to  read that they are being phased out and will not be supported in future HTML  versions.  The &lt;a href="http://www.w3schools.com/html/html_iframe.asp"&gt; Iframe&lt;/a&gt; is completely new to me.  Defined as &lt;q&gt;a web page within a web  page&lt;/q&gt;, I can see there might be applications for it.&lt;/p&gt;  &lt;p&gt;When I was a boy, you began an HTML document with the HTML tag, and that told  the browser what type of document it was.  Nowadays, apparently, you need a  document type declaration as well.  In practice you can get away without it  with ordinary HTML documents (none of the pages on &lt;a href="http://www.interactived.com/softway.htm"&gt;my web site&lt;/a&gt; use it), but  perhaps you need it for other document types, such as XHTML.&lt;/p&gt;  &lt;p&gt;This brings me to the &lt;a href="http://www.w3schools.com/xhtml/default.asp"&gt; tutorial on EXtensible HyperText Markup Language  (XHTML)&lt;/a&gt;, which I am surprised to learn is simply a &lt;q&gt;stricter and  cleaner version of HTML:&lt;/q&gt;&lt;/p&gt;  &lt;p&gt;&lt;cite&gt;XHTML consists of all the elements in HTML 4.01, combined with the  strict syntax of XML.&lt;/cite&gt;&lt;/p&gt;  &lt;ul&gt;&lt;li&gt;&lt;cite&gt;XHTML elements must be properly nested&lt;/cite&gt;&lt;/li&gt;&lt;li&gt;&lt;cite&gt;XHTML elements must always be closed&lt;/cite&gt;&lt;/li&gt;&lt;li&gt;&lt;cite&gt;XHTML elements must be in lowercase&lt;/cite&gt;&lt;/li&gt;&lt;li&gt;&lt;cite&gt;XHTML documents must have one root element&lt;/cite&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;&lt;cite&gt;An XHTML document must have a DOCTYPE declaration.  The html,  head, title, and body elements must also be present.&lt;/cite&gt;&lt;/p&gt; &lt;p&gt;Next came the tutorial on the search term which led me into this - &lt;a href="http://www.w3schools.com/css/default.asp"&gt;CSS&lt;/a&gt;.  To be honest,  now that I have confirmed what the initials stand for, I can't see that it will  be of much use to me.  For my purposes, the "styles" defined in HTML(1) -  H1, H2 etc - were more than enough for me.  I'm not looking to edit a  magazine here; I just want a page to host &lt;a href="http://www.interactived.com/jartest.htm"&gt;my Applet&lt;/a&gt;.  Just in  case, a style sheet is referenced inside the header as follows:&lt;/p&gt;  &lt;p&gt;  &lt;code&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;link rel="stylesheet" type="text/css" href="mystyle.css" /&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;/code&gt; &lt;/p&gt;  &lt;p&gt;And the style sheet itself is simply a text document saved with the .css  extension and written out something like this:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;hr {color:sienna;}&lt;br /&gt;p {margin-left:20px;}&lt;br /&gt;body {background-image:url("images/back40.gif");}&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;And the "cascading" works as follows:&lt;/p&gt;  &lt;p&gt;&lt;cite&gt;Generally speaking we can say that all the styles will "cascade" into a  new "virtual" style sheet by the following rules, where number four has the  highest priority:&lt;/cite&gt;&lt;/p&gt; &lt;ol&gt;&lt;li&gt;&lt;cite&gt;Browser default&lt;/cite&gt;&lt;/li&gt;&lt;li&gt;&lt;cite&gt;External style sheet&lt;/cite&gt;&lt;/li&gt;&lt;li&gt;&lt;cite&gt;Internal style sheet (in the head section)&lt;/cite&gt;&lt;/li&gt;&lt;li&gt;&lt;cite&gt;Inline style (inside an HTML element)&lt;/cite&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;cite&gt;So, an inline style (inside an HTML element) has the highest priority,  which means that it will override a style defined inside the &amp;lt;head&amp;gt; tag, or  in an external style sheet, or in a browser (a default value).&lt;/cite&gt;&lt;/p&gt;  &lt;p&gt;The tutorial goes on and on, but I think I have what I need for now.   And that's it for what W3Schools calls the HTML group of tutorials.  When I  saw XHTML in there I was hoping it might be just a trendy way of saying XML, but  I see now that it is part of a whole group on its own, so it is probably worthy  of its own blog entry.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-4200932470603909837?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/4200932470603909837/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=4200932470603909837' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4200932470603909837'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4200932470603909837'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/web-language-revision.html' title='Web language Revision'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-7546835152360078128</id><published>2011-08-17T22:45:00.000-07:00</published><updated>2011-08-18T05:02:13.166-07:00</updated><title type='text'>Mozilla JavaScript Learning Material</title><content type='html'>A Google search on "JavaScript Tutorial" brings up an abundance of online  learning materials.  I added Mozilla to the search string to find their &lt;a href="https://developer.mozilla.org/en/JavaScript/Getting_Started"&gt;Getting  Started with JavaScript&lt;/a&gt; page. &lt;p&gt;I can't resist commenting on the style of the page.  There are  comments like:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;JavaScript is a very easy language to start programming with. All you need is  a text editor and a web browser to get started.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;And:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;JavaScript is a great programming language for introductory computer  languages. It allows instant feedback to the new student and teaches them about  tools they will likely find useful in their real life. This is in stark contrast  to C, C++ and Java which are really only useful for dedicated software  developers.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;And then the first code example is:&lt;/p&gt; &lt;p&gt;  &lt;code&gt;&amp;lt;span onclick="alert ('Hello World!');"&amp;gt;Click Here&amp;lt;/span&amp;gt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;With zero explanation besides a list of mouse "events" other than  &lt;code&gt;onclick&lt;/code&gt;.   To be fair, the code works.  When slotted into an empty browser page, it  comes up as shown below:&lt;/p&gt; &lt;p&gt;&lt;a href="http://4.bp.blogspot.com/-c0-IxkmKM_0/TkypsKMp1RI/AAAAAAAAAH4/av33r4nKZzk/s1600/pic01.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 309px; height: 185px;" src="http://4.bp.blogspot.com/-c0-IxkmKM_0/TkypsKMp1RI/AAAAAAAAAH4/av33r4nKZzk/s320/pic01.JPG" alt="" id="BLOGGER_PHOTO_ID_5642071009305154834" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;and if you click over the text it comes up as shown below:&lt;/p&gt; &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-s6AZet67tXc/Tkyn1wmtkLI/AAAAAAAAAHg/KSt9quoYrAU/s1600/pic02.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 309px; height: 279px;" src="http://3.bp.blogspot.com/-s6AZet67tXc/Tkyn1wmtkLI/AAAAAAAAAHg/KSt9quoYrAU/s320/pic02.JPG" alt="" id="BLOGGER_PHOTO_ID_5642068975210565810" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The second code example is a more complex and wordy way of achieving the same  thing:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;function onclick_callback ()&lt;br /&gt;{&lt;br /&gt;alert ("Hello, World!");&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;span onclick="onclick_callback();"&amp;gt;Click Here&amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;Slotting that into an empty web page achieves exactly the same as shown in  the illustrations above.&lt;/p&gt;  &lt;p&gt;The third code example shows an even more complex way of achieving almost the  same thing:&lt;/p&gt; &lt;p&gt;&lt;code&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;function onclick_callback(event)&lt;br /&gt;{&lt;br /&gt;var eType = event.type;&lt;br /&gt;/* the following is for compatability */&lt;br /&gt;/* Moz populates the target property of the event object */&lt;br /&gt;/* IE populates the srcElement property */&lt;br /&gt;var eTarget = event.target || event.srcElement;&lt;br /&gt;&lt;br /&gt;alert ("Captured Event (type="+ eType +", target="+ eTarget);&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;span onclick="onclick_callback(event);"&amp;gt;Click Here&amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This shows the same text as before and the following message:&lt;/p&gt; &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-JQt1_LJIYhA/Tkyn2MlXdQI/AAAAAAAAAHo/acDl2W0qHAI/s1600/pic03.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 309px; height: 279px;" src="http://2.bp.blogspot.com/-JQt1_LJIYhA/Tkyn2MlXdQI/AAAAAAAAAHo/acDl2W0qHAI/s320/pic03.JPG" alt="" id="BLOGGER_PHOTO_ID_5642068982721115394" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The fourth code example introduces still more complexity, and this time the  message box (shown below) is invoked by a larger range of possible mouse events:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt; function mouseevent_callback(event)&lt;br /&gt; {&lt;br /&gt; /* The following is for compatability */&lt;br /&gt; /* IE does NOT by default pass the event object */&lt;br /&gt; /* obtain a ref to the event if one was not given */&lt;br /&gt; if (!event) event = window.event;&lt;br /&gt;&lt;br /&gt; /* obtain event type and target as earlier */&lt;br /&gt; var eType = event.type;&lt;br /&gt; var eTarget = event.target || event.srcElement;&lt;br /&gt; alert(eType +' event on element with id: '+ eTarget.id);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; function onload ()&lt;br /&gt; {&lt;br /&gt; /* obtain a ref to the 'body' element of the page */&lt;br /&gt; var body = document.body;&lt;br /&gt; /* create a span element to be clicked */&lt;br /&gt; var span = document.createElement('span');&lt;br /&gt; span.id = 'ExampleSpan';&lt;br /&gt; span.appendChild(document.createTextNode ('Click Here!'));&lt;br /&gt;&lt;br /&gt; /* register the span object to receive specific mouse events */&lt;br /&gt; span.onmousedown = mouseevent_callback;&lt;br /&gt; span.onmouseup = mouseevent_callback;&lt;br /&gt; span.onmouseover = mouseevent_callback;&lt;br /&gt; span.onmouseout = mouseevent_callback;&lt;br /&gt;&lt;br /&gt; /* display the span on the page */&lt;br /&gt; body.appendChild(span);&lt;br /&gt; }&lt;br /&gt; &amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt; function mouseevent_callback(event)&lt;br /&gt; {&lt;br /&gt; /* The following is for compatability */&lt;br /&gt; /* IE does NOT by default pass the event object */&lt;br /&gt; /* obtain a ref to the event if one was not given */&lt;br /&gt; if (!event) event = window.event;&lt;br /&gt;&lt;br /&gt; /* obtain event type and target as earlier */&lt;br /&gt; var eType = event.type;&lt;br /&gt; var eTarget = event.target || event.srcElement;&lt;br /&gt; alert(eType +' event on element with id: '+ eTarget.id);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; function onload ()&lt;br /&gt; {&lt;br /&gt; /* obtain a ref to the 'body' element of the page */&lt;br /&gt; var body = document.body;&lt;br /&gt; /* create a span element to be clicked */&lt;br /&gt; var span = document.createElement('span');&lt;br /&gt; span.id = 'ExampleSpan';&lt;br /&gt; span.appendChild(document.createTextNode ('Click Here!'));&lt;br /&gt;&lt;br /&gt; /* register the span object to receive specific mouse events */&lt;br /&gt; span.onmousedown = mouseevent_callback;&lt;br /&gt; span.onmouseup = mouseevent_callback;&lt;br /&gt; span.onmouseover = mouseevent_callback;&lt;br /&gt; span.onmouseout = mouseevent_callback;&lt;br /&gt;&lt;br /&gt; /* display the span on the page */&lt;br /&gt; body.appendChild(span);&lt;br /&gt; }&lt;br /&gt; &lt;/script&gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-nQyJdAOm-mA/Tkyn2F6cCJI/AAAAAAAAAHw/L99dFBcwqYY/s1600/pic04.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 309px; height: 279px;" src="http://3.bp.blogspot.com/-nQyJdAOm-mA/Tkyn2F6cCJI/AAAAAAAAAHw/L99dFBcwqYY/s320/pic04.JPG" alt="" id="BLOGGER_PHOTO_ID_5642068980930447506" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is great, but it's not really what I'm looking for.&lt;/p&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-7546835152360078128?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/7546835152360078128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=7546835152360078128' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/7546835152360078128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/7546835152360078128'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/mozilla-javascript-learning-material.html' title='Mozilla JavaScript Learning Material'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-c0-IxkmKM_0/TkypsKMp1RI/AAAAAAAAAH4/av33r4nKZzk/s72-c/pic01.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-1462619626222019904</id><published>2011-08-14T04:17:00.000-07:00</published><updated>2011-08-17T17:03:50.953-07:00</updated><title type='text'>Playing with PHP</title><content type='html'>I'm not sure who &lt;a href="http://www.w3schools.com/PHP/default.asp"&gt;w3schools&lt;/a&gt;  are, but they have a tutorial on PHP.  They offer a list of &lt;a href="http://www.w3schools.com/PHP/php_install.asp"&gt;things you need&lt;/a&gt;,  including MySQL, Apache and PHP.  I'm going to ignore this, because I am  tired of getting things to work at home and then scratching my head to make them  work on a production server.   &lt;p&gt;I do note however that my &lt;a href="http://webcity.com.au/"&gt;web host&lt;/a&gt;  claims to offer MySQL, Apache and PHP on its server.  I shall therefore do  all of my experimenting in a live environment.  Unprofessional perhaps, but  how many people look at &lt;a href="http://www.interactived.com/index.htm"&gt;my web  site&lt;/a&gt; anyway?&lt;/p&gt; &lt;p&gt;The first code sample is a good old "Hello World" message:&lt;/p&gt; &lt;p&gt; &lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;echo "Hello World";&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt; &lt;/code&gt; &lt;/p&gt; &lt;p&gt;I popped this in a text file, called it hello.php, and uploaded it to my web  host.  I then typed:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.interactived.com/hello.php"&gt; http://www.interactived.com/hello.php&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;into my browser, and what do you know, the following page appeared:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://4.bp.blogspot.com/-Q7ZjnZ_cIDE/TkeyKkeAQ0I/AAAAAAAAAGw/yZgOA-sHx6w/s1600/pic01.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 183px;" src="http://4.bp.blogspot.com/-Q7ZjnZ_cIDE/TkeyKkeAQ0I/AAAAAAAAAGw/yZgOA-sHx6w/s320/pic01.JPG" alt="" id="BLOGGER_PHOTO_ID_5640672952962794306" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So far so good.&lt;/p&gt;  &lt;p&gt;There followed a number of boring chapters on linguistics, most of which I  tried out but will omit here.  The next more interesting one was an example  of a form:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;form action="welcome.php" method="post"&amp;gt;&lt;br /&gt;&amp;lt;p align=right&amp;gt;&lt;br /&gt;Name: &amp;lt;input type="text" name="fname" /&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;Age: &amp;lt;input type="text" name="age" /&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;&amp;lt;input type="submit" /&amp;gt;&lt;br /&gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt; &lt;/code&gt;&lt;/p&gt;  &lt;p&gt;I saved this as hello.htm, uploaded it and typed:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.interactived.com/hello.php"&gt;http://www.interactived.com/hello.htm&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;into my browser.  A nice neat form appeared on the screen (see below)  and I typed Jonathan into the name field and 24 into the age field.  &lt;/p&gt;  &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-z5EEUGU4hnw/TkeyKkFrXzI/AAAAAAAAAG4/6FH4COS4muE/s1600/pic02.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 297px; height: 258px;" src="http://3.bp.blogspot.com/-z5EEUGU4hnw/TkeyKkFrXzI/AAAAAAAAAG4/6FH4COS4muE/s320/pic02.JPG" alt="" id="BLOGGER_PHOTO_ID_5640672952860761906" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Before clicking the Submit button, I also saved the following code as  welcome.php and uploaded it:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;Welcome &amp;lt;?php echo $_POST["fname"]; ?&amp;gt;!&amp;lt;br /&amp;gt;&lt;br /&gt;You are &amp;lt;?php echo $_POST["age"]; ?&amp;gt; years old.&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;Then, when I clicked the Submit button, the following text appeared in the  browser:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-v79M3dXFCWU/TkeyK9rsv_I/AAAAAAAAAHA/S_iMnqO5cZI/s1600/pic03.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 297px; height: 258px;" src="http://1.bp.blogspot.com/-v79M3dXFCWU/TkeyK9rsv_I/AAAAAAAAAHA/S_iMnqO5cZI/s320/pic03.JPG" alt="" id="BLOGGER_PHOTO_ID_5640672959731122162" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Most interestingly (for me at least), when I tried to view the source code,  it came up as shown below.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-i0xhEANo5Z4/TkeyK6g2kuI/AAAAAAAAAHI/hwTTKCNAGRk/s1600/pic04.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 182px;" src="http://3.bp.blogspot.com/-i0xhEANo5Z4/TkeyK6g2kuI/AAAAAAAAAHI/hwTTKCNAGRk/s320/pic04.JPG" alt="" id="BLOGGER_PHOTO_ID_5640672958880322274" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;So the source code displayed was the rendered HTML, and NOT the PHP source  code.  This is quite good news, although I am still not quite sure how  secure that PHP file is.&lt;/p&gt;  &lt;p&gt;After skipping more linguistics chapters the time came to try a data  connection.  As I had deleted nearly everything from my table in a previous  exercise, I decided to try an insert:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;$con = mysql_connect("localhost","peter","abc123");&lt;br /&gt;if (!$con)&lt;br /&gt;{&lt;br /&gt;die('Could not connect: ' . mysql_error());&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;mysql_select_db("dbAMJ", $con);&lt;br /&gt;&lt;br /&gt;mysql_query("INSERT INTO Items (Partid, OpCode, Itemdet, Raw, Rate)&lt;br /&gt;VALUES (1, 1, '2+2=', 1, 1), (1, 1, '3+3=', 1, 1)");&lt;br /&gt;&lt;br /&gt;mysql_close($con);&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;I substituted my credentials, saved it as dbtestin.php, uploaded it and tried  it in the browser.  That code displays nothing on success (or failure of  the sql query), so I visited my &lt;a href="http://webcity.com.au/"&gt;web host&lt;/a&gt;  again and used their &lt;a href="http://www.phpmyadmin.net/home_page/index.php"&gt; phpMyAdmin&lt;/a&gt;&lt;span lang="en-us"&gt; facility to check that the extra lines had  been inserted, and sure enough they had.&lt;/span&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt; &lt;p&gt;&lt;span lang="en-us"&gt;I then tried the following code to apply a simple query:&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;$con = mysql_connect("localhost","peter","abc123");&lt;br /&gt;if (!$con)&lt;br /&gt; {&lt;br /&gt; die('Could not connect: ' . mysql_error());&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;mysql_select_db("dbAMJ", $con);&lt;br /&gt;&lt;br /&gt;$result = mysql_query("SELECT * FROM Items") or die(mysql_error());&lt;br /&gt;&lt;br /&gt;echo "&amp;lt;table border='1'&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&lt;br /&gt;&amp;lt;th&amp;gt;Itemdet&amp;lt;/th&amp;gt;&lt;br /&gt;&amp;lt;th&amp;gt;Raw&amp;lt;/th&amp;gt;&lt;br /&gt;&amp;lt;/tr&amp;gt;";&lt;br /&gt;&lt;br /&gt;while($row = mysql_fetch_array($result))&lt;br /&gt;{&lt;br /&gt;echo "&amp;lt;tr&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['Itemdet'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;td&amp;gt;" . $row['Raw'] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;echo "&amp;lt;/tr&amp;gt;";&lt;br /&gt;}&lt;br /&gt;echo "&amp;lt;/table&amp;gt;";&lt;br /&gt;&lt;br /&gt;mysql_close($con);&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;The following table was displayed:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-YJUNMDcx9zE/TkxVrQXSyKI/AAAAAAAAAHQ/32NW36u636Y/s1600/pic05.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 301px; height: 317px;" src="http://2.bp.blogspot.com/-YJUNMDcx9zE/TkxVrQXSyKI/AAAAAAAAAHQ/32NW36u636Y/s320/pic05.JPG" alt="" id="BLOGGER_PHOTO_ID_5641978634803792034" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;span lang="en-us"&gt;So it seems that I can run PHP on my live web site, and I  can use it to connect to my database.  Furthermore, the PHP source code  does not appear to be accessible for viewing in the browser.  This would  appear to be a step in the right direction.&lt;/span&gt;&lt;/p&gt;      &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-1462619626222019904?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/1462619626222019904/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=1462619626222019904' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/1462619626222019904'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/1462619626222019904'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/playing-with-php.html' title='Playing with PHP'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-Q7ZjnZ_cIDE/TkeyKkeAQ0I/AAAAAAAAAGw/yZgOA-sHx6w/s72-c/pic01.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-1316788998647606699</id><published>2011-08-13T04:26:00.000-07:00</published><updated>2011-08-13T04:28:59.317-07:00</updated><title type='text'>J2EE</title><content type='html'>&lt;p&gt;Three years ago I began this blog with a discussion of &lt;a href="http://download.oracle.com/javase/tutorial/index.html"&gt;The Java  Tutorial&lt;/a&gt;.  I didn't read it from top to bottom.  I took what I  needed to do what I wanted to do.  I left some quite large chunks unread,  so when I decided to research &lt;a href="http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html"&gt;Java  Servlets&lt;/a&gt;, I fully expected to find them there.&lt;/p&gt; &lt;p&gt;Certainly they were part of a &lt;a href="http://java.sun.com/j2ee/tutorial/1_3-fcs/index.html"&gt;tutorial&lt;/a&gt;, but  it had an unfamiliar feel to it.  When I clicked on the home link, I found  myself looking at the &lt;a href="http://java.sun.com/j2ee/tutorial/1_3-fcs/index.html"&gt;J2EE 1.3 Tutorial&lt;/a&gt;  - &lt;i&gt;"A beginner's guide to developing enterprise applications on the Java 2  Platform, Enterprise Edition SDK version 1.3"&lt;/i&gt;.&lt;/p&gt; &lt;p&gt;"Beginners guide" sounds good, but "developing enterprise applications" is something I neither need nor want to do.&lt;/p&gt; &lt;p&gt;In my &lt;a href="http://jhippjava.blogspot.com/2008/09/where-to-start.html"&gt; first post&lt;/a&gt; I suggested that using NetBeans to craft "Hello World" was like  using a sledge hammer to crack a nut, and at first glance, using J2EE to make a  simple connection between &lt;a href="http://www.interactived.com/jartest0904.htm"&gt; my little applet&lt;/a&gt; and a database is worthy of the same analogy.  There  has to be a simpler way to do it.&lt;/p&gt; &lt;p&gt;During my VB programming days I used &lt;a href="http://en.wikipedia.org/wiki/Active_Server_Pages"&gt;ASP&lt;/a&gt;, the MS  equivalent of &lt;a href="http://en.wikipedia.org/wiki/JavaServer_Pages"&gt;JSP&lt;/a&gt;,  and it really wasn't that hard.  In those days, I owned the server, and  controlled everything on it, including user accounts and passwords.  From  memory, the user had to supply credentials every time they accessed the intranet  site, so the issue of embedding credentials in code didn't arise.&lt;/p&gt; &lt;p&gt;I have just touched base with my &lt;a href="http://webcity.com.au/"&gt;web host&lt;/a&gt;,  and from my account stats, as well as a MySQL version number, I see one for  Apache and PHP.  I guess that means I can use PHP.  I've never done so  before, but from the &lt;a href="http://www.w3schools.com/PHP/php_mysql_connect.asp"&gt;w3schools site&lt;/a&gt;,  connecting to a MySQL database doesn't look very hard.&lt;/p&gt; &lt;p&gt;A couple of questions arise.  First where is the PHP code hidden, and is  that a better place to hide my username and password than an Applet?   Second, can my Applet talk to the PHP code and &lt;i&gt;vice versa&lt;/i&gt;?  I  suspect the answer to both questions is NO, but at least reading up on PHP looks  a little less daunting than J2EE.&lt;/p&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-1316788998647606699?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/1316788998647606699/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=1316788998647606699' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/1316788998647606699'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/1316788998647606699'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/j2ee.html' title='J2EE'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-2512082282519525657</id><published>2011-08-11T21:35:00.000-07:00</published><updated>2011-08-11T21:37:06.734-07:00</updated><title type='text'>A few notes on JavaScript</title><content type='html'>&lt;p&gt;I am one the 99% of the world who has long nursed the misconception that  JavaScript has something to do with Java.  And why not?  The name sort  of implies it.&lt;/p&gt; &lt;p&gt;It was only after I searched without success on the &lt;a href="http://download.oracle.com/javase/tutorial/index.html"&gt;Java Tutorial&lt;/a&gt;  site for some mention of JavaScript that I stumbled across the knowledge that  JavaScript was in fact developed by Netscape, under the name LiveScript.   Armed with that knowledge, it is not surprising to find the best reference  information on &lt;a href="https://developer.mozilla.org/en/javascript"&gt;Mozilla&lt;/a&gt;  site.&lt;/p&gt; &lt;p&gt;According to &lt;a href="http://en.wikipedia.org/wiki/JavaScript"&gt;Wikipedia&lt;/a&gt;,  the nonsensical name choice had something to do with Netscape wanting to cash in  on the popularity and &lt;i&gt;cachet&lt;/i&gt; of Java, and Sun wanting support for Java  technology in the then popular Netscape browser.&lt;/p&gt; &lt;p&gt;For a while only the Netscape family of browsers supported JavaScript.   Microsoft later produced what it calls JScript to run in its browser.   JScript is similar but not identical to Javascript.&lt;/p&gt; &lt;p&gt;According to &lt;a href="http://foldoc.org/javascript"&gt;Foldoc&lt;/a&gt; JavaScript  runs a hundred times slower than &lt;a href="http://foldoc.org/C"&gt;C&lt;/a&gt;, and ten  times slower than Java.&lt;/p&gt; &lt;p&gt;According to &lt;a href="http://en.wikipedia.org/wiki/JavaScript"&gt;Wikipedia&lt;/a&gt;:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;JavaScript very quickly gained widespread success as a  client-side scripting language for web pages [and] has become one of the most  popular programming languages on the web. Initially ... many professional  programmers denigrated the language because its target audience was web authors  and other such "amateurs" ... The advent of &lt;a title="Ajax (programming)" href="/wiki/Ajax_%28programming%29"&gt;Ajax&lt;/a&gt; returned  JavaScript to the spotlight and brought more professional programming attention.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;So what is &lt;a title="Ajax (programming)" href="/wiki/Ajax_%28programming%29"&gt;Ajax&lt;/a&gt;?   The link is to another Wiki page, which gives lots of details, but I'll quote a  bit of the history, as it mentions Applets:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;In the 1990s, most web sites were based on complete HTML  pages; each user action required that the page be re-loaded from the server (or  a new page loaded) ... Asynchronous loading of content first became practical  when Java applets were introduced in the first version of the Java language in  1995. These allow compiled client-side code to load data asynchronously from the  web server after a web page is loaded.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;But as I have reported in previous posts, Applets are fraught with  difficulties.  This brings me back to the definition of &lt;a title="Ajax (programming)" href="/wiki/Ajax_%28programming%29"&gt;Ajax&lt;/a&gt;, which is  an acronym for "asynchronous JavaScript and XML"&lt;/p&gt; &lt;p&gt;In summary, JavaScript is a scripting language used in web pages in  conjunction with other languages and technologies to achieve ends more complex  than can be achieved with simple HTML.  The language looks a bit like Java  (and C) and meshes with Java, but it was developed independently by the creators  of the Netscape browser.&lt;/p&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-2512082282519525657?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/2512082282519525657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=2512082282519525657' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/2512082282519525657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/2512082282519525657'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/few-notes-on-javascript.html' title='A few notes on JavaScript'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-4636414784401164610</id><published>2011-08-06T08:22:00.000-07:00</published><updated>2011-08-06T08:28:42.290-07:00</updated><title type='text'>Forum Comments on Java Applets</title><content type='html'>&lt;p&gt;It is so long since I last posted on the &lt;a href="http://forums.oracle.com/forums/main.jspa?categoryID=84"&gt;once was  Sun/Java now is Oracle developer forum&lt;/a&gt; my account seems to have been  ditched.  While I wait to have it resurrected I've done a little searching  in the &lt;a href="http://forums.oracle.com/forums/forum.jspa?forumID=1050"&gt;Java  Database Connectivity (JDBC) forum&lt;/a&gt; using the search term "Applet".&lt;/p&gt; &lt;p&gt;My first search, using the default 3 month period, yielded nothing.  No  one had posted anything about or even mentioned Applets in the last three  months.  So either they are very easy to use and work very well, so hardly  anyone has any problems with them, or maybe ... not very many people use them at  all.&lt;/p&gt; &lt;p&gt;My stomach was beginning to churn a bit, when I extended the search period to  the current year - and with good reason.  Somebody, a little bit like me I  think, had written a game in an applet, and wanted to record top scores in a  database.  He described his connection problem in &lt;a href="http://forums.oracle.com/forums/thread.jspa?messageID=9413426&amp;amp;"&gt;this  thread&lt;/a&gt;, and the first reply began:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;Doing JDBC calls from an Applet is such a bad idea that I am  glad you are having trouble with it. You might want to reconsider your design!  If you persist on going this way, I can tell you that there will be many more  even more difficult hurdles that you will need to overcome which would make this  problem seem like a piece of cake ...&lt;/span&gt;&lt;/p&gt; &lt;p&gt;The OP opened his question with the phrase:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;I'm trying to write a very basic test applet ...&lt;/span&gt;&lt;/p&gt; &lt;p&gt;One reply to this specific phrase was:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;You may as well be hunting unicorns. Applets are never easy.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;Another reply, to the post as a whole began:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;Apart from the bad idea of connecting to your db from an  applet (security is one that springs to mind ...&lt;/span&gt;&lt;/p&gt; &lt;p&gt;and concluded his reply with:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;...Exactly how this wires up for an applet I can't say since  I've not written one in a decade. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So perhaps 10 years ago Applets were "hip" for whatever reason, but now they  seem definitely not to be.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://forums.oracle.com/forums/thread.jspa?messageID=9270558&amp;amp;"&gt;Another  thread&lt;/a&gt; actually opened with a quote from another website, inviting comments  and clarification.  The quote was:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;It is generally not a good idea to use JDBC directly in an  Applet. You need to presume some brat will decompile your Applet and use that  knowledge to create a substitute Applet that causes as much havoc as possible.  If your Applet has direct access to JDBC, the brat’s substitute can snoop or  pillage the database to its heart’s content.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;Most of the posts are pretty uncomplimentary about Applets and the ODBC-JDBC  bridge (which I looked at but gave up on because it was too hard to get it to  work), but one of them suggests a solution using servlets:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;What you could do is write two servlets. One is called "gimmethescores".  The applet calls http://www.example.com/gimmethescores and gets a list of high  scores to display. You can use a simple line by line text format, or XML, or  whatever you wish.&lt;br /&gt;&lt;br /&gt;The other servlet is "setscore". After the game is over, the applet calls  http://www.example.com/setscore?user=jim&amp;amp;score=1050. The servlet then checks the  parameters look sane and updates the high score table.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So now I'm thinking I need to study up on servlets.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-4636414784401164610?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/4636414784401164610/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=4636414784401164610' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4636414784401164610'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4636414784401164610'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/forum-comments-on-java-applets.html' title='Forum Comments on Java Applets'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-4085721503557381229</id><published>2011-08-04T06:20:00.000-07:00</published><updated>2011-08-04T06:26:21.120-07:00</updated><title type='text'>Webcity</title><content type='html'>&lt;p&gt;&lt;a href="http://www.interactived.com/softway.htm"&gt;My web site&lt;/a&gt; is hosted by &lt;a href="http://webcity.com.au/"&gt;WebCity&lt;/a&gt;&lt;span lang="en-us"&gt;,  an Australian domain registrar and web host, whose motto is "Self Service  Savings".&lt;/span&gt;  &lt;span lang="en-us"&gt;And when they say self service they  mean &lt;i&gt;self&lt;/i&gt; service.  &lt;/span&gt;They  offer a&lt;span lang="en-us"&gt; very comprehensive&lt;/span&gt; &lt;a href="http://help.webcity.com.au/"&gt;self help library&lt;/a&gt;, &lt;span lang="en-us"&gt;supplemented by a range of good&lt;/span&gt; video tutorial&lt;span lang="en-us"&gt;s,  but the whole site is somewhat cryptic, if you don't know your way around, and  they don't really like being contacted.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span lang="en-us"&gt;However, they are also true to their word on savings.  Certainly they saved me money on my original domain registrar and on my  traditional ISP.  The ISP offered free web space, but charged a ridiculous  annual fee to domain holders.  This didn't include domain registration,  which I paid for separately.  I guess it covered the one off three minute  task of letting the domain registrar know my physical web address, but apart  from that, I have no idea how they justified it.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span lang="en-us"&gt;Webcity also offer a MySQL server, and when I plucked  courage to ask them about it they assured me that it was on the same server as  my web code, and that the server name "localhost" should be used for  connections.  That sounded pretty good news.  It might be an unusual  set up, but it gives me a chance to try out my existing Applet code on a  commercial server, before re-writing in a more rigorous or generalist way.   I therefore set about creating a database on their server.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span lang="en-us"&gt;I mentioned that the Webcity web site is a bit cryptic.   Most websites offer on their home page a bold login button, or clearly labeled  user id and password fields.  Not so this one.  You have to know to  type "yourdomain/cPanel" into the address field of your browser, and then you  will be offered user id and password fields to fill in.  &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span lang="en-us"&gt;The cPanel, as the name suggests, is a bit like the  Control Panel in Windows, with an array of icons allowing you to tweak this and  that.  They are arranged into groups such as mail files, logs etc.  Well  down the page is a group called Databases.  The first item called MySQL  databases offers a GUI to create databases and users.  Another item, called&lt;/span&gt; &lt;a href="http://www.phpmyadmin.net/home_page/index.php"&gt;phpMyAdmin&lt;/a&gt;&lt;span lang="en-us"&gt;,&lt;/span&gt; offers  a  GUI to create a table and define fields&lt;span lang="en-us"&gt; in one tab, and in  another tab it offers an SQL window to type or paste one's own queries.&lt;/span&gt;  I&lt;span lang="en-us"&gt;  cut and pasted the one I had used to create the &lt;a href="http://jhippjava.blogspot.com/2011/07/creating-mysql-database-for-gui-applet.html"&gt; dbAMJ&lt;/a&gt;&lt;/span&gt;&lt;a href="http://jhippjava.blogspot.com/2011/07/creating-mysql-database-for-gui-applet.html"&gt; &lt;span lang="en-us"&gt;database&lt;/span&gt;&lt;/a&gt;&lt;span lang="en-us"&gt; on my own server.   It ran fine, and I added a few lines in the format I intend to use.  That  was fine, and I deleted a couple as well.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span lang="en-us"&gt;I then modified my applet code to include the following  URL for the database:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;code&gt;String url = "jdbc:mysql://localhost:3306/int22853_dbAMJ";&lt;/code&gt;&lt;/p&gt; &lt;p&gt;&lt;span lang="en-us"&gt;I modified the username and password for Webcity, compiled  and uploaded the code files and uploaded the MySQL JDBC driver.  I included  in the code modifications a few extra diagnostic messages.  The applet is  designed to display these in a text field.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span lang="en-us"&gt;The applet loaded, and it displayed a message to confirm  that the JDBC driver had been loaded.  It then displayed an extra message  to confirm that it had moved to the next line of code.  But nothing came  back from the connection "Try" loop.  There was no success message and no  fail or error message.  It was as if it just did not run.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span lang="en-us"&gt;It did this from the website hosted by Webcity, and it did  exactly the same on the site hosted on my own IIS server.  So after a break  of two years, I think I need to post a question in the Java forum.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-4085721503557381229?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/4085721503557381229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=4085721503557381229' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4085721503557381229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4085721503557381229'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/webcity.html' title='Webcity'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-3203336829958126355</id><published>2011-08-03T16:44:00.000-07:00</published><updated>2011-08-03T16:45:42.691-07:00</updated><title type='text'>Limitations of Java Applets</title><content type='html'>&lt;p&gt;Having installed IIS, I was still struggling to get my Applet to connect to  the MySQL database, and I stumbled across &lt;a href="http://www.java-forums.org/java-applets/39326-applet-connection-mysql-database-using-jdbc.html"&gt; this post&lt;/a&gt;.  The grammar is questionable but of relevance to me is:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;This keeps coming up ... applets trying to make JDBC database  connections don't work in general ... Mainly because JDBC is a server side  technology. Where applets may only always and forever communicate with the HTTP  server ... which they originated from (same server as their code base) ... and  in general the database will almost always be on a different server.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;In other words, it doesn't matter how hard I work to get the Applet working  at home, when I upload to my ISP it probably won't work, because their MySQL  server is most likely on a different box to the web server with my code on it.   I guess I could send them a question, but if I want to make my code robust, I  probably need a more general solution.  &lt;a href="http://www.java-forums.org/java-applets/39326-applet-connection-mysql-database-using-jdbc.html"&gt; The post quoted above&lt;/a&gt; goes on to suggest solutions, but at this stage of my  knowledge development they are all gibberish to me.  I'll quote them  because they include a nice collection of search strings for possible use in my  research:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;So, we need some kind of web service or custom query  mechanism, e.g. XML RPC over HTTP, or JSON over HTTP ... where we have the  APPLET invoke HTTP requests to a Servlet in the server ... which receives these  requests (also handles authentication, authorization) and then uses a JDBC  connection to the database to invoke some query, unpack the result set into the  HTTP servlet response in a suitable format (e.g XML, JSON, etc, what ever was  used for request and what ever the applet is expecting as a response).&lt;br /&gt;&lt;br /&gt;[This] means you'd need a web app at least with a servlet listening on a URL  that your applet is able to invoke, and have the database JDBC connection  available to this servlet.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;Years ago I posted a question on some Java forum about JDBC and Applets, and  I was asked why I was using an Applet and not writing a web application with  Java Script.  I gave some bullshit answer at the time, but the honest  answer would have been that I had never used Java script, and didn't know the  first thing about it.  I have used Java, I have used VB script, and I  have used HTML, so I can't believe it would be that hard; but I guess I need to  hit the text books again.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-3203336829958126355?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/3203336829958126355/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=3203336829958126355' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3203336829958126355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3203336829958126355'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/08/limitations-of-java-applets.html' title='Limitations of Java Applets'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-4208256246086307290</id><published>2011-07-31T20:30:00.000-07:00</published><updated>2011-08-03T16:11:06.472-07:00</updated><title type='text'>Microsoft Internet Information Services (IIS)</title><content type='html'>When I referred to &lt;a href="http://jhippjava.blogspot.com/2009/01/joys-of-microsoft-iis.html"&gt;my  last post on Microsoft IIS&lt;/a&gt;, I was disappointed to find that it was little more  than a set of cryptic references to broken links.   So in case I ever need to do this again, I shall include more detail this time. &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-xByrz9KvubE/TjYqmetJN1I/AAAAAAAAAGQ/iyv885dGvZw/s1600/IIS01.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 247px;" src="http://3.bp.blogspot.com/-xByrz9KvubE/TjYqmetJN1I/AAAAAAAAAGQ/iyv885dGvZw/s320/IIS01.JPG" alt="" id="BLOGGER_PHOTO_ID_5635738824266561362" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;IIS is a Windows component, which by default is not installed on the  non-server editions.  To install it, you open Windows components (via Add  or Remove Programs in XP), and check the IIS box (see above).  It really  helps if you have the install CD used to install your system, &lt;i&gt;and&lt;/i&gt; for it  to have the same Service Pack level as your current OS (and with XP this  should be SP3).&lt;/p&gt; &lt;p&gt;&lt;a href="http://4.bp.blogspot.com/-UMKqKLojRxY/TjYqmiq9aSI/AAAAAAAAAGY/5vSnahi29lM/s1600/IIS02.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 89px;" src="http://4.bp.blogspot.com/-UMKqKLojRxY/TjYqmiq9aSI/AAAAAAAAAGY/5vSnahi29lM/s320/IIS02.JPG" alt="" id="BLOGGER_PHOTO_ID_5635738825331140898" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Once installed you can open IIS via Administrative Tools in the Control Panel  (see above).&lt;/p&gt; &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/-0lXEGszbfYc/TjYqm9mfb-I/AAAAAAAAAGg/39jw9ks79Qo/s1600/IIS03.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 243px;" src="http://3.bp.blogspot.com/-0lXEGszbfYc/TjYqm9mfb-I/AAAAAAAAAGg/39jw9ks79Qo/s320/IIS03.JPG" alt="" id="BLOGGER_PHOTO_ID_5635738832560156642" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Expand the local computer node and the websites node to find the default web  site (which contains the IIS help files - see above).&lt;/p&gt; &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/-wqI_r5teTAY/TjYqmwJpxxI/AAAAAAAAAGo/sXtnLfLry1A/s1600/IIS04.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 243px;" src="http://1.bp.blogspot.com/-wqI_r5teTAY/TjYqmwJpxxI/AAAAAAAAAGo/sXtnLfLry1A/s320/IIS04.JPG" alt="" id="BLOGGER_PHOTO_ID_5635738828949538578" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Right click over this and, from the context menu, select New and Virtual  Directory (see above).&lt;/p&gt; &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-q32KHHrKmOE/TjYqQT40h8I/AAAAAAAAAGI/dfpWorBcmks/s1600/IIS05.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 253px;" src="http://2.bp.blogspot.com/-q32KHHrKmOE/TjYqQT40h8I/AAAAAAAAAGI/dfpWorBcmks/s320/IIS05.JPG" alt="" id="BLOGGER_PHOTO_ID_5635738443405625282" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This opens the Virtual directory creation wizard (see above).&lt;/p&gt; &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-4-EbxQ9BR-4/TjYqGqg3kzI/AAAAAAAAAGA/FOUYgO5j5ek/s1600/IIS06.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 253px;" src="http://2.bp.blogspot.com/-4-EbxQ9BR-4/TjYqGqg3kzI/AAAAAAAAAGA/FOUYgO5j5ek/s320/IIS06.JPG" alt="" id="BLOGGER_PHOTO_ID_5635738277680485170" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Give the virtual directory a name which means something to you.  I  called mine AMWeb, with AM being short for Active Math (see above).&lt;/p&gt; &lt;p&gt;&lt;a href="http://2.bp.blogspot.com/-An6sR4SQfQw/TjYpbSRIuyI/AAAAAAAAAFw/_CCLVMVHRew/s1600/IIS07.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 253px;" src="http://2.bp.blogspot.com/-An6sR4SQfQw/TjYpbSRIuyI/AAAAAAAAAFw/_CCLVMVHRew/s320/IIS07.JPG" alt="" id="BLOGGER_PHOTO_ID_5635737532437674786" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I then used the Browse button to navigate to a local copy of my web site (see  above).&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-uNkdhSEZuwE/TjYpJXL1G5I/AAAAAAAAAFo/iDKZeheKO9E/s1600/IIS08.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 253px;" src="http://3.bp.blogspot.com/-uNkdhSEZuwE/TjYpJXL1G5I/AAAAAAAAAFo/iDKZeheKO9E/s320/IIS08.JPG" alt="" id="BLOGGER_PHOTO_ID_5635737224519949202" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The next page sets the permissions for the web site.  I checked  everything except write (see above).&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-Y8dp7Xl8scY/TjYny5xtJtI/AAAAAAAAAFg/0ebrRs9YXV4/s1600/IIS10.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 243px;" src="http://1.bp.blogspot.com/-Y8dp7Xl8scY/TjYny5xtJtI/AAAAAAAAAFg/0ebrRs9YXV4/s320/IIS10.JPG" alt="" id="BLOGGER_PHOTO_ID_5635735739156997842" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;After clicking through the final page of the wizard, you can see the IIS  layout again with a new node for the web site.&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-uExt47XbuOQ/TjYkaSzIMSI/AAAAAAAAAFY/e0evmbnGuCc/s1600/IIS12.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 254px; height: 320px;" src="http://2.bp.blogspot.com/-uExt47XbuOQ/TjYkaSzIMSI/AAAAAAAAAFY/e0evmbnGuCc/s320/IIS12.JPG" alt="" id="BLOGGER_PHOTO_ID_5635732017842237730" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;For belt and braces, I right click over the default web site and select  properties (see above).&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-1cfYX9eVaXs/TjYkaL4D2LI/AAAAAAAAAFQ/AoIvziLOK1g/s1600/IIS16.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 315px;" src="http://4.bp.blogspot.com/-1cfYX9eVaXs/TjYkaL4D2LI/AAAAAAAAAFQ/AoIvziLOK1g/s320/IIS16.JPG" alt="" id="BLOGGER_PHOTO_ID_5635732015983876274" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;From there I select the Home Directory tab and make the permissions match my  web site (see above).  I'm not sure you really need to do this, but it  makes me feel better.&lt;/p&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-VZo5kI75wsI/TjYh21m2nDI/AAAAAAAAAFI/MtYvybgkZ3g/s1600/IIS18.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 285px; height: 320px;" src="http://2.bp.blogspot.com/-VZo5kI75wsI/TjYh21m2nDI/AAAAAAAAAFI/MtYvybgkZ3g/s320/IIS18.JPG" alt="" id="BLOGGER_PHOTO_ID_5635729209687448626" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;However, I am sure you need to carry out one more task.  Using Windows  Explorer navigate to the directory actually holding your web files.  Hover  over the folder node, right click, and select Sharing and Security (see above).&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-rqsOIPNunAI/TjYh2sDSDhI/AAAAAAAAAFA/nPk5GERE1sc/s1600/IIS19.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 259px; height: 320px;" src="http://1.bp.blogspot.com/-rqsOIPNunAI/TjYh2sDSDhI/AAAAAAAAAFA/nPk5GERE1sc/s320/IIS19.JPG" alt="" id="BLOGGER_PHOTO_ID_5635729207122333202" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Check Share this folder on the network (see above).&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-5Y2FtgE5Bxs/TjYeWa2B8GI/AAAAAAAAAE4/PP4q-jGpDV8/s1600/IIS20.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 214px;" src="http://3.bp.blogspot.com/-5Y2FtgE5Bxs/TjYeWa2B8GI/AAAAAAAAAE4/PP4q-jGpDV8/s320/IIS20.JPG" alt="" id="BLOGGER_PHOTO_ID_5635725354212651106" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;It was only after doing this that I was actually able to view my web in a  browser (see above).&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-4208256246086307290?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/4208256246086307290/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=4208256246086307290' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4208256246086307290'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4208256246086307290'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/07/microsoft-internet-information-services.html' title='Microsoft Internet Information Services (IIS)'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-xByrz9KvubE/TjYqmetJN1I/AAAAAAAAAGQ/iyv885dGvZw/s72-c/IIS01.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-7842757308338828617</id><published>2011-07-30T05:11:00.000-07:00</published><updated>2011-07-30T05:16:38.993-07:00</updated><title type='text'>Running Code for a GUI Applet</title><content type='html'>&lt;p&gt;On my first attempt at running the modified &lt;a href="http://www.interactived.com/jartest0906.htm"&gt;Applet&lt;/a&gt; from within a  web page, I was delighted to observe that it worked.  I then noticed the  following lines of code:&lt;/p&gt; &lt;p&gt; &lt;code&gt;/**&lt;br /&gt;* These are implementation variables&lt;br /&gt;*/&lt;br /&gt;boolean dbDEBUG = false;&lt;br /&gt;boolean mathDEBUG = false;&lt;br /&gt;boolean LIVE = false; &lt;/code&gt; &lt;/p&gt; &lt;p&gt;I had very cunningly (in my opinion) put in a safety check.  By default,  no attempt is made to attempt to connect to a database, and the applet just runs  without it.  So I had not been so clever with the coding change as I  initially thought.  The applet had run, but without attempting to implement  the new connection code.  So with great trepidation I changed both &lt;code&gt;boolean  LIVE&lt;/code&gt; and &lt;code&gt;boolean dbDEBUG&lt;/code&gt; to true, recompiled, and tried again.&lt;/p&gt; &lt;p&gt;Again to my delight, the applet opened, and there was even a debug message  saying:&lt;/p&gt; &lt;p&gt;&lt;code&gt;starting... driver succeeds...&lt;/code&gt;&lt;/p&gt; &lt;p&gt;However my joy subsided when I clicked the "&lt;a href="http://www.interactived.com/jartest0906.htm"&gt;Click  to begin&lt;/a&gt;" button, entered an answer clicked "Check Answer" and the debug  field read:&lt;/p&gt; &lt;p&gt;&lt;code&gt;SQLException: nullSQLException: null.&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The original text file class, used to create the database in Derby, included  some code to populate a few lines.  On reflection, I could see why I  included this, and that perhaps it would have been a good idea to run it first.&lt;/p&gt; &lt;p&gt;So I modified the class to connect to MySQL, renamed it to &lt;code&gt;ItemdbTest&lt;/code&gt;, and compiled it.  I also modified  another text file/command line class, &lt;code&gt;ItemdbQuery&lt;/code&gt;, which runs a simple query and displays the  table contents.  The SQL for the insert was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;"INSERT INTO Items " +&lt;br /&gt;"(Partid, OpCode, Itemdet, Raw, Rate) " +&lt;br /&gt;"VALUES (1, 1, '1+1=', 1, 1), " +&lt;br /&gt;"(1, 1, '2+2=', 1, 1), " +&lt;br /&gt;"(1, 1, '3+3=', 1, 1)";&lt;/code&gt;&lt;/p&gt; &lt;p&gt;That ran fine.  The SQL for the simple query was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;"SELECT * FROM Items"&lt;/code&gt;&lt;/p&gt; &lt;p&gt;and the output was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;try connection&lt;br /&gt;connection succeeds&lt;br /&gt;try query&lt;br /&gt;1 1 1 1+1= 1 1&lt;br /&gt;2 1 1 2+2= 1 1&lt;br /&gt;3 1 1 3+3= 1 1&lt;br /&gt;query succeeds&lt;br /&gt;disconnection succeeds&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;Now the SQL used here is supposed to reflect that in the Applet, so it was  strange that the Applet is falling over, when a similar command from the command  line was working.  &lt;/p&gt; &lt;p&gt;On further investigation, the answer lay on the &lt;a href="http://download.oracle.com/javase/tutorial/deployment/applet/security.html"&gt; What Applets Can and Cannot Do&lt;/a&gt; page in the &lt;a href="http://download.oracle.com/javase/tutorial/index.html"&gt;Java Tutorial&lt;/a&gt;.   I remember when I was first trying to use the Derby embedded driver, an applet  can't make changes on the local machine.  So I shall have to set up IIS on  either this or another machine, set MySQL to accept outside connections, and  start again.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-7842757308338828617?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/7842757308338828617/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=7842757308338828617' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/7842757308338828617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/7842757308338828617'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/07/running-code-for-gui-applet.html' title='Running Code for a GUI Applet'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-1667530281924660536</id><published>2011-07-28T05:34:00.000-07:00</published><updated>2011-07-29T02:01:04.137-07:00</updated><title type='text'>Creating a MySQL database for a GUI applet</title><content type='html'>&lt;p&gt;Thus far I have been working entirely with what I call text file code, run from the  command line, and with nothing to see beyond a few cryptic messages to the  screen.  The process was interesting because it revealed differences in the  required coding modifications extend beyond making the connection and include  minor but critical differences in the SQL itself.&lt;/p&gt; &lt;p&gt;The next step is to modify a GUI applet.  It is ages since I  cobbled this together, so I have no idea  where to begin.  From memory there is &lt;a href="http://www.interactived.com/jartest0906.htm"&gt;something sitting on a  website&lt;/a&gt;, which does not connect to a database, and there is a link  (deliberately not hyperlinked here) to another applet sitting on my own server.   That server has long been consigned to the bin, and by now the disk back up  probably also erased.&lt;/p&gt; &lt;p&gt;My habit with code is to store it in many places and to give the locations  labels which will have absolutely no meaning to me when I come looking for it  later.  While I was fumbling around my local hard drive, I suddenly  remembered that I have a &lt;a href="http://java.net/projects/rasch-itembank"&gt; Java.net project: Rasch-itembank&lt;/a&gt;.  What a great place to store code!&lt;/p&gt;  &lt;p&gt;The database connection was coded as follows:&lt;/p&gt; &lt;p&gt;&lt;code&gt;/**&lt;br /&gt;* This method loads the database driver&lt;br /&gt;*/&lt;br /&gt;public String dataDriv() {&lt;br /&gt;try {&lt;br /&gt;String ldriver = "org.apache.derby.jdbc.ClientDriver";&lt;br /&gt;Class.forName(ldriver);&lt;br /&gt;buffer = "driver succeeds... ";&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;buffer = "driver error: " + ex.getMessage();&lt;br /&gt;}&lt;br /&gt;return buffer;&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* This method makes the connection&lt;br /&gt;*/&lt;br /&gt;public String dataConn() {&lt;br /&gt;try {&lt;br /&gt;// String strconn = "jdbc:derby://192.168.2.3:1527/dbAMJ";&lt;br /&gt;String strconn = "jdbc:derby://202.65.70.207:1527/dbAMJ";&lt;br /&gt;liveconn = DriverManager.getConnection( strconn );&lt;br /&gt;smt = liveconn.createStatement();&lt;br /&gt;buffer = "connection succeeds... ";&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;buffer = "connection error: " + ex.getMessage();&lt;br /&gt;}&lt;br /&gt;return buffer;&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Converting for MySQL this will require replacing:&lt;/p&gt; &lt;p&gt;&lt;code&gt;String ldriver = "org.apache.derby.jdbc.ClientDriver";&lt;/code&gt;&lt;/p&gt; &lt;p&gt;with&lt;/p&gt; &lt;p&gt;&lt;code&gt;String ldriver = "com.mysql.jdbc.Driver";&lt;/code&gt;&lt;/p&gt; &lt;p&gt;and&lt;/p&gt;  &lt;p&gt;&lt;code&gt;String strconn = "jdbc:derby://202.65.70.207:1527/dbAMJ";&lt;br /&gt;liveconn = DriverManager.getConnection( strconn );&lt;/code&gt;&lt;/p&gt; &lt;p&gt;with&lt;/p&gt; &lt;p&gt;&lt;code&gt;String url = "jdbc:mysql://localhost:3306/dbAMJ";&lt;br /&gt;&lt;/code&gt;&lt;code&gt;liveconn &lt;/code&gt;&lt;code&gt;= DriverManager.getConnection(url,"jhipp", "h1pp0");&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Prior running this, dbAMJ needed to be created on the MySQL server, and  I needed to look up the SQL I ran to do this.  Eventually, I found it, in another  small text file class.  It was going to require a lot of editing, because it included  the "Create=true" switch, which probably doesn't work for MySQL.  I therefore opted to adapt the &lt;a href="http://jhippjava.blogspot.com/2011/07/encoding-local-connection-to-mysql.html"&gt; class I had used to create my financial database&lt;/a&gt; as follows:&lt;/p&gt; &lt;p&gt; &lt;code&gt;import java.sql.*;&lt;br /&gt;&lt;br /&gt;public class AMdbCreate {&lt;br /&gt;public static void main(String args[])&lt;br /&gt;throws ClassNotFoundException, SQLException {&lt;br /&gt;/**&lt;br /&gt;* These are shared variable declarations&lt;br /&gt;*/&lt;br /&gt;Connection connect = null;&lt;br /&gt;Statement stat = null;&lt;br /&gt;/**&lt;br /&gt;* This is the start of the main code.&lt;br /&gt;*/&lt;br /&gt;System.out.println("try connection");&lt;br /&gt;try {&lt;br /&gt;// Load database driver&lt;br /&gt;Class.forName("com.mysql.jdbc.Driver");&lt;br /&gt;// Make connection&lt;br /&gt;String url = "jdbc:mysql://localhost:3306/mysql";&lt;br /&gt;connect = DriverManager.getConnection(url,"root", "my password");&lt;br /&gt;stat = connect.createStatement();&lt;br /&gt;System.out.println("connection succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("connection fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* These are the makedatabase lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try makedatabase dbAMJ");&lt;br /&gt;try {&lt;br /&gt;stat.executeUpdate("CREATE DATABASE dbAMJ");&lt;br /&gt;System.out.println("makedatabase succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("makedatabase fails");&lt;br /&gt;System.out.println("CREATE DATABASE &lt;/code&gt;&lt;code&gt;dbAMJ&lt;/code&gt;&lt;code&gt;");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;} finally {&lt;br /&gt;// Close connection&lt;br /&gt;if (connect!= null) {&lt;br /&gt;try {&lt;br /&gt;connect.close();&lt;br /&gt;System.out.println("disconnection succeeds");&lt;br /&gt;} catch (SQLException sqlEx) {&lt;br /&gt;System.out.println("disconnection fails");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt; &lt;/p&gt; &lt;p&gt;This ran successfully with the following output:&lt;/p&gt; &lt;p&gt;&lt;code&gt;try connection&lt;br /&gt;connection succeeds&lt;br /&gt;try makedatabase dbAMJ&lt;br /&gt;makedatabase succeeds&lt;br /&gt;disconnection succeeds&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I then adapted the other two classes I had used &lt;a href="http://jhippjava.blogspot.com/2011/07/more-simple-mysql-jdbc-examples.html"&gt; to add a user and a table&lt;/a&gt; to my financial database.  Adding the user  was fine, but as I half expected, there was a problem creating the table.   The screen output was as follows:&lt;/p&gt; &lt;p&gt;&lt;code&gt;try connection&lt;br /&gt;connection succeeds&lt;br /&gt;try maketable&lt;br /&gt;maketable fails&lt;br /&gt;CREATE TABLE Items (Itemid INT&lt;br /&gt;GENERATED BY DEFAULT AS IDENTITY, Partid BIGINT,&lt;br /&gt;OpCode SMALLINT, Itemdet CHAR(9), Raw SMALLINT,&lt;br /&gt;Rate DOUBLE, primary key (Itemid))&lt;br /&gt;SQLException: You have an error in your SQL syntax;&lt;br /&gt;check the manual that corresponds to your MySQL&lt;br /&gt;server version for the right syntax to use near&lt;br /&gt;'GENERATED BY DEFAULT AS IDENTITY, Partid BIGINT,&lt;br /&gt;OpCode SMALLINT, Itemdet CHAR(9' at line 1&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I suspected the problem lay with the "auto-increment" option on the item id.  The syntax I  used for this had come from the &lt;a href="http://db.apache.org/derby/docs/10.2/ref/ref-single.html"&gt;Derby SQL  reference manual&lt;/a&gt;.   &lt;/p&gt; &lt;p&gt;A quick Google search revealed &lt;span style="text-decoration: underline;"&gt;&lt;/span&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html"&gt;a page in the MySQL online manual&lt;/a&gt;, which gave the correct language and syntax for MySQL.   &lt;/p&gt; &lt;p&gt;All I had to do was change  my &lt;code&gt;Itemid&lt;/code&gt; field as follows:&lt;/p&gt; &lt;p&gt;&lt;code&gt;Itemid INT NOT NULL AUTO_INCREMENT,&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And the table was created without a problem.  I am now ready to try  running the applet.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-1667530281924660536?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/1667530281924660536/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=1667530281924660536' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/1667530281924660536'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/1667530281924660536'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/07/creating-mysql-database-for-gui-applet.html' title='Creating a MySQL database for a GUI applet'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-8749727469109502333</id><published>2011-07-27T03:56:00.000-07:00</published><updated>2011-07-27T04:02:57.553-07:00</updated><title type='text'>Further Diagnostics with MySQL</title><content type='html'>&lt;p&gt;I shall now go back to the diagnostic class (&lt;code&gt;FindbSDiag1&lt;/code&gt; shown  below), and bring  back some but not all of the commented out code.&lt;/p&gt; &lt;p&gt;My first screen dump was very fussy, but it confirmed that the buy queries  were running successfully:&lt;/p&gt; &lt;p&gt; &lt;code&gt;Buy Query = SELECT * FROM TransRaw where&lt;br /&gt;TrType = 'Buy' and StCode = 'ABS' for update&lt;br /&gt;try Buy Query&lt;br /&gt;Buy Query succeeds&lt;br /&gt;fBCumQ= 0.0&lt;br /&gt;fSQ= 2000.0&lt;br /&gt;Buy Query = SELECT * FROM TransRaw where&lt;br /&gt;TrType = 'Buy' and StCode = 'TIM' for update&lt;br /&gt;try Buy Query&lt;br /&gt;Buy Query succeeds&lt;br /&gt;fBCumQ= 0.0&lt;br /&gt;fSQ= 7000.0&lt;/code&gt; &lt;/p&gt; &lt;p&gt;So I took out the rubbish and was left with a nice neat buy query screen  dump, mirroring the one for the sell queries: &lt;/p&gt;  &lt;p&gt;&lt;code&gt;SELECT * FROM TransRaw where TrType = 'Buy' and StCode = 'ZFX' for  update&lt;br /&gt;SELECT * FROM TransRaw where TrType = 'Buy' and StCode = 'BIL' for update&lt;br /&gt;SELECT * FROM TransRaw where TrType = 'Buy' and StCode = 'QCH' for update&lt;br /&gt;SELECT * FROM TransRaw where TrType = 'Buy' and StCode = 'CDO' for update&lt;br /&gt;SELECT * FROM TransRaw where TrType = 'Buy' and StCode = 'LIP' for update&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Thus far then, the code is working correctly. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;And it turns out that the  next "problem" was a couple of "diagnostic lines" inserted by me at the very  start of the diagnostic process. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;Having corrected this, the diagnostic  program now (in theory) runs exactly as the original was supposed to run, with  the few extra comments.  As a few changes have now been made to accommodate  MySQL, I'll print the whole thing here (c/cf the original &lt;code&gt;FindbQ1&lt;/code&gt;  for Derby class shown &lt;a href="http://jhippjava.blogspot.com/2010/06/revisiting-old-code.html"&gt;here&lt;/a&gt;):&lt;/p&gt;  &lt;p&gt;  &lt;code&gt;import java.sql.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;public class FindbSDiag1 {&lt;br /&gt;public static void main(String args[])&lt;br /&gt;throws ClassNotFoundException, SQLException, IOException {&lt;br /&gt;/**&lt;br /&gt;* These are shared variable declarations&lt;br /&gt;*/&lt;br /&gt;Connection connect = null;&lt;br /&gt;Statement statS = null;&lt;br /&gt;Statement statB = null;&lt;br /&gt;Statement statI = null;&lt;br /&gt;ResultSet resultBuy = null;&lt;br /&gt;String Sidx = new String();&lt;br /&gt;String Bidx = new String();&lt;br /&gt;String strDate = new String();&lt;br /&gt;String strTrType = new String();&lt;br /&gt;String strCode = new String();&lt;br /&gt;String strPrice = new String();&lt;br /&gt;String strTrQ = new String();&lt;br /&gt;String dInsert = new String();&lt;br /&gt;String dDelete = new String();&lt;br /&gt;float fSPrice = 0;&lt;br /&gt;float fSQ = 0;&lt;br /&gt;float fSProc = 0;&lt;br /&gt;float fBCumQ = 0;&lt;br /&gt;float fBCurQ = 0;&lt;br /&gt;float fBEQ = 0;&lt;br /&gt;int iBEQ = 0;&lt;br /&gt;float fBPrice = 0;&lt;br /&gt;float fBCurCost = 0;&lt;br /&gt;float fBCumCost = 0;&lt;br /&gt;float fProfit = 0;&lt;br /&gt;float fComm = 22;&lt;br /&gt;/**&lt;br /&gt;* This is the start of the main code.&lt;br /&gt;*/&lt;br /&gt;System.out.println("try connection");&lt;br /&gt;try {&lt;br /&gt;// Load database driver&lt;br /&gt;Class.forName("com.mysql.jdbc.Driver");&lt;br /&gt;// Make connection&lt;br /&gt;String url = "jdbc:mysql://localhost:3306/dbFin";&lt;br /&gt;connect = DriverManager.getConnection(url,"jhipp", "h1pp0");&lt;br /&gt;statS = connect.createStatement();&lt;br /&gt;statB = connect.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,&lt;br /&gt;ResultSet.CONCUR_UPDATABLE);&lt;br /&gt;statI = connect.createStatement();&lt;br /&gt;System.out.println("connection succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("connection fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* These are optional delete lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try delete");&lt;br /&gt;try {&lt;br /&gt;statI.executeUpdate("DELETE FROM TransComp");&lt;br /&gt;System.out.println("delete succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("delete fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* These are query execution lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try sell query loop");&lt;br /&gt;try {&lt;br /&gt;String aquery = "SELECT * FROM TransRaw" +&lt;br /&gt;" where TrType = 'Sell'" +&lt;br /&gt;" order by dDate, TRidx";&lt;br /&gt;ResultSet resultSell = statS.executeQuery(aquery);&lt;br /&gt;System.out.println("Sell Query = " + aquery);&lt;br /&gt;/**&lt;br /&gt;* Display sell results.&lt;br /&gt;*/&lt;br /&gt;while(resultSell.next()) {&lt;br /&gt;Sidx = resultSell.getString(1);&lt;br /&gt;// System.out.println("Sidx= " + Sidx);&lt;br /&gt;strDate = resultSell.getString(2);&lt;br /&gt;strTrType = resultSell.getString(3);&lt;br /&gt;strCode = resultSell.getString(4);&lt;br /&gt;strPrice = resultSell.getString(5);&lt;br /&gt;strTrQ = resultSell.getString(6);&lt;br /&gt;fSPrice = resultSell.getFloat(5);&lt;br /&gt;fSQ = -resultSell.getFloat(6);&lt;br /&gt;fSProc = fSPrice * fSQ;&lt;br /&gt;fSProc = fSProc - fComm;&lt;br /&gt;dInsert = "INSERT INTO TransComp " +&lt;br /&gt;"VALUES (" + Sidx +&lt;br /&gt;", '" + strDate +&lt;br /&gt;"', '" + strTrType +&lt;br /&gt;"', '" + strCode +&lt;br /&gt;"', " + strPrice +&lt;br /&gt;", " + strTrQ + ")";&lt;br /&gt;// System.out.println("Sell insert Query = " + dInsert);&lt;br /&gt;// System.out.println(dInsert);&lt;br /&gt;/**&lt;br /&gt;* These are the insert lines&lt;br /&gt;*/&lt;br /&gt;// System.out.println("try insert sell");&lt;br /&gt;try {&lt;br /&gt;statI.executeUpdate(dInsert);&lt;br /&gt;// System.out.println("insert sell succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("insert sell fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* Display buy results.&lt;br /&gt;*/&lt;br /&gt;String bquery = "SELECT * FROM TransRaw" +&lt;br /&gt;" where TrType = 'Buy'" +&lt;br /&gt;" and StCode = '" +&lt;br /&gt;strCode +&lt;br /&gt;"' for update";&lt;br /&gt;System.out.println(bquery);&lt;br /&gt;// System.out.println("try Buy Query");&lt;br /&gt;try {&lt;br /&gt;resultBuy = statB.executeQuery(bquery);&lt;br /&gt;// System.out.println("Buy Query succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("Buy Query fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;fBCumQ = 0;&lt;br /&gt;fBCumCost = 0;&lt;br /&gt;fProfit = 0;&lt;br /&gt;// System.out.println("fBCumQ= " + fBCumQ);&lt;br /&gt;// System.out.println("fSQ= " + fSQ);&lt;br /&gt;while(fBCumQ &amp;lt; fSQ){&lt;br /&gt;if(resultBuy.next()) {&lt;br /&gt;Bidx = resultBuy.getString(1);&lt;br /&gt;System.out.println("Bidx= " + Bidx);&lt;br /&gt;strDate = resultBuy.getString(2);&lt;br /&gt;strTrType = resultBuy.getString(3);&lt;br /&gt;strCode = resultBuy.getString(4);&lt;br /&gt;strPrice = resultBuy.getString(5);&lt;br /&gt;strTrQ = resultBuy.getString(6);&lt;br /&gt;fBPrice = resultBuy.getFloat(5);&lt;br /&gt;fBCurQ = resultBuy.getFloat(6);&lt;br /&gt;fBCumQ = fBCumQ + fBCurQ;&lt;br /&gt;if(fBCumQ &amp;gt; fSQ){&lt;br /&gt;fBEQ = fBCumQ - fSQ;&lt;br /&gt;fBCurQ = fBCurQ - fBEQ;&lt;br /&gt;fBCumQ = fBCumQ - fBEQ;&lt;br /&gt;iBEQ = (int)(fBEQ);&lt;br /&gt;resultBuy.updateInt("TrQ", iBEQ);&lt;br /&gt;} else {&lt;br /&gt;dDelete = "DELETE FROM TransRaw " +&lt;br /&gt;"where TRidx = " + Bidx;&lt;br /&gt;statI.executeUpdate(dDelete);&lt;br /&gt;}&lt;br /&gt;fBCurCost = fBCurQ * fBPrice;&lt;br /&gt;fBCurCost = fBCurCost + fComm;&lt;br /&gt;fBCumCost = fBCumCost + fBCurCost;&lt;br /&gt;dInsert = "INSERT INTO TransComp " +&lt;br /&gt;"VALUES (" + Sidx +&lt;br /&gt;", '" + strDate +&lt;br /&gt;"', '" + strTrType +&lt;br /&gt;"', '" + strCode +&lt;br /&gt;"', " + strPrice +&lt;br /&gt;", " + fBCurQ + ")";&lt;br /&gt;System.out.println("TransComp insert = " + dInsert);&lt;br /&gt;/**&lt;br /&gt;* These are the insert lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try TransComp insert");&lt;br /&gt;try {&lt;br /&gt;statI.executeUpdate(dInsert);&lt;br /&gt;System.out.println("TransComp insert succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("TransComp insert fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;fProfit = fSProc - fBCumCost;&lt;br /&gt;System.out.println("Proceeds = " + fSProc);&lt;br /&gt;System.out.println("Costs = " + fBCumCost);&lt;br /&gt;System.out.println("Profit = " + fProfit);&lt;br /&gt;resultBuy.close();&lt;br /&gt;} //end of while(resultSell.next())&lt;br /&gt;resultSell.close();&lt;br /&gt;statS.close();&lt;br /&gt;// statB.close();&lt;br /&gt;statI.close();&lt;br /&gt;System.out.println("sell query loop succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("sell query loop fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;} finally {&lt;br /&gt;// Close connection&lt;br /&gt;if (connect!= null) {&lt;br /&gt;try {&lt;br /&gt;connect.close();&lt;br /&gt;System.out.println("disconnection succeeds");&lt;br /&gt;} catch (SQLException sqlEx) {&lt;br /&gt;System.out.println("disconnection fails");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt; &lt;/p&gt;  &lt;p&gt;My final task is to modify the &lt;code&gt; &lt;a href="http://jhippjava.blogspot.com/2010/06/revisiting-old-code.html"&gt;FindbQSim2&lt;/a&gt;&lt;/code&gt; class for MySQL, and hope that it  makes the transition more smoothly than the last one.&lt;/p&gt;  &lt;p&gt;And as luck would have it, I simply had to modify the five connection lines  and it worked as it should.  I can now complete my annual tax return!&lt;br /&gt;&lt;/p&gt;  &lt;p&gt;The Java classes described in this and the immediately preceding posts are  not trivial, but only one of them required a couple of changes in addition to the  connection line changes.  From this one might deduce that SQL for MySQL is  not identical to SQL for Derby, but it seems similar enough to make the  transition not insurmountable.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-8749727469109502333?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/8749727469109502333/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=8749727469109502333' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8749727469109502333'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8749727469109502333'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/07/further-diagnostics-with-mysql.html' title='Further Diagnostics with MySQL'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-750507377972570413</id><published>2011-07-26T03:00:00.000-07:00</published><updated>2011-07-26T03:18:48.070-07:00</updated><title type='text'>References to the MySQL manual</title><content type='html'>&lt;p&gt;The MySQL manual can be downloaded from the &lt;a href="http://dev.mysql.com/doc/"&gt;MySQL Documentation: MySQL Reference Manuals&lt;/a&gt;  page of the &lt;a href="http://dev.mysql.com/"&gt;MySQL&lt;/a&gt; web site.  A wide  range of formats and versions are offered.  I chose a PDF file for version  5.5.&lt;/p&gt; &lt;p&gt;My first port of call was Chapter 10 on Data types, and specifically 10.3 on  date and time types.  I presume I must have done the same for Derby, and  used that to guide the design of my text export file.  Anyway, it is  already obvious that the rules are different for MySQL, and for clarity I quote  from the manual:&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;Although MySQL tries to interpret values in several formats, dates always  must be given in year-month-day order (for example, '98-09-04'), rather than in  the month-day-year or day-month-year orders commonly used elsewhere.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;I therefore need to change my selections in the MS Access data export wizard  advanced options as follows, with the date delimiter changed to "-" and the date order changed to YMD:&lt;/p&gt;  &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-1DEHCmWh8Ww/Ti6RM9jL8PI/AAAAAAAAAEw/w_RUIVPkdms/s1600/pane9.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 282px;" src="http://3.bp.blogspot.com/-1DEHCmWh8Ww/Ti6RM9jL8PI/AAAAAAAAAEw/w_RUIVPkdms/s320/pane9.JPG" alt="" id="BLOGGER_PHOTO_ID_5633599835753672946" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;and the dataset should now look like this:&lt;/p&gt;  &lt;p&gt;  &lt;code&gt;1,2006-09-05,Buy,BSL,6.86,200&lt;br /&gt;2,2006-09-12,Buy,TFC,0.38,2500&lt;br /&gt;3,2006-09-12,Buy,ZFX,10.65,100&lt;/code&gt; &lt;/p&gt;  &lt;p&gt;I now need to re-import the data to the MySQL database.  Fortunately my &lt;code&gt;FindbFill&lt;/code&gt; import class deletes everything first (to allow for  frequent stuff-ups), so the new dataset should be clean.  Unfortunately the  name of the text file is hard coded, so I do need to go in and change this,  before running it.  I then run the modified &lt;code&gt;FindbQ1&lt;/code&gt; class to  check the modified screen output.  For any reader with a very high boredom  threshold, these classes are shown in their original form &lt;a href="http://jhippjava.blogspot.com/2010/06/revisiting-old-code.html"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;code&gt;try sell query loop&lt;br /&gt;Sell Query = SELECT * FROM TransRaw where TrType = 'Sell' order by dDate, TRidx&lt;br /&gt;INSERT INTO TransComp VALUES (420, '2006-09-12', 'Sell', 'ZXF', 10.65, -100)&lt;br /&gt;INSERT INTO TransComp VALUES (410, '2006-12-12', 'Sell', 'BIL', 12.44, -80)&lt;br /&gt;INSERT INTO TransComp VALUES (418, '2007-08-01', 'Sell', 'QCH', 5.9, -300)&lt;br /&gt;INSERT INTO TransComp VALUES (412, '2007-08-15', 'Sell', 'CDO', 6.2, -220)&lt;br /&gt;INSERT INTO TransComp VALUES (417, '2007-11-07', 'Sell', 'LIP', 0.95, -1300)&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;The output, shown above confirms that the dates have now been stored  correctly, and the program is looping through the data in the correct order.&lt;/p&gt;  &lt;p&gt;Now to address the second problem identified in my &lt;a href="http://jhippjava.blogspot.com/2011/07/diagnostics-with-mysql.html"&gt;last  post&lt;/a&gt;, from the &lt;a href="http://db.apache.org/derby/manuals/reference/sqlj49.html"&gt;Derby  reference manual&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:85%;"&gt;A SELECT statement consists of a query with an optional ORDER  BY clause and an optional FOR UPDATE clause...The FOR UPDATE clause makes the  result an updatable cursor.&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;And the format seems to be:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;Select [fields] from [table] order by [fields] for update of [fields]&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;Which is precisely the format used in my soft query, shown at the base of &lt;a href="http://jhippjava.blogspot.com/2011/07/diagnostics-with-mysql.html"&gt;this  page&lt;/a&gt;.  Now from the MySQL manual, the syntax of the Select statement is  as follows:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;SELECT&lt;br /&gt;[ALL | DISTINCT | DISTINCTROW ]&lt;br /&gt;[HIGH_PRIORITY]&lt;br /&gt;[STRAIGHT_JOIN]&lt;br /&gt;[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]&lt;br /&gt;[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]&lt;br /&gt;select_expr [, select_expr ...]&lt;br /&gt;[FROM table_references&lt;br /&gt;[WHERE where_condition]&lt;br /&gt;[GROUP BY {col_name | expr | position}&lt;br /&gt;[ASC | DESC], ... [WITH ROLLUP]]&lt;br /&gt;[HAVING where_condition]&lt;br /&gt;[ORDER BY {col_name | expr | position}&lt;br /&gt;[ASC | DESC], ...]&lt;br /&gt;[LIMIT {[offset,] row_count | row_count OFFSET offset}]&lt;br /&gt;[PROCEDURE procedure_name(argument_list)]&lt;br /&gt;[INTO OUTFILE 'file_name'&lt;br /&gt;[CHARACTER SET charset_name]&lt;br /&gt;export_options&lt;br /&gt;| INTO DUMPFILE 'file_name'&lt;br /&gt;| INTO var_name [, var_name]]&lt;br /&gt;[FOR UPDATE | LOCK IN SHARE MODE]]&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;So at first sight, the only thing wrong with my SQL statement is the little  word "of".  The field name &lt;code&gt;TrQ&lt;/code&gt; also seems to be redundant.   So I took them both out and re-ran the &lt;code&gt;FindbQ1S&lt;/code&gt; (simply the MySQL  version of the &lt;code&gt; &lt;a href="http://jhippjava.blogspot.com/2010/06/revisiting-old-code.html"&gt;FindbQ1&lt;/a&gt;&lt;/code&gt;)  class.&lt;/p&gt; &lt;p&gt;Now the original error dump was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;try connection&lt;br /&gt;connection succeeds&lt;br /&gt;try delete&lt;br /&gt;delete succeeds&lt;br /&gt;try query&lt;br /&gt;INSERT INTO TransComp VALUES&lt;br /&gt;(337, '2001-06-20', 'Sell', 'CRT', 0.45, -6000)&lt;br /&gt;try insert&lt;br /&gt;insert succeeds&lt;br /&gt;query fails&lt;br /&gt;SQLException: You have an error in your SQL syntax;&lt;br /&gt;check the manual that corresponds to your MySQL&lt;br /&gt;server version for the right syntax to use&lt;br /&gt;near 'of TrQ' at line 1&lt;br /&gt;disconnection succeeds&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This time, the error dump was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;try connection&lt;br /&gt;connection succeeds&lt;br /&gt;try delete&lt;br /&gt;delete succeeds&lt;br /&gt;try sell query&lt;br /&gt;Sell insert Query = INSERT INTO TransComp VALUES&lt;br /&gt;(420, '2006-09-12', 'Sell', 'ZFX', 10.65, -100)&lt;br /&gt;try insert sell&lt;br /&gt;insert sell succeeds&lt;br /&gt;Buy Query = SELECT * FROM TransRaw where&lt;br /&gt;TrType = 'Buy' and StCode = 'ZFX' for update&lt;br /&gt;try Buy Query&lt;br /&gt;Buy Query succeeds&lt;br /&gt;fBCumQ= 0.0&lt;br /&gt;fSQ= 100.0&lt;br /&gt;query fails&lt;br /&gt;SQLException: Before start of result set&lt;br /&gt;disconnection succeeds&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And it represents progress to the extent that second query, the buy query,  which caused the initial problem, is now running.  However, it appears the  diagnostic work must continue, because there is another exception, perhaps further  inside the loops.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-750507377972570413?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/750507377972570413/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=750507377972570413' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/750507377972570413'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/750507377972570413'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/07/references-to-mysql-manual.html' title='References to the MySQL manual'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-1DEHCmWh8Ww/Ti6RM9jL8PI/AAAAAAAAAEw/w_RUIVPkdms/s72-c/pane9.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-4358702929573359432</id><published>2011-07-25T16:28:00.000-07:00</published><updated>2011-07-26T03:02:37.616-07:00</updated><title type='text'>Diagnostics with MySQL</title><content type='html'>&lt;p&gt;I have changed my mind and decided to record my diagnostic work because it  may be of interest to someone else moving from a Derby database to MySQL, and  perhaps more honestly, it helps me to think.&lt;/p&gt; &lt;p&gt;The problem I am addressing is twofold.  First I am running routines  written two years ago, and although they were written by me, with the passage of  time they now look like double Dutch.  Second I am using an aging dataset,  which has become messy with the passage of time.  I know the code ran two  years ago, and one year ago, so the problem probably relates to something I have  done in the last year.  The trouble is, I have done a lot, mostly in the  name of "cleaning it up" or "filling holes" in the dataset.  &lt;/p&gt; &lt;p&gt;Shares, like all real world data, don't behave in a simple or uniform way.   Companies change their names, they merge with and get taken over by other  companies, and they change the nominal unit value of their shares on a whim.   The question is how to deal with this.  Do you use "transactions", which  didn't take place, but which attempt to adjust to the current situation, or do  you break all accounting and audit protocols by overwriting old transactions  with updated parameters.  Either way, you muck up the data and make it more  difficult to analyze in the sort of methodical fashion which lends itself to  easy programming.&lt;/p&gt; &lt;p&gt;The error reported was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;SQLException: You have an error in your SQL syntax;&lt;br /&gt;check the manual that corresponds to your MySQL&lt;br /&gt;server version for the right syntax to use&lt;br /&gt;near 'of TrQ' at line 1&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Now if the problematic SQL query were hard coded, it would be quite easy to  check it against the manual as recommended.  But in this case it is not.   The query is generated from within the code.  Indeed it is generated from  within an iterative loop, and at first site, the problem does not seem occur on the  first iteration.  Stranger still, when I ran it using Derby, the program  crashed, but in a different place.&lt;/p&gt; &lt;p&gt;So I need to break up the code such that the loops begin to run, but pass  their output to the screen rather than trying to use it run more queries.&lt;/p&gt; &lt;p&gt;My initial screen dump was in the form:&lt;/p&gt; &lt;p&gt;&lt;code&gt;Sidx= 470&lt;br /&gt;Sell insert Query = INSERT INTO TransComp VALUES&lt;br /&gt;(470, '2027-10-20', 'Sell', 'CEY', 6.2, -400)&lt;br /&gt;try insert sell&lt;br /&gt;insert sell succeeds&lt;br /&gt;Buy Query = SELECT * FROM TransRaw where TrType = 'Buy'&lt;br /&gt;and StCode = 'CEY' for update of TrQ&lt;br /&gt;Sidx= 471&lt;br /&gt;Sell insert Query = INSERT INTO TransComp VALUES&lt;br /&gt;(471, '2027-10-20', 'Sell', 'AVE', 1.77, -1000)&lt;br /&gt;try insert sell&lt;br /&gt;insert sell succeeds&lt;br /&gt;Buy Query = SELECT * FROM TransRaw where TrType = 'Buy'&lt;br /&gt;and StCode = 'AVE' for update of TrQ&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This confirmed that sales data were being successfully inserted, but the dump  was too long, and I lost the top.  To save the bother of writing to a text  file, I shortened it.  The next dump was in the form:&lt;/p&gt; &lt;p&gt;&lt;code&gt;try sell query loop&lt;br /&gt;Sell Query = SELECT * FROM TransRaw where TrType = 'Sell' order by dDate, TRidx&lt;br /&gt;INSERT INTO TransComp VALUES (337, '2001-06-20', 'Sell', 'CRT', 0.45, -6000)&lt;br /&gt;INSERT INTO TransComp VALUES (418, '2001-08-20', 'Sell', 'QCH', 5.9, -300)&lt;br /&gt;INSERT INTO TransComp VALUES (443, '2001-09-20', 'Sell', 'CBA', 51.2, -125)&lt;br /&gt;INSERT INTO TransComp VALUES (404, '2002-08-20', 'Sell', 'CBA', 53.48, -125)&lt;br /&gt;INSERT INTO TransComp VALUES (475, '2002-11-20', 'Sell', 'CBA', 49.99, -100)&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This all fitted on one screen, and the first thing I noticed was that the  dates are all wrong.  I also noticed that CRT is indeed the first item in  this jumbled up dataset.  I therefore ran the same dump using Derby, and  the first five items were now:&lt;/p&gt; &lt;p&gt;&lt;code&gt;try sell query loop&lt;br /&gt;Sell Query = SELECT * FROM TransRaw where TrType = 'Sell' order by dDate, TRidx&lt;br /&gt;INSERT INTO TransComp VALUES (420, '2006-09-12', 'Sell ', 'ZFX', 10.65, -100)&lt;br /&gt;INSERT INTO TransComp VALUES (410, '2006-12-12', 'Sell ', 'BIL', 12.44, -80)&lt;br /&gt;INSERT INTO TransComp VALUES (418, '2007-08-01', 'Sell ', 'QCH', 5.9, -300)&lt;br /&gt;INSERT INTO TransComp VALUES (412, '2007-08-15', 'Sell ', 'CDO', 6.2, -220)&lt;br /&gt;INSERT INTO TransComp VALUES (417, '2007-11-07', 'Sell ', 'LIP', 0.95, -1300)&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The dates here are correct, and the order is as I would expect.  I must  confess here, that while I spent a few days browsing the Derby documentation, I  haven't even glanced at that for MySQL yet.  I just assumed it would be the  same, and thought I could "wing it".  I guess that assumption has now been  proven false.  I really need to have a look at the manual (as the error  message suggested), but first let's have a closer look at the lines for CRT:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;INSERT INTO TransComp VALUES (337, '2001-06-20', 'Sell', 'CRT', 0.45,  -6000)&lt;br /&gt;INSERT INTO TransComp VALUES (337, '2009-06-01', 'Sell ', 'CRT', 0.45, -6000)&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;The first line above is taken using MySQL, and the second using Derby.   And the first observation is that MySQL is using day information for the year  and converting the first two digits of the year to the day.  That should be  easy enough to fix.  The second is that MySQL is removing trailing spaces  from the transaction type, while Derby is not.  I've used a 5 character  field: Derby displays it with 5 characters: 'Sell ', while MySQL truncatates it  to 'Sell'.&lt;/p&gt;  &lt;p&gt;Finally for today, using the first screen dump above, let's look closely at the Buy query, which MySQL rejected:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;SELECT * FROM TransRaw where TrType = 'Buy'&lt;br /&gt;and StCode = 'CEY' for update of TrQ&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;Just now I can't remember what I meant by "for update of TrQ".  Perhaps I  need to revisit both manuals.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-4358702929573359432?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/4358702929573359432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=4358702929573359432' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4358702929573359432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4358702929573359432'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/07/diagnostics-with-mysql.html' title='Diagnostics with MySQL'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-8094229130822330327</id><published>2011-07-24T05:25:00.000-07:00</published><updated>2011-07-24T23:32:05.137-07:00</updated><title type='text'>More ambitious MySQL-JDBC examples</title><content type='html'>&lt;p&gt;The Java classes described in my last two entries were ideal for a first try  at writing code for the MySQL Connector/J driver, because they were essentially  trivial - they made a connection, submitted a single SQL query (I call them all  queries - some people call them commands or statements) and then disconnected  from the database.  I shall now try a slightly more ambitious class,  intended to populate a table from a text file.  Before running it, I need  to create the text file in the following format:&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-ilkREya6t_8/TiwRSNSjYTI/AAAAAAAAADw/UJ_YRr06j8k/s1600/pane8.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 319px; height: 230px;" src="http://2.bp.blogspot.com/-ilkREya6t_8/TiwRSNSjYTI/AAAAAAAAADw/UJ_YRr06j8k/s320/pane8.JPG" alt="" id="BLOGGER_PHOTO_ID_5632896238436442418" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Somebody very clever would probably write an SQL query to do that, but as the  raw data resides in an Access database, I use the export wizard.&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-V8KtU4A0B4k/TiwRSX6xTpI/AAAAAAAAAD4/GaJJbkax9Vo/s1600/pane1.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 257px;" src="http://1.bp.blogspot.com/-V8KtU4A0B4k/TiwRSX6xTpI/AAAAAAAAAD4/GaJJbkax9Vo/s320/pane1.JPG" alt="" id="BLOGGER_PHOTO_ID_5632896241289481874" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The pane above is the first pane of the export wizard.  The default  selection for export type is delimited, so I leave that and click Next.&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-FsSEYJAyhQo/TiwRSjpvQgI/AAAAAAAAAEA/uKZQV98XBWY/s1600/pane2.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 257px;" src="http://4.bp.blogspot.com/-FsSEYJAyhQo/TiwRSjpvQgI/AAAAAAAAAEA/uKZQV98XBWY/s320/pane2.JPG" alt="" id="BLOGGER_PHOTO_ID_5632896244439269890" border="0" /&gt;&lt;/a&gt;The pane above is the second pane of the export wizard.  I select Comma  as my delimiter, and I change my text qualifier to {none}.  I also click on  the Advanced button.&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-ixmtkbv8rBQ/TiwRSrGCsWI/AAAAAAAAAEI/RY6M0sioVbk/s1600/pane3.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 283px;" src="http://3.bp.blogspot.com/-ixmtkbv8rBQ/TiwRSrGCsWI/AAAAAAAAAEI/RY6M0sioVbk/s320/pane3.JPG" alt="" id="BLOGGER_PHOTO_ID_5632896246437032290" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The pane above is the pane opened by the Advanced button in Pane 2.   Here I change the date delimiter to a full stop, and I select the Leading Zeros  in Dates check box.  I then click OK to return to Pane 2 and Next to move  to Pane 3.&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-2VUhKKFzqu0/TiwSqpz2oWI/AAAAAAAAAEQ/wo5PC2vGwVM/s1600/pane4.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 257px;" src="http://3.bp.blogspot.com/-2VUhKKFzqu0/TiwSqpz2oWI/AAAAAAAAAEQ/wo5PC2vGwVM/s320/pane4.JPG" alt="" id="BLOGGER_PHOTO_ID_5632897757920797026" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The pane above is the third pane of the export wizard.  Here I simply  change the file name to Trans110630.csv and click finish.  I then open the  file with Notepad and make 3 modifications.&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-hYsOPBipHPQ/TiwSq2noo-I/AAAAAAAAAEY/qaEokh2IQ5k/s1600/pane5.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 169px;" src="http://2.bp.blogspot.com/-hYsOPBipHPQ/TiwSq2noo-I/AAAAAAAAAEY/qaEokh2IQ5k/s320/pane5.JPG" alt="" id="BLOGGER_PHOTO_ID_5632897761359209442" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The pane above shows the first modification.  Here I replace  [space]0:00:00 with nothing.&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-uvCoCCnDsjk/TiwSq-NQhcI/AAAAAAAAAEg/JfSOM5Yngbc/s1600/pane6.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 169px;" src="http://2.bp.blogspot.com/-uvCoCCnDsjk/TiwSq-NQhcI/AAAAAAAAAEg/JfSOM5Yngbc/s320/pane6.JPG" alt="" id="BLOGGER_PHOTO_ID_5632897763396060610" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The pane above shows the second modification.  Here I replace .00 with  nothing.&lt;/p&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-y20UbUybpa4/TiwSrEPYVZI/AAAAAAAAAEo/t3idTC1IF2Y/s1600/pane7.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 169px;" src="http://3.bp.blogspot.com/-y20UbUybpa4/TiwSrEPYVZI/AAAAAAAAAEo/t3idTC1IF2Y/s320/pane7.JPG" alt="" id="BLOGGER_PHOTO_ID_5632897765015573906" border="0" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The pane above shows the third modification.  Here I replace $ with  nothing.  And I end up with something looking like Pane 1 above.  I  then move this file to the fin folder in my local code files folder.  It is  from here that I will run the new class, which in it's JDBC-Derby format is  shown on &lt;a href="http://jhippjava.blogspot.com/2010/06/revisiting-old-code.html"&gt;this  page&lt;/a&gt;.  I shall refrain from reprinting the entire code file here, but  simply confirm that the following 5 lines from the original file:&lt;/p&gt; &lt;p&gt;&lt;code&gt;// Load database driver&lt;br /&gt;Class.forName("org.apache.derby.jdbc.EmbeddedDriver");&lt;br /&gt;// Make connection&lt;br /&gt;String connn = "jdbc:derby:dbFin";&lt;br /&gt;connect = DriverManager.getConnection( connn );&lt;/code&gt;&lt;/p&gt; &lt;p&gt;were replaced by the following 5 lines in the new code file:&lt;/p&gt; &lt;p&gt;&lt;code&gt;// Load database driver&lt;br /&gt;Class.forName("com.mysql.jdbc.Driver");&lt;br /&gt;// Make connection&lt;br /&gt;String url = "jdbc:mysql://localhost:3306/dbFin";&lt;br /&gt;connect = DriverManager.getConnection(url,"jhipp", "h1pp0");&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Obviously, the text file name was updated as well, and the message came back:&lt;/p&gt; &lt;p&gt;&lt;code&gt;try connection&lt;br /&gt;connection succeeds&lt;br /&gt;try delete&lt;br /&gt;delete succeeds&lt;br /&gt;502 records successfully inserted&lt;br /&gt;disconnection succeeds&lt;/code&gt;&lt;/p&gt; &lt;p&gt;which confirmed that the code also worked with the MySQL database.&lt;/p&gt;  &lt;p&gt;So far so good, but the real manipulation is in the class, &lt;code&gt;FindbQ1&lt;/code&gt;,  shown in full on &lt;a href="http://jhippjava.blogspot.com/2010/06/revisiting-old-code.html"&gt;this  page&lt;/a&gt;.  So I converted and ran the code.  Once again, there was no  problem connecting, but there was an SQL syntax error, which will need investigating:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;try connection&lt;br /&gt;connection succeeds&lt;br /&gt;try delete&lt;br /&gt;delete succeeds&lt;br /&gt;try query&lt;br /&gt;INSERT INTO TransComp VALUES&lt;br /&gt;(337, '2001-06-20', 'Sell', 'CRT', 0.45, -6000)&lt;br /&gt;try insert&lt;br /&gt;insert succeeds&lt;br /&gt;query fails&lt;br /&gt;SQLException: You have an error in your SQL syntax;&lt;br /&gt;check the manual that corresponds to your MySQL&lt;br /&gt;server version for the right syntax to use&lt;br /&gt;near 'of TrQ' at line 1&lt;br /&gt;disconnection succeeds&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;To  investigate, I reran my Derby-JDBC code with the same text file to see if it  comes up with the same or a similar error, and it did.  This seems to be a problem with my own code or data, and as it is beyond the scope of the current topic, I shall go silent again until I have fixed it.&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-8094229130822330327?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/8094229130822330327/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=8094229130822330327' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8094229130822330327'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8094229130822330327'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/07/more-ambitious-mysql-jdbc-examples.html' title='More ambitious MySQL-JDBC examples'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-ilkREya6t_8/TiwRSNSjYTI/AAAAAAAAADw/UJ_YRr06j8k/s72-c/pane8.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-2672926762464551966</id><published>2011-07-23T03:14:00.000-07:00</published><updated>2011-07-23T03:35:20.827-07:00</updated><title type='text'>More simple MySQL-JDBC examples</title><content type='html'>&lt;p&gt;In order to consolidate my understanding of JDBC using the MySQL Connector/J  driver, I shall convert all of the files from my &lt;a href="http://jhippjava.blogspot.com/2009/09/building-financial-mini-app.html"&gt; financial mini-application&lt;/a&gt;, for which I described the JDBC-Derby connection  in detail &lt;a href="http://jhippjava.blogspot.com/2010/06/revisiting-old-code.html"&gt;here&lt;/a&gt;.   They are all examples of what I would call text file code, with each class very  short and easy to follow.  I shall work through half a dozen of these  before attempting to convert any gui code.&lt;/p&gt; &lt;p&gt;In the first example I shall add a user to my dbFin database.  &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt;R.G.  Baldwin&lt;/a&gt;, to whose article I have referred in previous posts, achieved this  in the same file/class as the creation of a database.  I wanted to keep my  first MySQL-JDBC class very simple.  I didn't want confusion over the  syntax of long strings mucking it up.  So I shall create a special class to  achieve that practically redundant but theoretically possibly important task.&lt;/p&gt; &lt;p&gt;The class having been created, the code was as follows:&lt;/p&gt; &lt;p&gt; &lt;code&gt;import java.sql.*;&lt;br /&gt;&lt;br /&gt;public class FindbUAdd {&lt;br /&gt;public static void main(String args[])&lt;br /&gt;throws ClassNotFoundException, SQLException {&lt;br /&gt;/**&lt;br /&gt;* These are shared variable declarations&lt;br /&gt;*/&lt;br /&gt;Connection connect = null;&lt;br /&gt;Statement stat = null;&lt;br /&gt;String dCreate = "GRANT SELECT,INSERT,UPDATE,DELETE," +&lt;br /&gt;"CREATE,DROP " +&lt;br /&gt;"ON dbFin.* TO 'jhipp'@'localhost' " +&lt;br /&gt;"IDENTIFIED BY 'h1pp0'";&lt;br /&gt;/**&lt;br /&gt;* This is the start of the main code.&lt;br /&gt;*/&lt;br /&gt;System.out.println("try connection");&lt;br /&gt;try {&lt;br /&gt;// Load database driver&lt;br /&gt;Class.forName("com.mysql.jdbc.Driver");&lt;br /&gt;// Make connection&lt;br /&gt;String url = "jdbc:mysql://localhost:3306/dbFin";&lt;br /&gt;connect = DriverManager.getConnection(url,"root", "my password");&lt;br /&gt;stat = connect.createStatement();&lt;br /&gt;System.out.println("connection succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("connection fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* These are the makeuser lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try makeuser");&lt;br /&gt;try {&lt;br /&gt;stat.executeUpdate(dCreate);&lt;br /&gt;System.out.println("makeuser succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("makeuser fails");&lt;br /&gt;System.out.println(dCreate);&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;} finally {&lt;br /&gt;// Close connection&lt;br /&gt;if (connect!= null) {&lt;br /&gt;try {&lt;br /&gt;connect.close();&lt;br /&gt;System.out.println("disconnection succeeds");&lt;br /&gt;} catch (SQLException sqlEx) {&lt;br /&gt;System.out.println("disconnection fails");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;So far, with the code included in my previous post, and the code above, we  have achieved what was achieved with twelve characters included in a single line  using JDBC for Derby.  The twelve characters were:&lt;/p&gt;   &lt;p&gt;&lt;code&gt;;create=true&lt;/code&gt;&lt;/p&gt;   &lt;p&gt;included at the end of:&lt;/p&gt;   &lt;p&gt;&lt;code&gt;String connn = "jdbc:derby:dbFin;create=true";&lt;/code&gt;&lt;/p&gt;   &lt;p&gt;The substantive part of my original &lt;code&gt;FindbCreate&lt;/code&gt; class was the  creation of a table.  I shall now attempt this with a third mini-class:&lt;/p&gt;   &lt;p&gt;&lt;code&gt;import java.sql.*;&lt;br /&gt;  &lt;/code&gt;&lt;br /&gt;&lt;code&gt;public class FintabCreate {&lt;br /&gt;public static void main(String args[])&lt;br /&gt;throws ClassNotFoundException, SQLException {&lt;br /&gt;/**&lt;br /&gt;* These are shared variable declarations&lt;br /&gt;*/&lt;br /&gt;Connection connect = null;&lt;br /&gt;Statement stat = null;&lt;br /&gt;String dCreate = "CREATE TABLE TransRaw " +&lt;br /&gt;"(TRidx INTEGER, " +&lt;br /&gt;"dDate DATE, TrType CHAR(5), StCode CHAR(3), " +&lt;br /&gt;"TrPrice REAL, TrQ INTEGER, primary key (TRidx))";&lt;br /&gt;/**&lt;br /&gt;* This is the start of the main code.&lt;br /&gt;*/&lt;br /&gt;System.out.println("try connection");&lt;br /&gt;try {&lt;br /&gt;// Load database driver&lt;br /&gt;Class.forName("com.mysql.jdbc.Driver");&lt;br /&gt;// Make connection&lt;br /&gt;String url = "jdbc:mysql://localhost:3306/dbFin";&lt;br /&gt;connect = DriverManager.getConnection(url,"jhipp", "h1pp0");&lt;br /&gt;stat = connect.createStatement();&lt;br /&gt;System.out.println("connection succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("connection fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;/code&gt;&lt;br /&gt;&lt;code&gt;}&lt;br /&gt;/**&lt;br /&gt;* These are the maketable lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try maketable");&lt;br /&gt;try {&lt;br /&gt;stat.executeUpdate(dCreate);&lt;br /&gt;System.out.println("maketable succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("maketable fails");&lt;br /&gt;System.out.println(dCreate);&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;} finally {&lt;br /&gt;// Close connection&lt;br /&gt;if (connect!= null) {&lt;br /&gt;try {&lt;br /&gt;connect.close();&lt;br /&gt;System.out.println("disconnection succeeds");&lt;br /&gt;} catch (SQLException sqlEx) {&lt;br /&gt;System.out.println("disconnection fails");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The output from this was:&lt;/p&gt; &lt;p&gt;&lt;code&gt;try connection&lt;br /&gt;connection succeeds&lt;br /&gt;try maketable&lt;br /&gt;maketable succeeds&lt;br /&gt;disconnection succeeds&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This now takes me to the end of my original &lt;code&gt;FindbCreate&lt;/code&gt; class, and  is a suitable point for a break.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-2672926762464551966?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/2672926762464551966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=2672926762464551966' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/2672926762464551966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/2672926762464551966'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/07/more-simple-mysql-jdbc-examples.html' title='More simple MySQL-JDBC examples'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-6249389605289350888</id><published>2011-07-22T17:24:00.000-07:00</published><updated>2011-07-23T01:02:10.380-07:00</updated><title type='text'>Encoding a local connection to MySQL</title><content type='html'>&lt;p&gt;The code, which I intend to modify, is described in detail on &lt;a href="http://jhippjava.blogspot.com/2010/06/revisiting-old-code.html"&gt;this  page&lt;/a&gt;.  My first task is to modify the batch file which sets the path to  the  binaries directories  to incorporate the current jdk version:&lt;/p&gt; &lt;p&gt;&lt;code&gt;cd My Documents\DDrive\CodeLocal\Fin&lt;br /&gt;set path=C:\Program Files\Java\jdk1.6.0_26\bin&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This batch file also makes current the directory where my code files are  kept.  It leads me to the second task, which is to modify the code files.   The first modification is to replace:&lt;/p&gt; &lt;p&gt;&lt;code&gt;// Load database driver&lt;br /&gt;Class.forName("org.apache.derby.jdbc.EmbeddedDriver");&lt;/code&gt;&lt;/p&gt; &lt;p&gt;with&lt;/p&gt; &lt;p&gt;&lt;code&gt;// Load database driver&lt;br /&gt;Class.forName("com.mysql.jdbc.Driver");&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The second modification is to replace:&lt;/p&gt; &lt;p&gt;&lt;code&gt;// Make connection&lt;br /&gt;String connn = "jdbc:derby:dbFin;create=true";&lt;br /&gt;connect = DriverManager.getConnection( connn );&lt;/code&gt;&lt;/p&gt; &lt;p&gt;with&lt;/p&gt; &lt;p&gt;&lt;code&gt;// Make connection&lt;br /&gt;String url = "jdbc:mysql://localhost:3306/mysql";&lt;br /&gt;connect = DriverManager.getConnection(url,"root", "my password");&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The third modification is to create the dbFin database as follows:&lt;/p&gt; &lt;p&gt;&lt;code&gt;stat.executeUpdate("CREATE DATABASE dbFin");&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Finally, for simplicity, I shall remove the make table query and leave the  disconnection sequence unchanged.&lt;/p&gt; &lt;p&gt;Before modifying the batch file to run the code, I must compile it as  follows:&lt;/p&gt; &lt;p&gt;&lt;code&gt;javac FindbCreate.java&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This having been done, the one line batch file to run the code becomes:&lt;/p&gt; &lt;p&gt;&lt;code&gt;Java -classpath "C:\Documents and Settings\Jonathan\My Documents\DDrive\ CodeLocal\Fin\mysql-connector-java-5.1.17-bin.jar"; "C:\Documents and Settings\Jonathan\My Documents\DDrive\ CodeLocal\Fin" FindbCreate&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Running it was quite hard work, not least because it was late evening and I'd  hit the grog again, so the batch files were full of typos.  I had also  forgotten that I had set my own password on the root user.  Anyway, in the  clear light of the next morning it ran correctly.  For completeness the full text of the  code file was:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;import java.sql.*;&lt;br /&gt;&lt;br /&gt;public class FindbCreate {&lt;br /&gt;public static void main(String args[])&lt;br /&gt;throws ClassNotFoundException, SQLException {&lt;br /&gt;/**&lt;br /&gt;* These are shared variable declarations&lt;br /&gt;*/&lt;br /&gt;Connection connect = null;&lt;br /&gt;Statement stat = null;&lt;br /&gt;/**&lt;br /&gt;* This is the start of the main code.&lt;br /&gt;*/&lt;br /&gt;System.out.println("try connection");&lt;br /&gt;try {&lt;br /&gt;// Load database driver&lt;br /&gt;Class.forName("com.mysql.jdbc.Driver");&lt;br /&gt;// Make connection&lt;br /&gt;String url = "jdbc:mysql://localhost:3306/mysql";&lt;br /&gt;connect = DriverManager.getConnection(url,"root", "my password");&lt;br /&gt;stat = connect.createStatement();&lt;br /&gt;System.out.println("connection succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("connection fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* These are the makedatabase lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try makedatabase");&lt;br /&gt;try {&lt;br /&gt;stat.executeUpdate("CREATE DATABASE dbFin");&lt;br /&gt;System.out.println("makedatabase succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("makedatabase fails");&lt;br /&gt;System.out.println("CREATE DATABASE dbFin");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;} finally {&lt;br /&gt;// Close connection&lt;br /&gt;if (connect!= null) {&lt;br /&gt;try {&lt;br /&gt;connect.close();&lt;br /&gt;System.out.println("disconnection succeeds");&lt;br /&gt;} catch (SQLException sqlEx) {&lt;br /&gt;System.out.println("disconnection fails");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;And the return messages were:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;try connection&lt;br /&gt;connection succeeds&lt;br /&gt;try makedatabase&lt;br /&gt;makedatabase succeeds&lt;br /&gt;disconnection succeeds&lt;/code&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-6249389605289350888?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/6249389605289350888/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=6249389605289350888' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6249389605289350888'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6249389605289350888'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/07/encoding-local-connection-to-mysql.html' title='Encoding a local connection to MySQL'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-3110193075685118188</id><published>2011-07-21T18:06:00.000-07:00</published><updated>2011-07-22T23:47:37.694-07:00</updated><title type='text'>MySQL versus Derby - file locations</title><content type='html'>&lt;p&gt;If you use the embedded driver for Derby, the default location for any  database created is in the same folder as the driver, derby.jar.  In the  case of my &lt;a href="http://jhippjava.blogspot.com/2009/09/building-financial-mini-app.html"&gt; financial mini-app&lt;/a&gt; I placed this package in the same folder as my code  files, and I gave it a name derived from the function of the code - fin.   When I ran the code, Derby created a subfolder called dbFin to contain the data  files.  It was all very convenient.&lt;/p&gt; &lt;p&gt;According to my understanding of MySQL:&lt;/p&gt; &lt;ol&gt;&lt;li&gt;The server has to running.  By default, when you install it starts as    a service with Windows.    &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt;   R.G. Baldwin, in 2004&lt;/a&gt;, deselected this option.  Computers have moved    on since then, so I left it in, and the four cores of my Ci5 processor    (boasting a little here, because a couple of years ago I was still using a PII)    still run at 0-1% as they did before the installation.  So I don't need    to worry about getting the server running, because it is running.&lt;/li&gt;&lt;li&gt;The JDBC driver, MySQL Connector/J, needs to be installed on your computer    and included in the class path.    &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt;   R.G. Baldwin&lt;/a&gt; placed it in his jre libraries folder.  My preferred    option would be to place the mysql-connector-java-3.0.15-ga-bin.jar file with    my own code files, and I shall try that as a first option.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;In order to run my existing code:&lt;/p&gt; &lt;ol&gt;&lt;li&gt;I need a copy of the Java Development Kit (JDK) installed.  Again,    I've had it before, but I checked on the (now) Oracle   &lt;a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html"&gt;   Java Downloads&lt;/a&gt; page for the current version.  I had JDK update 3, and    the current release is update 26.  As I happened to check during off peak    hours for my ISP, I downloaded the current release and installed that.&lt;/li&gt;&lt;li&gt;Before running any code I need to set a path to the JDK binaries.     This can be done as an environment variable, or just prior to runtime.  I    usually use a batch file, which also takes me to the locale of my own code.&lt;/li&gt;&lt;li&gt;In the command to run my code, I need to set the classpath for my own    binaries and for the JDBC driver.  Again, I usually use a one line batch    file, because it is easy to edit and run.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;In order to convert my code to use MySQL:&lt;/p&gt; &lt;ol&gt;&lt;li&gt;I need to modify my classpath to point to the MySQL Connector/J driver,    and of course ensure that the mysql-connector-java-3.0.15-ga-bin.jar file is    actually where the classpath is pointing.&lt;/li&gt;&lt;li&gt;I need to modify two lines of my own connection code, to load the MySQL    JDBC driver, and to refer to the MySQL database.  I also need to add a    command to create the database, if I have not already done so.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;My next entry will record the execution of these steps, and the results of  doing so.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-3110193075685118188?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/3110193075685118188/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=3110193075685118188' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3110193075685118188'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3110193075685118188'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/07/mysql-versus-derby-file-locations.html' title='MySQL versus Derby - file locations'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-8006449073306258343</id><published>2011-07-19T06:41:00.000-07:00</published><updated>2011-07-23T00:15:52.526-07:00</updated><title type='text'>MySQL versus Derby - JDBC code</title><content type='html'>&lt;p&gt;I have mentioned that I am using a &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt; developer.com article&lt;/a&gt; as a template, but before trying to compile and run  it, I shall compare the code outlined therein with that in my own  description of a simple &lt;a href="http://jhippjava.blogspot.com/2010/06/revisiting-old-code.html"&gt; connection to a Derby database&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The  &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt;article&lt;/a&gt; rather neatly summarises the five critical steps in encoding any JDBC connection to a database:&lt;/p&gt; &lt;ol&gt;&lt;li&gt;Load and register the JDBC driver classes &lt;em&gt;(programming interface)&lt;/em&gt;    for the database server that you intend to use. &lt;/li&gt;&lt;li&gt;Get a &lt;strong&gt;Connection&lt;/strong&gt; object that recodesents a connection to    the database server &lt;em&gt;(analogous to logging onto the server).&lt;/em&gt; &lt;/li&gt;&lt;li&gt;Get one or more &lt;strong&gt;Statement&lt;/strong&gt; objects for use in manipulating    the database. &lt;/li&gt;&lt;li&gt;Use the &lt;strong&gt;Statement&lt;/strong&gt; objects to manipulate the database.   &lt;/li&gt;&lt;li&gt;Close the connection to the database. &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;The first section of code from the  &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt;article&lt;/a&gt;  runs as follows: &lt;/p&gt; &lt;p&gt; &lt;code&gt;public class Jdbc11 {&lt;br /&gt;public static void main(String args[]){&lt;br /&gt;System.out.println(&lt;br /&gt;"Copyright 2004, R.G.Baldwin");&lt;br /&gt;try {&lt;br /&gt;Statement stmt;&lt;/code&gt; &lt;/p&gt; &lt;p&gt;The approximately corresponding section in my code is:&lt;/p&gt; &lt;p&gt;&lt;code&gt;public class FindbCreate {&lt;br /&gt;public static void main(String args[])&lt;br /&gt;throws ClassNotFoundException, SQLException {&lt;br /&gt;/**&lt;br /&gt;* These are shared variable declarations&lt;br /&gt;*/&lt;br /&gt;Connection connect = null;&lt;br /&gt;Statement stat = null;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I also define an SQL string in this section, but for comparison I'll leave  it out for now.  The &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt; &lt;/a&gt;&lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt;article&lt;/a&gt; continues with:&lt;/p&gt; &lt;p&gt; &lt;code&gt;//Register the JDBC driver for MySQL.&lt;br /&gt;Class.forName("com.mysql.jdbc.Driver");&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The corresponding section of my code goes:&lt;/p&gt; &lt;p&gt;&lt;code&gt;System.out.println("try connection");&lt;br /&gt;try {&lt;br /&gt;// Load database driver&lt;br /&gt;Class.forName("org.apache.derby.jdbc.EmbeddedDriver");&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;You may note that I declare my variables outside the try statement, and I  send a message to myself, so I know how far the program has got if it  subsequently crashes, but apart from that the structure is similar.  The  main difference is the name of the JDBC driver, with mine being for Derby, and  his for MySQL.  In passing in might be noted that Derby offers the option  of an embedded driver, which does not require a server to be running, while  MySQL does not.&lt;/p&gt; &lt;p&gt;The &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt; &lt;/a&gt;&lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt;article&lt;/a&gt; breaks the connection code into two snippets, which I shall  combine into one:&lt;/p&gt; &lt;p&gt;&lt;code&gt;//Define URL of database server for&lt;br /&gt;// database named mysql on the localhost&lt;br /&gt;// with the default port number 3306.&lt;br /&gt;String url =&lt;br /&gt;"jdbc:mysql://localhost:3306/mysql";&lt;br /&gt;&lt;br /&gt;//Get a connection to the database for a&lt;br /&gt;// user named root with a blank password.&lt;br /&gt;Connection con =&lt;br /&gt;DriverManager.getConnection(&lt;br /&gt;url,"root", "");&lt;/code&gt;&lt;/p&gt; &lt;p&gt; My corresponding code is: &lt;/p&gt; &lt;p&gt;&lt;code&gt;// Make connection&lt;br /&gt;String connn = "jdbc:derby:dbFin;create=true";&lt;br /&gt;connect = DriverManager.getConnection( connn );&lt;/code&gt;&lt;/p&gt; &lt;p&gt;So the  &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt;article&lt;/a&gt; puts the database URL into a string and hard codes the  rest of the connection string, whereas I put the whole connection string into a string.  The &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt;article&lt;/a&gt; names the so called "master database", named &lt;i&gt;mysql&lt;/i&gt;, and logs in as root.   I don't think the Derby embedded driver requires users or passwords, and I named  my own database, and appended create = true in case I had codeviously forgotten  to create it.  I am not sure whether that construct will work with MySQL.&lt;/p&gt; &lt;p&gt;The code in the &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt;article&lt;/a&gt;  then sends a couple of messages about the connection.  I'll skip these.   The next substantive line is:&lt;/p&gt;  &lt;p&gt;  &lt;code&gt;stmt = con.createStatement();&lt;/code&gt; &lt;/p&gt; &lt;p&gt;The corresponding line in my code is:&lt;/p&gt;  &lt;p&gt;  &lt;code&gt;stat = connect.createStatement();&lt;/code&gt; &lt;/p&gt; &lt;p&gt;And my code includes an error trap after this, in case anything has gone  wrong:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;System.out.println("connection succeeds");&lt;br /&gt;} catch(Exception ex) {&lt;br /&gt;System.out.println("connection fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The next snippet from the &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt;article&lt;/a&gt;  creates the database "JunkDB":&lt;/p&gt;  &lt;p&gt;  &lt;code&gt;stmt.executeUpdate("CREATE DATABASE JunkDB");&lt;/code&gt; &lt;/p&gt; &lt;p&gt;This was achieved in my code with the connection string, but as I said I am  not sure whether it will work with MySQL, so I'll follow the format of the  article when I try it out.&lt;/p&gt;  &lt;p&gt;From this point on comparisons between my code and his are a bit redundant,  because we are both just running a series of SQL statements, so I'll leave it  there.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-8006449073306258343?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/8006449073306258343/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=8006449073306258343' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8006449073306258343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8006449073306258343'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/07/comparing-jdbc-code-for-derby-with-that.html' title='MySQL versus Derby - JDBC code'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-2252418264344767754</id><published>2011-07-18T17:22:00.000-07:00</published><updated>2011-07-18T19:02:42.649-07:00</updated><title type='text'>Running MySQL from the command screen</title><content type='html'>&lt;p&gt;In the time it has taken me to edge towards my current goal of encoding a link  to MySQL in Java, I have rebuilt my computer again, and so lost the  installation of MySQL described in my last entry.  This has forced me to  retrace my steps a bit, and in so doing I have stumbled upon another handy  resource.  On a site called &lt;a href="http://www.developer.com/"&gt;developer.com&lt;/a&gt;, there is an article entitled "&lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt;JDBC  and MySQL: Installation and Preparation of MySQL&lt;/a&gt;".  I could have done  with this when I was  &lt;a href="http://jhippjava.blogspot.com/2009/05/jdbctm-database-access.html"&gt;first learning JDBC&lt;/a&gt;.  It is very well written -  concise, yet thorough.&lt;/p&gt;  &lt;p&gt;I visited the &lt;a href="http://dev.mysql.com/downloads/"&gt;MySQL download page&lt;/a&gt;  before installing.  The current version is 5.5.14 rc.  I had  previously downloaded 5.5.9, and as it is a 100MB download, I decided to use  my existing installation package.  I pretty much followed &lt;a href="http://jhippjava.blogspot.com/2011/02/installing-mysql.html"&gt;my own  installation instructions&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;I picked up one ambiguity.  I recommended  "Custom Installation" from the Server Instance Configuration Wizard.  I  should have noted for clarity that this wizard runs after the software  installation, and that for the &lt;i&gt;software&lt;/i&gt; installation the "Standard  Installation" works fine.&lt;/p&gt;  &lt;p&gt;I also picked up sloppy word ordering.  I mentioned that I had opted to  have the path to the MySQL binaries folder added as an environment variable in  the section on running MySQL.  So when I reinstalled after dinner and a  couple of drinks, I forgot to do this.  The path note would therefore have been  better placed in the installation section.  So I added the environment  variable manually, and as often happens with me, it didn't work.  So I ran  MySQL from the binaries folder as follows:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;C:\Program Files\MySQL\MySQL Server 5.5\bin&amp;gt;mysql -u root -p&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;And it ran fine, which confirmed that the installation had gone correctly.&lt;/p&gt;  &lt;p&gt;This takes be back where I ended my last blog entry.  This time I went  a step or two further, taking my lead from &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt; the article mentioned above&lt;/a&gt;.  First I created a local database, with  the following one line command:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;mysql&amp;gt; CREATE DATABASE JunkDB;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;from which the response back was:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;Query OK, 1 row affected (0.00 sec)&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;A small but satisfying point was that in the &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt; article&lt;/a&gt; the recorded time was 0.13 sec, indicating that 7 years after the  article was written computers are running at least 26 times faster than they  were then.&lt;/p&gt; &lt;p&gt;Second I  added a new user:&lt;/p&gt; &lt;p&gt;&lt;code&gt;mysql&amp;gt; GRANT SELECT,INSERT,UPDATE,&lt;br /&gt;-&amp;gt; DELETE,CREATE,DROP&lt;br /&gt;-&amp;gt; ON JunkDB.*&lt;br /&gt;-&amp;gt; TO 'auser'@'localhost'&lt;br /&gt;-&amp;gt; IDENTIFIED BY 'drowssap';&lt;br /&gt;Query OK, 0 rows affected (0.00 sec)&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Please note that if you want to copy and paste this, get rid of the little  arrows.  MySQL seems to add these after any line return, not preceded by ; or  \g.  Please note also that the last line is a response.  So if you use a text file to  clean  up the command for pasting, after cleaning it should look this this:&lt;/p&gt; &lt;p&gt;&lt;code&gt;GRANT SELECT,INSERT,UPDATE,&lt;br /&gt;DELETE,CREATE,DROP&lt;br /&gt;ON JunkDB.*&lt;br /&gt;TO 'auser'@'localhost'&lt;br /&gt;IDENTIFIED BY 'drowssap';&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I copied exactly from the &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt; article&lt;/a&gt;, because my knowledge of the command syntax is too week to want to  fiddle, although it was explained &lt;i&gt;inter alia&lt;/i&gt; that &lt;code&gt;'auser' &lt;/code&gt;is  the username and &lt;code&gt;'drowssap'&lt;/code&gt; is the password.&lt;/p&gt; &lt;p&gt;The third and final step before have a crack at some code was to download the  JDBC connector driver for MySQL: Connector/J.  I recommend doing this from  the &lt;a href="http://dev.mysql.com/downloads/connector/"&gt;MySQL connector page&lt;/a&gt;,  which can be reached easily from the &lt;a href="http://dev.mysql.com/downloads/"&gt; main download page&lt;/a&gt;.  The download from there was an ordinary zip file,  and for now I just extracted the contents into an easy to find location.   From the &lt;a href="http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html"&gt; article&lt;/a&gt;, the key file was:&lt;/p&gt; &lt;p&gt;mysql-connector-java-5.1.17-bin.jar&lt;/p&gt; &lt;p&gt;which was in the root directory of the extracted files.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-2252418264344767754?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/2252418264344767754/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=2252418264344767754' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/2252418264344767754'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/2252418264344767754'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/07/running-mysql-from-command-screen.html' title='Running MySQL from the command screen'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-1595741523384877235</id><published>2011-02-23T02:12:00.000-08:00</published><updated>2011-02-23T02:27:25.661-08:00</updated><title type='text'>Installing MySQL</title><content type='html'>Before attempting to encode a link to MySQL, I thought I'd install MySQL on  my local machine and have a bit of a play.  My first port of call was the &lt;a href="http://www.mysql.com/"&gt;home page&lt;/a&gt; of the MySQL web site.  I  couldn't see any obvious link to installation or user instructions, so I tried  the &lt;a href="http://www.mysql.com/why-mysql/windows/"&gt;Windows page&lt;/a&gt;, but  again it was all about selling the produce rather than using it.  So I did  a How to search on Google and ended up on a &lt;a href="http://www.wikihow.com/Use-MySQL"&gt;wikihow&lt;/a&gt; page which fitted the  bill. &lt;p&gt;The screenshots on the &lt;a href="http://www.wikihow.com/Install-the-MySQL-Database-Server-on-Your-Windows-PC"&gt; installation page&lt;/a&gt; were from version 4.1 (I was installing 5.5), but they  still pretty close to the mark.  The recommendation to select "Standard  Installation" from the Server Instance Configuration Wizard was a bad one  because it hung.  The default selection for custom installation worked  better, not least because it automated the addition of the correct port to the  Windows firewall.&lt;/p&gt; &lt;p&gt;Another reason the installation hung on my machine was AVG blocking the  wizard, and it was not immediately obvious how to turn it off.  After  search for a forum post, it turns out I had to open Resident Shield, Advanced  Settings, from the main console (see below).&lt;/p&gt; &lt;div style="text-align: left;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-h-eWPSnr7BY/TWTd3H2oFoI/AAAAAAAAAC0/4bTv-pPXD1k/s1600/blog403a.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 325px; height: 275px;" src="http://3.bp.blogspot.com/-h-eWPSnr7BY/TWTd3H2oFoI/AAAAAAAAAC0/4bTv-pPXD1k/s320/blog403a.JPG" alt="" id="BLOGGER_PHOTO_ID_5576826177662228098" border="0" /&gt;&lt;/a&gt;From there is was pretty to uncheck "enable resident shield" (see below) to  switch AVG off.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-9muHvqBBimE/TWTeR3XdhaI/AAAAAAAAAC8/8274KZvr-6A/s1600/blog403b.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 395px; height: 290px;" src="http://3.bp.blogspot.com/-9muHvqBBimE/TWTeR3XdhaI/AAAAAAAAAC8/8274KZvr-6A/s320/blog403b.JPG" alt="" id="BLOGGER_PHOTO_ID_5576826637093012898" border="0" /&gt;&lt;/a&gt;Meanwhile the wizard, having hung, needed to be closed with Task Manager,  under the applications tab.  Fortunately the initial installation of MySQL  had placed an item in the Start menu under "Start"&gt;"All Programs"&gt;"MySQL"&gt;"MySQL  Server 4.x" to restart the Server Instance Configuration Wizard, the first page  of which gave the option to remove the MySQL service.  I needed to do this  so the wizard could then be rerun on a clean slate. &lt;p&gt;The &lt;a href="http://www.wikihow.com/Install-the-MySQL-Database-Server-on-Your-Windows-PC"&gt; installation page&lt;/a&gt; in &lt;a href="http://www.wikihow.com/Use-MySQL"&gt;wikihow&lt;/a&gt;  seemed to think there would also be a menu item to Start MySQL in the command  line, which there wasn't.  However, the &lt;a href="http://www.wikihow.com/Send-Sql-Queries-to-Mysql-from-the-Command-Line"&gt; How to Send sql Queries to MySQL page&lt;/a&gt; had the syntax required to start  mysql.exe straight from the command line.&lt;/p&gt; &lt;p&gt;In my case I was logging in as the root so the command was:&lt;/p&gt; &lt;p&gt; &lt;code&gt;D:\Documents and Settings\Jonno&gt;mysql -u root -p&lt;/code&gt; &lt;/p&gt; &lt;p&gt;During the setup I had opted to have the path to the MySQL binaries folder  added as an environment variable, which is why I could run the command from my  Windows home folder.  The response came back:&lt;/p&gt; &lt;p&gt;&lt;code&gt;Enter password: *******&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I put in my password and got:&lt;/p&gt; &lt;p&gt;&lt;code&gt;Welcome to the MySQL monitor. Commands end with ; or \g.&lt;br /&gt;Your MySQL connection id is 4&lt;br /&gt;Server version: 5.5.9 MySQL Community Server (GPL)&lt;br /&gt;&lt;br /&gt;Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.&lt;br /&gt;&lt;br /&gt;Oracle is a registered trademark of Oracle Corporation and/or its&lt;br /&gt;affiliates. Other names may be trademarks of their respective&lt;br /&gt;owners.&lt;br /&gt;&lt;br /&gt;Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I didn't want to enter any sql from the command line, so I entered:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;mysql&gt; exit&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And got a very polite:&lt;/p&gt; &lt;p&gt;&lt;code&gt;Bye&lt;br /&gt;&lt;br /&gt;D:\Documents and Settings\Jonno&gt;&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Thus ended the lesson.&lt;/p&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-1595741523384877235?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/1595741523384877235/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=1595741523384877235' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/1595741523384877235'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/1595741523384877235'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/02/installing-mysql.html' title='Installing MySQL'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-h-eWPSnr7BY/TWTd3H2oFoI/AAAAAAAAAC0/4bTv-pPXD1k/s72-c/blog403a.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-6868753963480879160</id><published>2011-02-17T23:22:00.000-08:00</published><updated>2011-02-17T23:23:27.921-08:00</updated><title type='text'>Rasch Itembank Blog</title><content type='html'>&lt;p&gt;So I have started a blog for my &lt;a href="http://java.net/projects/rasch-itembank/"&gt;Rasch Itembank Project&lt;/a&gt;,  and the address is:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://rasch-itembank.blogspot.com/"&gt; http://rasch-itembank.blogspot.com&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The Learning Java blog will now be kept for java related issues, including issues related  to data storage and access.&lt;/p&gt;  &lt;p&gt;I am currently using a Derby database, and I had a few teething problems with  that.  Anyway after failing to find an ISP who would host a derby server  for me, I have now found one who will host MySQL.  So that will be a new  learning curve for me.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-6868753963480879160?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/6868753963480879160/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=6868753963480879160' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6868753963480879160'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6868753963480879160'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2011/02/rasch-itembank-blog.html' title='Rasch Itembank Blog'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-5276191130467198522</id><published>2010-11-08T23:24:00.000-08:00</published><updated>2011-02-15T00:16:43.968-08:00</updated><title type='text'>Rounding up the year</title><content type='html'>&lt;p&gt;This blog was created to record my journey in learning Java.  While that  journey might not have completely reached its conclusion, it has certainly  started to plateau.  I posted 22 pages in the last four months of 2008, 66  in 2009, and just 11 in the whole of 2010.&lt;/p&gt; &lt;p&gt;Most of my 2010 posts related to my &lt;a href="http://java.net/projects/rasch-itembank/"&gt;psychometric project&lt;/a&gt;,  which is  another journey really, and I think is worthy of its own blog.  If people run a  search on "learning java" they probably won't be very interested in the ups and  downs of my math project, but if they run a search on "Rasch" or "Scoring  Rates", I'd like them to find me writing a blog focused on the topic, rather  than rambling about the ins and outs of Java.&lt;/p&gt; &lt;p&gt;I shall post a link to the new blog here when it begins (which might not be  until some time in 2011), and keep any new posts in this blog more closely  related to learning new tricks in java.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-5276191130467198522?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/5276191130467198522/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=5276191130467198522' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5276191130467198522'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5276191130467198522'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2010/11/rounding-up.html' title='Rounding up the year'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-3465371491107885639</id><published>2010-06-27T05:00:00.000-07:00</published><updated>2011-02-15T03:05:48.454-08:00</updated><title type='text'>Checking the database</title><content type='html'>The code currently uploaded to my &lt;a href="https://java.net/projects/rasch-itembank/"&gt;java project&lt;/a&gt; at covers only  the front end of the application.  I have not formalized the back end.   It remains a collection of code scraps, which I use from time to time to check  what is in the database, or less often to change what is in the database.  &lt;p&gt;&lt;/p&gt; &lt;p&gt;I have not formalized it because I am currently the only user.  In  previous incarnations of the app I have incorporated data queries, with all  sorts of filters and user customization, which no one has understood how to use.&lt;/p&gt; &lt;p&gt;My current &lt;i&gt;ad hoc&lt;/i&gt; query code is as follows:&lt;/p&gt; &lt;pre&gt;public class ItemdbQuery {&lt;br /&gt;public static void main(String args[])&lt;br /&gt;   throws ClassNotFoundException, SQLException {&lt;br /&gt;/**&lt;br /&gt;* These are shared variable declarations&lt;br /&gt;*/&lt;br /&gt;Connection connect = null;&lt;br /&gt;Statement stat = null;&lt;br /&gt;/**&lt;br /&gt;* This is the start of the main code.&lt;br /&gt;*/&lt;br /&gt;System.out.println("try connection");&lt;br /&gt;try {&lt;br /&gt;// Load database driver&lt;br /&gt;Class.forName("org.apache.derby.jdbc.ClientDriver");&lt;br /&gt;// Make connection&lt;br /&gt;String connn = "jdbc:derby://192.168.2.2:1527/dbAMJ";&lt;br /&gt;connect = DriverManager.getConnection( connn );&lt;br /&gt;stat = connect.createStatement();&lt;br /&gt;System.out.println("connection succeeds");&lt;br /&gt;  }  catch(Exception ex) {&lt;br /&gt;System.out.println("connection fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;  }&lt;br /&gt;// Execute a query&lt;br /&gt;System.out.println("try query");&lt;br /&gt;try {&lt;br /&gt;String aquery = "SELECT * FROM Items";&lt;br /&gt;ResultSet resultSet = stat.executeQuery(aquery);&lt;br /&gt;// Display results&lt;br /&gt;while(resultSet.next()) {&lt;br /&gt;      System.out.println(resultSet.getString(1) + " " +&lt;br /&gt;      resultSet.getString(2) + " " +&lt;br /&gt;      resultSet.getString(3) + " " +&lt;br /&gt;      resultSet.getString(4) + " " +&lt;br /&gt;      resultSet.getString(5) + " " +&lt;br /&gt;      resultSet.getString(6));&lt;br /&gt;}&lt;br /&gt;resultSet.close();&lt;br /&gt;stat.close();&lt;br /&gt;System.out.println("query succeeds");&lt;br /&gt;  }  catch(Exception ex) {&lt;br /&gt;System.out.println("query fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;  } finally {&lt;br /&gt;// Close connection&lt;br /&gt;if (connect!= null) {&lt;br /&gt;try {&lt;br /&gt;connect.close();&lt;br /&gt;System.out.println("disconnection succeeds");&lt;br /&gt;} catch (SQLException sqlEx) {&lt;br /&gt;System.out.println("disconnection fails");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;  }&lt;br /&gt;   }&lt;br /&gt;} &lt;/pre&gt; &lt;p&gt;This code differs from that used for my &lt;a href="http://jhippjava.blogspot.com/2010/06/revisiting-old-code.html"&gt;financial transaction&lt;/a&gt; query in that  the database is hosted remotely, so the derby "Clientdriver" was used, and the  connection string included the local IP address of my server.&lt;/p&gt;  &lt;p&gt;A sample of the data output is given below:&lt;/p&gt;  &lt;pre&gt;23 1247061594801 1 3 + 2 =   1 8.683068&lt;br /&gt;24 1247061594801 1 5 + 3 =   1 36.518562&lt;br /&gt;25 1247061594801 1 2 + 5 =   1 39.164494&lt;/pre&gt;  &lt;p&gt;The fields are essentially: an index, a datestamp, an operation code, an  item, the raw score for the item, and the scoring rate.  This can be sucked  into a spreadsheet or GUI database for further analysis.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-3465371491107885639?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/3465371491107885639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=3465371491107885639' title='21 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3465371491107885639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3465371491107885639'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2010/06/checking-database.html' title='Checking the database'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>21</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-4369080636474838516</id><published>2010-06-10T06:22:00.000-07:00</published><updated>2010-06-10T22:14:24.020-07:00</updated><title type='text'>MS Outlook Slow to Start</title><content type='html'>&lt;p&gt;It is embarrassing, whatever ones business, if a client rings up for an  appointment, and you have to keep them waiting for 30 or more seconds while MS  Outlook cranks into action.  It is especially embarrassing if the client is  calling to ask you to build a new computer for them, which they hope will be  quick and easy to use.&lt;/p&gt; &lt;p&gt;My old excuse was that I was using a Dell Pentium III laptop, which for  sentimental reasons I didn't have the heart to throw out.  But I am now  using a recently built system using a Pentium Core 2 Duo processor and 2 GB RAM  to run Windows XP pro.  So what is my excuse now?&lt;/p&gt; &lt;p&gt;When I built the system I partitioned the hard drive and put an identical OS  on both partitions.  The idea was that the C drive would be my top copy,  and the D drive would be for experimentation.  But I was so paranoid about  intalling anything on the C drive, the D drive became my de-facto working drive.   And it is the D drive on which MS Outlook displays the flash screen for 30  seconds before revealing any emails or appointments.  On the clean C drive,  MS Outlook starts in between 1 and 3 seconds.  I could scrub the D drive  and start again, but I thought I'd do some research first.&lt;/p&gt; &lt;p&gt;The first place I looked was the &lt;a href="http://www.microsoft.com/communities/newsgroups/en-us/default.aspx"&gt; Microsoft forum&lt;/a&gt;.  It used to be good, but it has gone badly downhill  over the last few years.  Anyway, using the title of the current blog as a  search string rendered quite a short list of posts and absolutely nothing  useful.  Plugging the same search string into &lt;a href="http://www.google.com.au/"&gt;Google&lt;/a&gt; yielded a few hopeful looking  forum posts.  I tried &lt;a href="http://www.utipu.com/app/tip/id/2608/"&gt;this  one&lt;/a&gt; and &lt;a href="http://www.fansoftech.com/2008/06/19/experiencing-slow-outlook-start-up-times/"&gt; this one&lt;/a&gt; and &lt;a href="http://www.ifoundafix.com/2009/01/28/microsoft-outlook-is-slow-to-open-upon-startup/"&gt; this one&lt;/a&gt;.  Sadly none came close to fixing my problem.&lt;/p&gt; &lt;p&gt;To summarize, deleting or renaming the extend.dat file did nothing.   Running "Detect and Repair" from within Outlook did nothing.  Backing up my  personal folders file to a safe location and deleting the original to force  Outlook to build a clean empty one did nothing.  Uninstalling MS Outlook  and reinstalling did nothing to solve the problem.  It just took 30 seconds  to display and empty mail folder.  Uninstalling my AVG antivirus software  did not help MS Outlook to start any faster.&lt;/p&gt; &lt;p&gt;So I thought the problem might be in the Windows registry, and I thought I'd  try using Windows restore.  I remember it took a few weeks to corrupt MS  Outlook, so I chose a restore point from the day after I installed it.  My  AV software had been installed before that, and nothing had been installed  since.  (If nothing had been installed since, the question might arise, how  did I corrupt it, but let's leave that one for now).  Anyway let me caution  anyone else tempted to use Windows restore not to.  It is perhaps the  stupidest invention ever to come out of Microsoft, and in the ten years since it  came out, I have only ever once achieved a successful outcome with it.   Mostly it achieves nothing, and often it corrupts the whole system.  This  for me was one of those occasions.  My AV software disappeared/ceased to  function, and MS Outlook still displayed the flash screen for 30 seconds before  showing my now empty mailbox.&lt;/p&gt; &lt;p&gt;After wasting the best part of 4 hours fiddling around achieving nothing, my  conclusion is that the only sensible solution is to ditch the OS.  So how  did the situation arise?  I don't know exactly.  My mailboxes are  large, but they are large on the C drive and that installation works fine.   I was using the import feature a lot, when I was alternating between the C drive  and the D drive, and maybe the mailbox got corrupted.  But in that case why  did the problem remain after I deleted my mail box and created a new one?   The only other possible explanation lies in the integration with AVG - maybe  something happened during an update.  But again it seems unlikely, as I  have another computer using Outlook (admittedly with an empty mailbox) and AVG,  and it works fine.&lt;/p&gt; &lt;p&gt;So it will remain another Windows mystery.  I'll go back to using my C  drive, and either ditch the D drive, or not use Outlook in it, or leave Outlook  running all the time so I don't have to wait for it to start.  I'll back up  my C drive on a regular basis, so I really can "restore" to an earlier time if I  need to.  And I won't hate Microsoft - I use their software, and I still  don't completely like the alternatives - but I will wonder whether the day will  come when such problems really can be fixed with a diagnostic tool, rather than  wiping a drive sector and starting again.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-4369080636474838516?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/4369080636474838516/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=4369080636474838516' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4369080636474838516'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4369080636474838516'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2010/06/ms-outlook-slow-to-start.html' title='MS Outlook Slow to Start'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-6795078701862696811</id><published>2010-06-08T23:14:00.000-07:00</published><updated>2010-06-09T03:24:46.148-07:00</updated><title type='text'>Revisiting old code</title><content type='html'>&lt;p&gt;When I first &lt;a href="http://jhippjava.blogspot.com/2008/09/where-to-start.html"&gt;began this  blog&lt;/a&gt;, I was pretty down on the &lt;a href="http://java.sun.com/docs/books/tutorial/index.html"&gt;official Java  Tutorial on the Sun website&lt;/a&gt;.  I was especially down on the &lt;a href="http://java.sun.com/docs/books/tutorial/index.html"&gt;Java Tutorial&lt;/a&gt;  trail &lt;a href="http://java.sun.com/docs/books/tutorial/jdbc/index.html"&gt;JDBC(TM)  Database Access&lt;/a&gt;, which describes how to make a connection with a database.   But a year later, I find myself scanning my own blog, which I thought comprised  the finest pearls of clarity and wisdom, and I can't find any description, let  alone a better description, of how to connect to a database without using a GUI  app like NetBeans.&lt;/p&gt; &lt;p&gt;There is an entry, entitled "&lt;a href="http://jhippjava.blogspot.com/2009/09/building-financial-mini-app.html"&gt;Building  a financial mini-app&lt;/a&gt;", which describes an application of such a connection,  but it is distinctly unhelpful to anyone wanting to build such a tool for  themselves.  Indeed I found it distinctly unhelpful even to me, trying to  re-apply my own code.  I shall therefore attempt to re-write the page in a  slightly less cryptic fashion.   &lt;/p&gt; &lt;p&gt;This has nothing to do with my &lt;a href="https://rasch-itembank.dev.java.net/"&gt;Rasch-Itembank project&lt;/a&gt; at  java.net, but for me it is a useful exercise in manipulating data.  The  purpose of the code is to calculate my capital gains for tax purposes under  Australian Law.&lt;/p&gt; &lt;p&gt;I shall begin at the beginning by very beginning, with I couple of short  batch files I use to set paths.  In the Windows home directory I have a  batch file called cd1.bat, which sets the path to the Java binaries directory  and relocates us to the home of the planned new database and code intended to  create it:&lt;/p&gt; &lt;p&gt;&lt;code&gt;cd My Documents\CodeLocal\Fin&lt;br /&gt;set path=D:\Program Files\Java\jdk1.6.0_03\bin&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Some people set the path to the Java binaries directory as a Windows  environmental variable, but when I began I was using a ropy old computer with a  corrupted OS, and the environmental variable never stuck, so I got into the  habit of setting it for every session.&lt;/p&gt;  &lt;p&gt;In the \Fin directory I have another batch file called cd3.bat, which sets  the class path for both the derby.jar file and my own class file, which is  called &lt;code&gt;FindbCreate.class&lt;/code&gt;:&lt;/p&gt;  &lt;p&gt;&gt;&lt;code&gt;Java -classpath&lt;br /&gt;"D:\Docs\Jonno\My Documents\CodeLocal\Fin\derby.jar";&lt;br /&gt;"D:\Docs\Jonno\My Documents\CodeLocal\Fin"&lt;br /&gt;FindbCreate&gt;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;NB This is a one line batch file which has been broken up for display  purposes.  The java code behind the &lt;code&gt;FindbCreate.class&lt;/code&gt;,  used to  create the database and the first table, is as follows:&lt;/p&gt;  &lt;pre&gt;import java.sql.*;&lt;br /&gt;&lt;br /&gt;public class FindbCreate {&lt;br /&gt;public static void main(String args[])&lt;br /&gt;   throws ClassNotFoundException, SQLException {&lt;br /&gt;/**&lt;br /&gt;* These are shared variable declarations&lt;br /&gt;*/&lt;br /&gt;Connection connect = null;&lt;br /&gt;Statement stat = null;&lt;br /&gt;String dCreate = "CREATE TABLE TransRaw " +&lt;br /&gt;"(TRidx INTEGER, " +&lt;br /&gt;"dDate DATE, TrType CHAR(5), StCode CHAR(3), " +&lt;br /&gt;"TrPrice REAL, TrQ INTEGER, primary key (TRidx))";&lt;br /&gt;/**&lt;br /&gt;* This is the start of the main code.&lt;br /&gt;*/&lt;br /&gt;System.out.println("try connection");&lt;br /&gt;try {&lt;br /&gt;// Load database driver&lt;br /&gt;Class.forName("org.apache.derby.jdbc.EmbeddedDriver");&lt;br /&gt;// Make connection&lt;br /&gt;String connn = "jdbc:derby:dbFin;create=true";&lt;br /&gt;connect = DriverManager.getConnection( connn );&lt;br /&gt;stat = connect.createStatement();&lt;br /&gt;System.out.println("connection succeeds");&lt;br /&gt;  }  catch(Exception ex) {&lt;br /&gt;System.out.println("connection fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;  }&lt;br /&gt;/**&lt;br /&gt;* These are the maketable lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try maketable");&lt;br /&gt;try {&lt;br /&gt;stat.executeUpdate(dCreate);&lt;br /&gt;System.out.println("maketable succeeds");&lt;br /&gt;  }  catch(Exception ex) {&lt;br /&gt;System.out.println("maketable fails");&lt;br /&gt;System.out.println(dCreate);&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;  } finally {&lt;br /&gt;// Close connection&lt;br /&gt;if (connect!= null) {&lt;br /&gt;try {&lt;br /&gt;connect.close();&lt;br /&gt;System.out.println("disconnection succeeds");&lt;br /&gt;} catch (SQLException sqlEx) {&lt;br /&gt;System.out.println("disconnection fails");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;  }&lt;br /&gt;   }&lt;br /&gt;}&lt;/pre&gt; &lt;p&gt;And if all goes well, the following should appear in the command  screen:&lt;/p&gt;  &lt;pre&gt;&lt;code&gt;Java -classpath&lt;br /&gt;"D:\Docs\Jonno\My Documents\CodeLocal\Fin\derby.jar";&lt;br /&gt;"D:\Docs\Jonno\My Documents\CodeLocal\Fin"&lt;br /&gt;FindbCreate&lt;br /&gt;try connection&lt;br /&gt;connection succeeds&lt;br /&gt;try maketable&lt;br /&gt;maketable succeeds&lt;br /&gt;disconnection succeeds&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;The database needs a second table.  This could have been included in the  code which created the first table, but when I am feeling my way, I like to take  things one step at a time.  The code I used to create the second table is  shown below.  Note the connect string no longer includes the create=true  switch, because when you run this code, the database already exists.&lt;/p&gt;  &lt;pre&gt;import java.sql.*;&lt;br /&gt;&lt;br /&gt;public class FindbCreateT2 {&lt;br /&gt;public static void main(String args[])&lt;br /&gt;  throws ClassNotFoundException, SQLException {&lt;br /&gt;/**&lt;br /&gt;* These are shared variable declarations&lt;br /&gt;*/&lt;br /&gt;Connection connect = null;&lt;br /&gt;Statement stat = null;&lt;br /&gt;String dCreate = "CREATE TABLE TransComp " +&lt;br /&gt;"(Sidx INTEGER, " +&lt;br /&gt;"dDate DATE, TrType CHAR(5), StCode CHAR(3), " +&lt;br /&gt;"TrPrice REAL, TrQ INTEGER)";&lt;br /&gt;/**&lt;br /&gt;* This is the start of the main code.&lt;br /&gt;*/&lt;br /&gt;System.out.println("try connection");&lt;br /&gt;try {&lt;br /&gt;// Load database driver&lt;br /&gt;Class.forName("org.apache.derby.jdbc.EmbeddedDriver");&lt;br /&gt;// Make connection&lt;br /&gt;String connn = "jdbc:derby:dbFin";&lt;br /&gt;connect = DriverManager.getConnection( connn );&lt;br /&gt;stat = connect.createStatement();&lt;br /&gt;System.out.println("connection succeeds");&lt;br /&gt; }  catch(Exception ex) {&lt;br /&gt;System.out.println("connection fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt; }&lt;br /&gt;/**&lt;br /&gt;* These are the maketable lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try maketable");&lt;br /&gt;try {&lt;br /&gt;stat.executeUpdate(dCreate);&lt;br /&gt;System.out.println("maketable succeeds");&lt;br /&gt; }  catch(Exception ex) {&lt;br /&gt;System.out.println("maketable fails");&lt;br /&gt;System.out.println(dCreate);&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt; } finally {&lt;br /&gt;// Close connection&lt;br /&gt;if (connect!= null) {&lt;br /&gt;try {&lt;br /&gt;connect.close();&lt;br /&gt;System.out.println("disconnection succeeds");&lt;br /&gt;} catch (SQLException sqlEx) {&lt;br /&gt;System.out.println("disconnection fails");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt; }&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;  &lt;p&gt;To run this code you can create a new batch file or edit cd3.bat to call the  class &lt;code&gt;FindbCreateT2&lt;/code&gt;.&lt;/p&gt;  &lt;p&gt;And if all goes well, the following should appear in the command  screen:&lt;/p&gt;  &lt;pre&gt;&lt;code&gt;Java -classpath&lt;br /&gt;"D:\Docs\Jonno\My Documents\CodeLocal\Fin\derby.jar";&lt;br /&gt;"D:\Docs\Jonno\My Documents\CodeLocal\Fin"&lt;br /&gt;FindbCreateT2&lt;br /&gt;try connection&lt;br /&gt;connection succeeds&lt;br /&gt;try maketable&lt;br /&gt;maketable succeeds&lt;br /&gt;disconnection succeeds&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;The first table, now needs to be filled.  Once again, the code to do so  could have been included in either of the previously shown classes, but I have  broken it out into a separate class for the time being:&lt;/p&gt;  &lt;pre&gt;import java.sql.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;public class FindbFill {&lt;br /&gt;public static void main(String args[])&lt;br /&gt; throws ClassNotFoundException, SQLException, IOException {&lt;br /&gt;/**&lt;br /&gt;* These are shared variable declarations&lt;br /&gt;*/&lt;br /&gt;  BufferedReader reader = null;&lt;br /&gt;String strContents = new String();&lt;br /&gt;String strTridx = new String();&lt;br /&gt;float fTridx = 0;&lt;br /&gt;int iTridx = 0;&lt;br /&gt;String strDate = new String();&lt;br /&gt;String strTrType = new String();&lt;br /&gt;String strCode = new String();&lt;br /&gt;String strPrice = new String();&lt;br /&gt;float fPrice = 0;&lt;br /&gt;String strTrQ = new String();&lt;br /&gt;float fTrQ = 0;&lt;br /&gt;int iTrQ = 0;&lt;br /&gt;int iCount = 0;&lt;br /&gt;Connection connect = null;&lt;br /&gt;Statement stat = null;&lt;br /&gt;String dInsert = "";&lt;br /&gt;/**&lt;br /&gt;* This is the start of the main code.&lt;br /&gt;*/&lt;br /&gt;System.out.println("try connection");&lt;br /&gt;try {&lt;br /&gt;// Load database driver&lt;br /&gt;Class.forName("org.apache.derby.jdbc.EmbeddedDriver");&lt;br /&gt;// Make connection&lt;br /&gt;String connn = "jdbc:derby:dbFin";&lt;br /&gt;connect = DriverManager.getConnection( connn );&lt;br /&gt;stat = connect.createStatement();&lt;br /&gt;System.out.println("connection succeeds");&lt;br /&gt;}  catch(Exception ex) {&lt;br /&gt;System.out.println("connection fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* These are optional delete lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try delete");&lt;br /&gt;try {&lt;br /&gt;stat.executeUpdate("DELETE FROM TransRaw where TRidx &gt; 0");&lt;br /&gt;System.out.println("delete succeeds");&lt;br /&gt;}  catch(Exception ex) {&lt;br /&gt;System.out.println("delete fails");&lt;br /&gt;System.out.println(dInsert);&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* This code reads the text file.&lt;br /&gt;*/&lt;br /&gt;  try {&lt;br /&gt;      reader = new BufferedReader(new FileReader("Tr100608.txt"));&lt;br /&gt;      String l;&lt;br /&gt;      while ((l = reader.readLine()) != null) {&lt;br /&gt;StringTokenizer strToken = new StringTokenizer(l, ",", false);&lt;br /&gt;strTridx = strToken.nextToken();&lt;br /&gt;strDate = strToken.nextToken();&lt;br /&gt;strTrType = strToken.nextToken();&lt;br /&gt;strCode = strToken.nextToken();&lt;br /&gt;strPrice = strToken.nextToken();&lt;br /&gt;strTrQ = strToken.nextToken();&lt;br /&gt;dInsert = "INSERT INTO TransRaw " +&lt;br /&gt;"VALUES (" + strTridx +&lt;br /&gt;", '" + strDate +&lt;br /&gt;"', '" + strTrType +&lt;br /&gt;"', '" + strCode +&lt;br /&gt;"', " + strPrice +&lt;br /&gt;", " + strTrQ + ")";&lt;br /&gt;/**&lt;br /&gt;* These are the insert lines&lt;br /&gt;*/&lt;br /&gt;//  System.out.println("try insert");&lt;br /&gt;//  System.out.println(dInsert);&lt;br /&gt;try {&lt;br /&gt;stat.executeUpdate(dInsert);&lt;br /&gt;iCount = iCount + 1;&lt;br /&gt;//   System.out.println("insert succeeds");&lt;br /&gt; }  catch(Exception ex) {&lt;br /&gt;System.out.println("insert fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;  }  catch(Exception ex) {&lt;br /&gt;System.out.println("Error: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* These are the closing statements&lt;br /&gt;*/&lt;br /&gt;finally {&lt;br /&gt;/**&lt;br /&gt;* Close input stream&lt;br /&gt;*/&lt;br /&gt;if (reader != null) {&lt;br /&gt;reader.close();&lt;br /&gt;}&lt;br /&gt;System.out.println(iCount + " records successfully inserted");&lt;br /&gt;/**&lt;br /&gt;* Close connection&lt;br /&gt;*/&lt;br /&gt;if (connect!= null) {&lt;br /&gt;try {&lt;br /&gt;connect.close();&lt;br /&gt;System.out.println("disconnection succeeds");&lt;br /&gt;} catch (SQLException sqlEx) {&lt;br /&gt;System.out.println("disconnection fails");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;  &lt;p&gt;Prior to running this code it is essential to have the source text file ready  and in the same directory as the java class file.  I should have a query  written so that I could quote the SQL, but instead I just exported a table from  "MS Access" and tweaked the text file a bit so that it looked like this:&lt;/p&gt;  &lt;pre&gt;1,05.09.2006,Buy,BSL,6.86,200&lt;br /&gt;2,12.09.2006,Buy,TFC,0.38,2500&lt;br /&gt;3,12.09.2006,Buy,ZFX,10.65,100&lt;br /&gt;4,12.09.2006,Buy,TLS,3.51,300&lt;br /&gt;5,13.09.2006,Buy,CSR,2.85,400 ... &lt;/pre&gt;  &lt;p&gt;When you run the &lt;code&gt;FindbFill&lt;/code&gt; class from the command line, if all goes well the  output messages should be as follows:&lt;/p&gt;  &lt;pre&gt;Java -classpath&lt;br /&gt;"D:\Docs\Jonno\My Documents\CodeLocal\Fin\derby.jar";&lt;br /&gt;"D:\Docs\Jonno\My Documents\CodeLocal\Fin"&lt;br /&gt;FindbFill&lt;br /&gt;try connection&lt;br /&gt;connection succeeds&lt;br /&gt;try delete&lt;br /&gt;delete succeeds&lt;br /&gt;378 records successfully inserted&lt;br /&gt;disconnection succeeds &lt;/pre&gt;   &lt;p&gt;If you get the format of the text file wrong, you might get a few error  messages like these:&lt;/p&gt;   &lt;pre&gt;insert fails SQLException:&lt;br /&gt;Syntax error: Encountered "," at line 1, column 33.&lt;br /&gt;insert fails SQLException:&lt;br /&gt;Lexical error at line 1, column 64.&lt;br /&gt;Encountered: "$" (36), after: "".&lt;/pre&gt;   &lt;p&gt;After filling the &lt;code&gt;TransRaw&lt;/code&gt; table, the penultimate step is to transform the data and  fill the &lt;code&gt;TransComp&lt;/code&gt; table.  Once again, I have written the code for this in a class of its  own.  The code is as follows:&lt;/p&gt;   &lt;pre&gt;import java.sql.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;public class FindbQ1 {&lt;br /&gt;public static void main(String args[])&lt;br /&gt;throws ClassNotFoundException, SQLException, IOException {&lt;br /&gt;/**&lt;br /&gt;* These are shared variable declarations&lt;br /&gt;*/&lt;br /&gt;Connection connect = null;&lt;br /&gt;Statement statS = null;&lt;br /&gt;Statement statB = null;&lt;br /&gt;Statement statI = null;&lt;br /&gt;ResultSet resultBuy = null;&lt;br /&gt;String Sidx = new String();&lt;br /&gt;String Bidx = new String();&lt;br /&gt;String strDate = new String();&lt;br /&gt;String strTrType = new String();&lt;br /&gt;String strCode = new String();&lt;br /&gt;String strPrice = new String();&lt;br /&gt;String strTrQ = new String();&lt;br /&gt;String dInsert = new String();&lt;br /&gt;String dDelete = new String();&lt;br /&gt;float fSPrice = 0;&lt;br /&gt;float fSQ = 0;&lt;br /&gt;float fSProc = 0;&lt;br /&gt;float fBCumQ = 0;&lt;br /&gt;float fBCurQ = 0;&lt;br /&gt;float fBEQ = 0;&lt;br /&gt;int iBEQ = 0;&lt;br /&gt;float fBPrice = 0;&lt;br /&gt;float fBCurCost = 0;&lt;br /&gt;float fBCumCost = 0;&lt;br /&gt;float fProfit = 0;&lt;br /&gt;float fComm = 22;&lt;br /&gt;/**&lt;br /&gt;* This is the start of the main code.&lt;br /&gt;*/&lt;br /&gt;System.out.println("try connection");&lt;br /&gt;try {&lt;br /&gt;// Load database driver&lt;br /&gt;Class.forName("org.apache.derby.jdbc.EmbeddedDriver");&lt;br /&gt;// Make connection&lt;br /&gt;String connn = "jdbc:derby:dbFin";&lt;br /&gt;connect = DriverManager.getConnection( connn );&lt;br /&gt;statS = connect.createStatement();&lt;br /&gt;statB = connect.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,&lt;br /&gt;ResultSet.CONCUR_UPDATABLE);&lt;br /&gt;statI = connect.createStatement();&lt;br /&gt;System.out.println("connection succeeds");&lt;br /&gt;}  catch(Exception ex) {&lt;br /&gt;System.out.println("connection fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* These are optional delete lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try delete");&lt;br /&gt;try {&lt;br /&gt;statI.executeUpdate("DELETE FROM TransComp");&lt;br /&gt;System.out.println("delete succeeds");&lt;br /&gt;}  catch(Exception ex) {&lt;br /&gt;System.out.println("delete fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* These are query execution lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try query");&lt;br /&gt;try {&lt;br /&gt;String aquery = "SELECT * FROM TransRaw" +&lt;br /&gt;" where TrType = 'Sell'" +&lt;br /&gt;" order by dDate, TRidx";&lt;br /&gt;ResultSet resultSell = statS.executeQuery(aquery);&lt;br /&gt;/**&lt;br /&gt;* Display sell results.&lt;br /&gt;*/&lt;br /&gt;while(resultSell.next()) {&lt;br /&gt;   Sidx = resultSell.getString(1);&lt;br /&gt;   strDate = resultSell.getString(2);&lt;br /&gt;   strTrType = resultSell.getString(3);&lt;br /&gt;   strCode = resultSell.getString(4);&lt;br /&gt;   strPrice = resultSell.getString(5);&lt;br /&gt;   strTrQ = resultSell.getString(6);&lt;br /&gt;   fSPrice = resultSell.getFloat(5);&lt;br /&gt;   fSQ = -resultSell.getFloat(6);&lt;br /&gt;   fSProc = fSPrice * fSQ;&lt;br /&gt;   fSProc = fSProc - fComm;&lt;br /&gt;dInsert = "INSERT INTO TransComp " +&lt;br /&gt;"VALUES (" + Sidx +&lt;br /&gt;", '" + strDate +&lt;br /&gt;"', '" + strTrType +&lt;br /&gt;"', '" + strCode +&lt;br /&gt;"', " + strPrice +&lt;br /&gt;", " + strTrQ + ")";&lt;br /&gt;System.out.println(dInsert);&lt;br /&gt;/**&lt;br /&gt;* These are the insert lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try insert");&lt;br /&gt;try {&lt;br /&gt;statI.executeUpdate(dInsert);&lt;br /&gt;System.out.println("insert succeeds");&lt;br /&gt; }  catch(Exception ex) {&lt;br /&gt;System.out.println("insert fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt; }&lt;br /&gt;/**&lt;br /&gt;* Display buy results.&lt;br /&gt;*/&lt;br /&gt;String bquery = "SELECT * FROM TransRaw" +&lt;br /&gt;" where TrType = 'Buy'" +&lt;br /&gt;" and StCode = '" +&lt;br /&gt;strCode +&lt;br /&gt;"' for update of TrQ";&lt;br /&gt;resultBuy = statB.executeQuery(bquery);&lt;br /&gt;fBCumQ = 0;&lt;br /&gt;fBCumCost = 0;&lt;br /&gt;fProfit = 0;&lt;br /&gt;while(fBCumQ &lt; bidx =" resultBuy.getString(1);" strdate =" resultBuy.getString(2);" strtrtype =" resultBuy.getString(3);" strcode =" resultBuy.getString(4);" strprice =" resultBuy.getString(5);" strtrq =" resultBuy.getString(6);" fbprice =" resultBuy.getFloat(5);" fbcurq =" resultBuy.getFloat(6);" fbcumq =" fBCumQ"&gt; fSQ){&lt;br /&gt;     fBEQ = fBCumQ - fSQ;&lt;br /&gt;     fBCurQ = fBCurQ - fBEQ;&lt;br /&gt;     fBCumQ = fBCumQ - fBEQ;&lt;br /&gt;     iBEQ = (int)(fBEQ);&lt;br /&gt;     resultBuy.updateInt("TrQ", iBEQ);&lt;br /&gt;    } else {&lt;br /&gt;     dDelete = "DELETE FROM TransRaw " +&lt;br /&gt;     "where TRidx = " + Bidx;&lt;br /&gt;     statI.executeUpdate(dDelete);&lt;br /&gt;    }&lt;br /&gt;    fBCurCost = fBCurQ * fBPrice;&lt;br /&gt;    fBCurCost = fBCurCost + fComm;&lt;br /&gt;    fBCumCost = fBCumCost + fBCurCost;&lt;br /&gt;dInsert = "INSERT INTO TransComp " +&lt;br /&gt;"VALUES (" + Sidx +&lt;br /&gt;", '" + strDate +&lt;br /&gt;"', '" + strTrType +&lt;br /&gt;"', '" + strCode +&lt;br /&gt;"', " + strPrice +&lt;br /&gt;", " + fBCurQ + ")";&lt;br /&gt;System.out.println(dInsert);&lt;br /&gt;/**&lt;br /&gt;* These are the insert lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try insert");&lt;br /&gt;try {&lt;br /&gt;statI.executeUpdate(dInsert);&lt;br /&gt;System.out.println("insert succeeds");&lt;br /&gt;  }  catch(Exception ex) {&lt;br /&gt;System.out.println("insert fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;fProfit = fSProc - fBCumCost;&lt;br /&gt;System.out.println("Proceeds = " + fSProc);&lt;br /&gt;System.out.println("Costs    = " + fBCumCost);&lt;br /&gt;System.out.println("Profit   = " + fProfit);&lt;br /&gt;resultBuy.close();&lt;br /&gt;}&lt;br /&gt;resultSell.close();&lt;br /&gt;statS.close();&lt;br /&gt;statB.close();&lt;br /&gt;statI.close();&lt;br /&gt;System.out.println("query succeeds");&lt;br /&gt;}  catch(Exception ex) {&lt;br /&gt;System.out.println("query fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;} finally {&lt;br /&gt;// Close connection&lt;br /&gt;if (connect!= null) {&lt;br /&gt;try {&lt;br /&gt;connect.close();&lt;br /&gt;System.out.println("disconnection succeeds");&lt;br /&gt;} catch (SQLException sqlEx) {&lt;br /&gt;System.out.println("disconnection fails");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;   &lt;p&gt;The output from this one gives all the information I need to complete my tax  return, but the command window is a less than ideal place to store it, and the  format is not suitable for cutting and pasting into a data table.  I  therefore have a final chunk of code, which queries the &lt;code&gt;TransComp&lt;/code&gt;  table, and dumps the data cleanly into the command window.  The code is as  follows:&lt;/p&gt;   &lt;pre&gt;import java.sql.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;public class FindbQSim2 {&lt;br /&gt;public static void main(String args[])&lt;br /&gt;throws ClassNotFoundException, SQLException, IOException {&lt;br /&gt;/**&lt;br /&gt;* These are shared variable declarations&lt;br /&gt;*/&lt;br /&gt;Connection connect = null;&lt;br /&gt;Statement stat = null;&lt;br /&gt;/**&lt;br /&gt;* This is the start of the main code.&lt;br /&gt;*/&lt;br /&gt;System.out.println("try connection");&lt;br /&gt;try {&lt;br /&gt;// Load database driver&lt;br /&gt;Class.forName("org.apache.derby.jdbc.EmbeddedDriver");&lt;br /&gt;// Make connection&lt;br /&gt;String connn = "jdbc:derby:dbFin";&lt;br /&gt;connect = DriverManager.getConnection( connn );&lt;br /&gt;stat = connect.createStatement();&lt;br /&gt;System.out.println("connection succeeds");&lt;br /&gt;}  catch(Exception ex) {&lt;br /&gt;System.out.println("connection fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;}&lt;br /&gt;/**&lt;br /&gt;* These are query execution lines&lt;br /&gt;*/&lt;br /&gt;System.out.println("try query");&lt;br /&gt;try {&lt;br /&gt;String aquery = "SELECT * FROM TransComp";&lt;br /&gt;ResultSet resultSet = stat.executeQuery(aquery);&lt;br /&gt;// Display results&lt;br /&gt;while(resultSet.next()) {&lt;br /&gt;   System.out.println(resultSet.getString(1) + ", " +&lt;br /&gt;   resultSet.getString(2) + ", " +&lt;br /&gt;   resultSet.getString(3) + ", " +&lt;br /&gt;   resultSet.getString(4) + ", " +&lt;br /&gt;   resultSet.getString(5) + ", " +&lt;br /&gt;   resultSet.getString(6));&lt;br /&gt;}&lt;br /&gt;resultSet.close();&lt;br /&gt;stat.close();&lt;br /&gt;System.out.println("query succeeds");&lt;br /&gt;}  catch(Exception ex) {&lt;br /&gt;System.out.println("query fails");&lt;br /&gt;System.err.println("SQLException: " + ex.getMessage());&lt;br /&gt;} finally {&lt;br /&gt;// Close connection&lt;br /&gt;if (connect!= null) {&lt;br /&gt;try {&lt;br /&gt;connect.close();&lt;br /&gt;System.out.println("disconnection succeeds");&lt;br /&gt;} catch (SQLException sqlEx) {&lt;br /&gt;System.out.println("disconnection fails");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;   &lt;p&gt;Had time permitted I could have output the data to a text file, but it was  just as easy to copy and paste from the command line.  I imported this to a  table in "MS Access" and used the GUI to make a nice WYSIWYG report.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-6795078701862696811?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/6795078701862696811/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=6795078701862696811' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6795078701862696811'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/6795078701862696811'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2010/06/revisiting-old-code.html' title='Revisiting old code'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-5551629229201555901</id><published>2010-05-29T03:03:00.000-07:00</published><updated>2011-02-15T03:08:42.812-08:00</updated><title type='text'>Conundrum</title><content type='html'>&lt;p&gt;The idea of my &lt;a href="https://java.net/projects/rasch-itembank/"&gt;Rasch-Itembank  open-source project&lt;/a&gt; at java.net is to produce a large numeracy estimation  item bank, which updates the estimated difficulty parameters in real time, as it  is used.  To work properly, the client needs to generate items from the  item bank according to the latest item difficulty estimation.&lt;/p&gt; &lt;p&gt;The &lt;a href="http://www.interactived.com/jartest0906.htm"&gt;most reliable  current working version of my Java Math Test&lt;/a&gt; client is a complete cheat.   It has absolutely no connection with a database, it is ISP hosted, and it  usually works first time, as long as the user has the JRE installed.&lt;/p&gt; &lt;p&gt;A &lt;a href="http://58.7.121.42/myweb/jartest.htm"&gt;second version, hosted by me&lt;/a&gt;,  is a partial cheat.  It connects to a database to record performance data,  but it uses hard coded arrays of items, whose difficulty has been estimated from  static data collected in the past.  This version is less reliable for many  reasons.  I don't always have the server turned on, I don't always have the  database turned on, and sometimes my IP address changes.&lt;/p&gt; &lt;p&gt;The conundrum is that to get improved estimates of item difficulty, the  client needs to be used, and to be used a lot, it needs to be reliable.   Using hard coded item arrays, if the connection to the database fails, session  data is lost, but the client continues to function, so the user is not pissed  off.&lt;/p&gt; &lt;p&gt;However, in this more reliable configuration, a key selling point - that item  difficulty and student ability mutually interact in real time, to product the  best possible estimates of both - becomes something of a deception. &lt;/p&gt; &lt;p&gt;I think the best compromise solution is to leave reliable versions on &lt;a href="http://www.interactived.com/softway.htm"&gt;my web site&lt;/a&gt;, perhaps with  the hard coded arrays updated from time to time as more data comes in, and to  develop code for the true blue dinky dye version without actually deploying it  until data connection reliability can be assured.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-5551629229201555901?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/5551629229201555901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=5551629229201555901' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5551629229201555901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5551629229201555901'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2010/05/conundrum.html' title='Conundrum'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-3892274720975093199</id><published>2010-05-28T05:33:00.000-07:00</published><updated>2010-05-28T05:34:19.362-07:00</updated><title type='text'>Structural Changes to the Repository</title><content type='html'>&lt;p&gt;For a couple of reasons I have made some structural changes to my remote code  store, or repository.  First, if I want other people to contribute, I need  to make it easy to understand what goes where.  Secondly, I wanted to play  around a bit more with subversion (svn) commands.&lt;/p&gt; &lt;p&gt;My first task was to create some new directories.  When I read  &lt;a href="http://svnbook.red-bean.com/en/1.5/svn.tour.cycle.html"&gt;the book&lt;/a&gt;,  it looked as if you used svn commands just like DOS or "shell" commands, and  instead of them.  So I tried:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;svn add "my documents\code\100515\client" &lt;/code&gt;&lt;/p&gt;  &lt;p&gt;without having first created the client subdirectory.  But it didn't  work.  The wording given by the &lt;code&gt;--help&lt;/code&gt; switch makes it clearer:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;svn add --help&lt;br /&gt;add: Put files and directories under version control, scheduling&lt;br /&gt;them for addition to repository.&lt;br /&gt;usage: add PATH... &lt;/code&gt;&lt;/p&gt;  &lt;p&gt;In other words the add command brings a folder under the svn umbrella, but it  cannot be used to create one.&lt;/p&gt; &lt;p&gt;Next I wanted to move some source files from the trunk to the new  subdirectory.  The command and the displayed results were as follows.&lt;/p&gt; &lt;p&gt;&lt;code&gt;svn move "my documents\code\100515\AMJApp.java"&lt;br /&gt;"my documents\code\100515\client\src"&lt;br /&gt;A My Documents\Code\100515\Client\src\AMJApp.java&lt;br /&gt;D My Documents\Code\100515\AMJApp.java&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This time the svn command really did replace the equivalent DOS command.   I repeated the process for all my source files.&lt;/p&gt; &lt;p&gt;I then committed the changes:&lt;/p&gt; &lt;p&gt;&lt;code&gt;svn commit "my documents\code\100515" -m&lt;br /&gt;"Added a preliminary directory structure"&lt;br /&gt;Deleting My Documents\Code\100515\AMJApp.java&lt;br /&gt;Adding My Documents\Code\100515\Client&lt;br /&gt;Adding My Documents\Code\100515\Client\src&lt;br /&gt;Adding My Documents\Code\100515\Client\src\AMJApp.java&lt;br /&gt;Adding My Documents\Code\100515\Client\src\QAdd.java&lt;br /&gt;Adding My Documents\Code\100515\Client\src\QDiv.java&lt;br /&gt;Adding My Documents\Code\100515\Client\src\QMul.java&lt;br /&gt;Adding My Documents\Code\100515\Client\src\QSub.java&lt;br /&gt;Adding My Documents\Code\100515\Client\src\QTrack.java&lt;br /&gt;Deleting My Documents\Code\100515\QAdd.java&lt;br /&gt;Deleting My Documents\Code\100515\QDiv.java&lt;br /&gt;Deleting My Documents\Code\100515\QMul.java&lt;br /&gt;Deleting My Documents\Code\100515\QSub.java&lt;br /&gt;Deleting My Documents\Code\100515\QTrack.java&lt;/code&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-3892274720975093199?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/3892274720975093199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=3892274720975093199' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3892274720975093199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3892274720975093199'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2010/05/structural-changes-to-repository.html' title='Structural Changes to the Repository'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-5358239867895869101</id><published>2010-05-16T02:20:00.000-07:00</published><updated>2011-02-15T03:12:16.926-08:00</updated><title type='text'>Updating Source Code</title><content type='html'>&lt;p&gt;I think I was a little too cryptic in my blog entitled &lt;a href="http://jhippjava.blogspot.com/2010/01/posting-source-code.html"&gt;Posting  Source Code&lt;/a&gt;.  I referred back to it when I needed to update the source  code on my &lt;a href="https://rasch-itembank.dev.java.net/"&gt;project site&lt;/a&gt;, and  found it fell short of being helpful.&lt;/p&gt; &lt;p&gt;I shall try to be a bit more explicit in describing how I checked out what  was in the repository, and after making some changes, updated it.&lt;/p&gt; &lt;p&gt;When first using &lt;a href="http://www.open.collab.net/products/subversion/"&gt; CollabNet Subversion&lt;/a&gt; I made the mistake of cluttering my home computer with  the server.  I am on a new machine now, and I took care to get the  command-line &lt;i&gt;client&lt;/i&gt; from the &lt;a href="http://www.collab.net/downloads/subversion/"&gt;CollabNet Download&lt;/a&gt;  page.&lt;/p&gt; &lt;p&gt;After installing the client, I was pleasantly surprised to observe that it  ran happily from my Windows home directory.  That is in stark contrast to  Java, which requires paths to be set up by the user.&lt;/p&gt; &lt;p&gt;The command I needed to download my code into a working directory was&lt;/p&gt; &lt;p&gt;&lt;code&gt;svn checkout URL [PATH] --USERNAME&lt;/code&gt;&lt;/p&gt; &lt;p&gt;where URL is location of my repository and PATH is the path to the local  directory.  My URL is:&lt;/p&gt; &lt;p&gt;&lt;code&gt;https://java.net/projects/rasch-itembank/svn/rasch-itembank/trunk&lt;/code&gt;&lt;/p&gt; &lt;p&gt;and my local path for the day is:&lt;/p&gt; &lt;p&gt;&lt;code&gt;"my documents\code\100515"&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;To edit the source code I use jEdit, and because this is an exercise in  downloading from and uploading to a remote repository, I just add a few comments  to each source file.&lt;/p&gt;  &lt;p&gt;I was fiddling about with this overnight, so I used the update command to  check for any other activity.  This was an academic exercise, because I am  currently the only user, but I wanted to work through the proper procedure.   The syntax of the command is:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;svn update [PATH] &lt;/code&gt;&lt;/p&gt;  &lt;p&gt;In my case this translates as:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;svn update "my documents\code\100515" &lt;/code&gt;&lt;/p&gt;  &lt;p&gt;The response came back:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;At revision 5&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;The absence of any user listing confirms that no one else has worked on the  code in the repository.&lt;/p&gt;  &lt;p&gt;Again following on with the procedure recommended in  &lt;a href="http://svnbook.red-bean.com/en/1.5/svn.tour.cycle.html"&gt;the book&lt;/a&gt;, I used the  &lt;code&gt;status&lt;/code&gt; command as follows:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;svn status "my documents\code\100515"&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And got the following list of modified files.&lt;/p&gt; &lt;p&gt;&lt;code&gt;M My Documents\Code\100515\QDiv.java&lt;br /&gt;M My Documents\Code\100515\QTrack.java&lt;br /&gt;M My Documents\Code\100515\AMJApp.java&lt;br /&gt;M My Documents\Code\100515\QAdd.java&lt;br /&gt;M My Documents\Code\100515\QSub.java&lt;br /&gt;M My Documents\Code\100515\QMul.java&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;I used the  &lt;code&gt;status&lt;/code&gt; command, with identical syntax, to display a full list of  the changes I had made.&lt;/p&gt;  &lt;p&gt;As there are currently no other users I could skip the conflict resolution  steps, because the were no conflicts to resolve.  I could therefore jump  straight to the commit &lt;code&gt;command&lt;/code&gt; as follows:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;svn commit "my documents\code\100515" -m "Just added&lt;br /&gt;a few comments to test the update procedure"&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And got the following list of actions carried out.&lt;/p&gt; &lt;p&gt;&lt;code&gt;Sending My Documents\Code\100515\AMJApp.java&lt;br /&gt;Sending My Documents\Code\100515\QAdd.java&lt;br /&gt;Sending My Documents\Code\100515\QDiv.java&lt;br /&gt;Sending My Documents\Code\100515\QMul.java&lt;br /&gt;Sending My Documents\Code\100515\QSub.java&lt;br /&gt;Sending My Documents\Code\100515\QTrack.java&lt;br /&gt;Transmitting file data ......&lt;br /&gt;Committed revision 6.&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;Hopefully this is a clearer set of instructions than my last effort, so if I  come back here in six months time, I'll actually understand what I've written.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-5358239867895869101?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/5358239867895869101/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=5358239867895869101' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5358239867895869101'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5358239867895869101'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2010/05/updating-source-code.html' title='Updating Source Code'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-8066301597935041514</id><published>2010-01-08T00:06:00.000-08:00</published><updated>2010-01-08T00:11:10.788-08:00</updated><title type='text'>Parameter Estimation</title><content type='html'>&lt;p&gt;The &lt;a href="http://www.amazon.com/Probabilistic-Models-Intelligence-Attainment-Tests/dp/0226705544"&gt;Rasch book&lt;/a&gt;, and the &lt;a href="http://www.winsteps.com/"&gt;Winsteps&lt;/a&gt; documentation, about which I have written at some length, are both essentially about parameter estimation.  And one of the objectives I want to achieve with &lt;a href="http://www.interactived.com/jartest0906.htm"&gt;my java applet&lt;/a&gt;, is real time parameter estimation.  I revisited the Rasch book, and spent some time trying to follow the argument, when really I should have just gone straight for a &lt;a href="http://wiki.stat.ucla.edu/socr/index.php/EBook"&gt;math text book&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Rasch presents his mathematical argument as if it is new or somehow unique to the paradigm he is presenting; perhaps it was at the time, although by his own references to physics in the introduction I doubt it.  Perhaps in those days it was conventional to present an argument in full, rather than simply refer the reader to one or more generics methods, and assume the reader has the ability to look them up.  Certainly &lt;a href="http://www.amazon.com/Probabilistic-Models-Intelligence-Attainment-Tests/dp/0226705544"&gt;the book&lt;/a&gt; could have been a lot shorter, had he done so.&lt;/p&gt; &lt;p&gt;At the end of the day there is no substitute for the &lt;a href="http://en.wikipedia.org/wiki/Law_of_large_numbers"&gt;Law of Large Numbers&lt;/a&gt;, which essentially states that when your sample becomes large enough the experimental frequency of events will approximate to the expected frequency, and the need for esoteric and highfalutin mathematics is dispensed with.  That is why, regardless of whether people accept my preference for &lt;a href="http://jhippjava.blogspot.com/2009/08/scores-versus-scoring-rates.html"&gt;scoring rates over raw scores&lt;/a&gt;, there is a strong argument for establishing a &lt;a href="https://rasch-itembank.dev.java.net/"&gt;global item bank&lt;/a&gt; for frequently used items in the estimation of numeracy and other psychometric parameters.&lt;/p&gt; &lt;p&gt;The one feature of &lt;a href="http://jhippjava.blogspot.com/2009/08/rasch-parameters.html"&gt;Rasch-parameter&lt;/a&gt; estimation, which perhaps is unique, or at least unusual, is the need for the simultaneous estimation of two parameters.  If you toss a coin a hundred times and show roughly 50 heads, you can deduce that the probability of throwing a head is roughly 50%.  If a child sits ten tests and scores an average of 95%, you can deduce the mean probability of success on the test items was 95%, but in Rasch theory, that probability itself derives from two parameters - the ability of the child and the difficulty of the test.  These results in isolation do not tell you whether the child is very clever, or the test is very easy.  This is the problem which &lt;a href="http://www.winsteps.com/"&gt;Winsteps&lt;/a&gt; seeks to address with its data transformations and iterations, and which I have sought to address with my &lt;a href="http://jhippjava.blogspot.com/2009/08/scoring-rate-quotient-srq.html"&gt;scoring rate quotient&lt;/a&gt;.  Unfortunately, although Rasch showed in theory how to isolate each parameter in turn, he offered little advice on practical methodology, so to some extent there is no single authoritative source on the matter.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-8066301597935041514?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/8066301597935041514/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=8066301597935041514' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8066301597935041514'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8066301597935041514'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2010/01/parameter-estimation.html' title='Parameter Estimation'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-906655999267600110</id><published>2010-01-06T21:00:00.000-08:00</published><updated>2010-01-06T21:01:14.169-08:00</updated><title type='text'>Probability Theory</title><content type='html'>&lt;p&gt;Now that I've published some code, a risk arises that someone might read it, and thereby discover that the code does not really conform with my project description.  I should really rewrite it as quickly as possible, to minimise the risk of discovery, but there is a theoretical matter I should like to address first.&lt;/p&gt; &lt;p&gt;After writing my blog of &lt;a href="http://jhippjava.blogspot.com/2009/08/scores-versus-scoring-rates.html"&gt;9 August 2009&lt;/a&gt;, I thought I had stumbled across something worthy of more formal publication.  So I contacted my doctoral supervisors at &lt;a href="http://www.uwa.edu.au/"&gt;UWA&lt;/a&gt;, and some people at the &lt;a href="http://www.rasch.org/"&gt;Institute for Objective Measurement&lt;/a&gt;, but to cut a long story short nothing has happened.&lt;/p&gt; &lt;p&gt;To be honest I was looking for help with the theory as much as a co-author.  The probability theory was a bit out of my depth, so I was looking for someone who knew more about it.  But apart from one pragmatic and generally expedient former supervisor, who offered to "help" (which really means proof read), because he felt sorry for me, I drew a blank.&lt;/p&gt; &lt;p&gt;I guess I have this fantasy of communicating with intelligent people of like interest, like you read about in books or see in TV docos about famous scientists; but it never really works out.  I am not trying to put myself on a plane with famous scientists, but I am a qualified and published academic in a certain field, and it is disappointing to me that I have failed to track down anyone of like mind, either when I was enrolled at the university or since.  &lt;/p&gt; &lt;p&gt; I had two supervisors, one of whom checked for grammatical and spelling mistakes and the other of whom checked for calculation errors.  They did a good job, and I passed, but it was intellectually disappointing that they never really understood where I was coming from or what I was driving at.&lt;/p&gt; &lt;p&gt;And during that time I published five papers in refereed journals in three countries, the UK, Australia, and the US, and I had not one item of correspondence arising from any of them.  I had emails from people interested in &lt;a href="http://www.interactived.com/softway.htm"&gt;my website&lt;/a&gt;, but nothing from the printed journals.  &lt;/p&gt;  &lt;p&gt;So why do I want to publish in a refereed journal again?  Fair question.  Partly a litmus test, for approval rating, and partly, because, rightly or wrongly, they look good on a CV or personal web site.  But it is not that important.&lt;/p&gt;  &lt;p&gt;What is important, whether I am writing for a journal or a blog, is that I get right what I am trying to say.  And having failed to find an academic who is either qualified or interested to help me, I shall simply have to gem up on the theory myself.&lt;/p&gt;  &lt;p&gt;The good news is what social scientists and especially educationalists find esoteric and rarefied, scientists in other areas find bog standard.  So the stuff I need to learn is available in undergraduate text books for mathematics and the natural sciences.  I shall use the &lt;a href="http://wiki.stat.ucla.edu/socr/index.php/EBook"&gt;Probability and statistics EBook&lt;/a&gt;, published by UCLA.  I have referred to it &lt;a href="http://jhippjava.blogspot.com/2009/08/scores-versus-scoring-rates.html"&gt;before&lt;/a&gt;, and probably mentioned that it is quite fun to read, with lots of graphic examples.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-906655999267600110?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/906655999267600110/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=906655999267600110' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/906655999267600110'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/906655999267600110'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2010/01/probability-theory.html' title='Probability Theory'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-4073586842778347873</id><published>2010-01-05T06:35:00.001-08:00</published><updated>2010-01-05T06:35:55.680-08:00</updated><title type='text'>Posting Source Code</title><content type='html'>&lt;p&gt;&lt;a href="http://www.open.collab.net/products/subversion/"&gt;CollabNet Subversion&lt;/a&gt;  turns out not to be quite so hard to learn as I expected.&lt;/p&gt; &lt;p&gt;I had set out with a fundamental misconception, believing I needed to set up  the server on my end as well.  &lt;/p&gt; &lt;p&gt;When I realised that Sun had already done all that work for me at their end,  and that I simply had to use the client to post code on their server, and that I  could edit the local files with whatever I wanted at my end, it all became much  clearer to me.&lt;/p&gt; &lt;p&gt;Furthermore, Sun even provided the URL for &lt;a href="https://rasch-itembank.dev.java.net/"&gt;my  project&lt;/a&gt; on their server together with the syntax for the checkout  command.  &lt;/p&gt; &lt;p&gt;It was pretty easy to combine the URL in this example with the import command  given in &lt;a href="http://svnbook.red-bean.com/"&gt;the book&lt;/a&gt; to post my source  code in the project.  I say pretty easy; there was a bit of fiddling  around.  The checkout command includes a local path to which files should  be copied, and obviously that is not needed for the import (which term from my  perspective really means export or post), and the -m switch/parameter needed to  be filled with a comment.&lt;/p&gt; &lt;p&gt;But at the end of the day, a first draft of my code is posted, and I feel  much better.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-4073586842778347873?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/4073586842778347873/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=4073586842778347873' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4073586842778347873'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/4073586842778347873'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2010/01/posting-source-code.html' title='Posting Source Code'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-9044021861397531135</id><published>2010-01-04T18:32:00.000-08:00</published><updated>2010-01-04T18:36:09.093-08:00</updated><title type='text'>Going Open Source</title><content type='html'>&lt;p&gt;I have decided to go open source.  It has been my intention to do so for  a long time, but I hesitated for several months, because I thought my more  commercially minded friends would call me a fool.  So I put some feelers  out into the commercial world, and they were substantially ignored.  With  hindsight I should have followed my first instinct without hesitation, because  the exercise has been a blow to my confidence.  I am now launching myself  into the open source community with a very dented ego and a low self esteem.&lt;/p&gt; &lt;p&gt;To make it worse, going open source is not a simple exercise.  You don't  just say hello world this is my source code, share it with me.  You have to  master a technology called version control, and at first glance the learning  curve looks as steep as embracing java itself.  I feel is if I've started  all over again, and this time, instead if having my head held high, my heart is  in my boots.&lt;/p&gt; &lt;p&gt;When I began this blog 18 months ago, I was full of optimism.  I was  quite excited about learning a new programming language, and I was enthusiastic  about rewriting my code to make it better than before.  I was very  optimistic about using the web as a distribution tool, because it meant the  whole world could use my software as soon as it was written, without me using a  litre of fuel, or buying a postage stamp.  &lt;/p&gt; &lt;p&gt;Now it seems that so many other people have mastered the art of delivering  tools on the web, the availability of software, free and otherwise, way exceeds  the ability or inclination of people to use it.&lt;/p&gt; &lt;p&gt;So wilh heavy heart, I am beginning to read an online book entitled "&lt;a href="http://svnbook.red-bean.com/"&gt;Version  Control with Subversion&lt;/a&gt;".  It seems well written, but long.   Right now I cannot even envisage how my manually edited and managed source code  files will fit into its system, so I must resign myself to many hours of dry  reading.  I'll crack open a box of matches to hold open my eyes.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-9044021861397531135?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/9044021861397531135/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=9044021861397531135' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/9044021861397531135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/9044021861397531135'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2010/01/going-open-source.html' title='Going Open Source'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-3406419295438046724</id><published>2009-12-09T07:06:00.000-08:00</published><updated>2009-12-09T07:09:59.114-08:00</updated><title type='text'>The nub</title><content type='html'>&lt;p&gt;Sometimes people ask why I do what I do.  Why do I write software nobody  wants to use?  Why do I care about the reliability and validity of  psychometric data?  Why do I want to make available assessment tools, which  are accurate and meaningful, as well as cheap and easy to use?&lt;/p&gt; &lt;p&gt;I answer a question with a question.  How is it, I say, that scientists  such as Newton and Einstein were born at exactly the right time and in exactly  the right place for their work to be understood, appreciated, tested, and  applied?&lt;/p&gt; &lt;p&gt;The answer, I reply to myself, is that Newtons and Einsteins have been born  in mud huts throughout the globe, throughout history; and they are still being  born.  The Newton we read about happened to the lucky one born in the right  place at the right time, wealthy enough to receive an education and to study as  a vocation, in a society disposed to listen, rather than ignore him, imprison  him, or burn him at the stake.  Einstein was also a lucky one, born at a  time when his more esoteric theories could be put to the test and applied.&lt;/p&gt; &lt;p&gt;My mission is to dredge out the genius buried in the mud huts and slums of  the world.&lt;/p&gt; &lt;p&gt;Why do I care?  I care because I know it is there.  I have seen  children begging in the slums of India, with minds crying out to be heard.&lt;/p&gt; &lt;p&gt;I have another blog, which I use to express disdain for the society in which  we live, so I shall refrain from raving on here.  I shall simply suggest  that every intelligent child lifted from the mire may contribute to lifting  society itself from the mire, in later life.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-3406419295438046724?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/3406419295438046724/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=3406419295438046724' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3406419295438046724'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3406419295438046724'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2009/12/nub.html' title='The nub'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-5515145478928991278</id><published>2009-10-20T03:32:00.000-07:00</published><updated>2009-10-20T03:34:00.216-07:00</updated><title type='text'>Marketing</title><content type='html'>&lt;p&gt;I am crap at marketing.  In a perfect world, I'd never have to sell  anything.  I'd just be.  But the world is not perfect.  And why  waste time creating computer software if you can't sell it?&lt;/p&gt; &lt;p&gt;One of the reasons I began the quest to learn Java was that the version of my  software written in VB6 is sitting on 600 CD's, which now gather dust in my  living room.  I spent a year writing to, calling and visiting schools, but  the revenue generated was barely compensation for the installation time, let  alone marketing, let alone development.&lt;/p&gt; &lt;p&gt;Out of 221 schools on the target list (essentially primary schools in the  metropolitan area of Perth, Western Australia), 61 agreed to a meeting and a  trial on at least one computer, and 16 actually paid for a full site  license.  The official price was $660, but I let some have it for half  that, and I always threw in a day's worth of installation and training.  I  didn't charge for the two or three presale visits, and for the three to six  month evaluation and decision making period, I had no income.  After a year  of this, and a negative income after operating costs, I pulled up stumps and let  the software rot.&lt;/p&gt; &lt;p&gt;Was the product crap?  Of course I am biased, but I don't think  so.  A group of schools in the remote Pilbara region used Federal  Government grants to fly me out to install the software and train staff.  A  number of schools paid me to address "PD" staff training  sessions.  Two regional radio stations interviewed me on the software and  what it was trying to do.&lt;/p&gt; &lt;p&gt;What went wrong?  Essentially, I ran out of steam.  For one person  to develop, market, and support a product is to much to ask.  &lt;/p&gt; &lt;p&gt;Successful "education" software is mainly produced by games  companies, who have an existing marketing and support infrastructure.  Even  the software is produced mainly by games developers, and the curriculum content  is traditionally minimal.&lt;/p&gt; &lt;p&gt;Latterly, some software has begun to appear on the web, with a slightly  higher quality content.  &lt;a href="http://www.mathletics.com.au/"&gt;Mathletics&lt;/a&gt;  is one.  My daughters use it at school, and for a while they were keen to  use it for &lt;i&gt;homework&lt;/i&gt;.  But their interest waned after a few  weeks.  Now they use my software at home just as often, perhaps to please  me.&lt;/p&gt; &lt;p&gt;The bottom line is that designing software, which covers the curriculum,  records progress, and is sufficiently interesting to captivate the attention of  children for more than a few hours, is a task so enormous, so difficult, and so  expensive, that neither the public nor the private sector has yet attempted to  do it properly.&lt;/p&gt; &lt;p&gt;I freely admit that both my &lt;a href="http://www.interactived.com/screenshots.htm"&gt;CD  software&lt;/a&gt; and my &lt;a href="http://www.interactived.com/jartest.htm"&gt;web-based  software&lt;/a&gt; only scratches at the surface of the primary school math  curriculum.  But I'm not going to sit at home and dedicate the rest of my  life to reinventing the wheel if I can't get people to use what I have done  already.&lt;/p&gt; &lt;p&gt;Selling my &lt;a href="http://www.interactived.com/jartest.htm"&gt;web-based  software&lt;/a&gt; really shouldn't be that hard.  It's free!  But so far,  offering it to just two schools to try out has been like trying to push shit up  hill.&lt;/p&gt; &lt;p&gt;The first was the local school in the country town, where I now live.  I  have lived here, repairing computers, for five years, I have four children, and  I sit on the local Council, so getting an appointment was not a problem.   And the meeting went very well.  I had been told that the new deputy  principals, a husband and wife team, were dead keen on computers, and on their  application in education.  And sure enough, they understood what I was  saying and were enthusiastic about what they saw.  They said they would  address the next staff meeting on the subject and get back to me.&lt;/p&gt; &lt;p&gt;Silence followed.&lt;/p&gt; &lt;p&gt;Many weeks later the same team were invited into a Council function.  A  few days before the function, I put in a phone call to ask what had happened,  but the call was not returned.  At the function itself, where I was in the  role of host, rather than salesman, I sought them out again to ask what had  happened.  Unable to run away, or avoid me, I sensed awkwardness, even  fear.  After much vacillation and skirting around the subject, all I got  out of them was that I would need to talk to the principal.  So far I have  not bothered.  The application is not permanently hosted yet, and it would  be premature to make a fuss.  I called on them, because I had been told  they would be interested.  They were, but some invisible barrier rose up  and prevented further progress.&lt;/p&gt; &lt;p&gt;The second was my daughters' primary school.  Again, as a parent, I had  easy access to an audience with the school principal, and just as with the first  school, she purported to like what she saw.  She even later wrote a polite  note extolling the virtues of the software, but enclosed the CD, which she was  returning to me.  So I tried the guy who emails the school newsletter, and  he passed me to the lady who runs the computers.  I got the CD back to her,  but after a couple of failed attempts to meet (my contact with the girls is  infrequent and erratic), she was also wanting to return the CD, saying the  school had access to "plenty of resources".  I'll remember that  the next time they write to parents asking for money.&lt;/p&gt; &lt;p&gt;Prior to contacting these schools, I had assumed they would be friendly, and  suitable candidates for a pre-release trial of the software, tolerant of  glitches, and willing to try subsequent editions.  They have made it clear  that they are not.  And while ten years have passed since I was last  knocking on doors, and awareness of technology has improved, teachers are as  conservative as ever, entrenched in their daily routine, and deeply suspicious  of anything unfamiliar.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-5515145478928991278?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/5515145478928991278/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=5515145478928991278' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5515145478928991278'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/5515145478928991278'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2009/10/marketing.html' title='Marketing'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-3782502324202246595</id><published>2009-10-18T04:37:00.000-07:00</published><updated>2009-10-18T04:48:11.808-07:00</updated><title type='text'>More on Scoring Rates</title><content type='html'>&lt;p&gt;Following on from my last blog, the table below shows the raw scoring rates on two additional items, H and K.  Item H is twice as hard as item I, and is only addressed by Student B.  Item K is twice as easy as Item J and is only addressed by Student A.  This scenario synthesises one which might be generated by a &lt;a href="http://www.interactived.com/jartest.htm"&gt;computer based adaptive arithmetic test&lt;/a&gt;, which presents more difficult items to more able students and easier items to less able students.&lt;/p&gt; &lt;table width="95%" align="center" border="0" cellspacing="1"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="16%" align="center"&gt;Raw       Rates&lt;/td&gt;     &lt;td width="16%" align="center"&gt;Item H&lt;/td&gt;     &lt;td width="16%" align="center"&gt;Item I&lt;/td&gt;     &lt;td width="17%" align="center"&gt;Item J&lt;/td&gt;     &lt;td width="17%" align="center"&gt;Item K&lt;/td&gt;     &lt;td width="17%" align="center"&gt;Session Mean&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%" align="center"&gt; Student A&lt;/td&gt;     &lt;td width="16%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="16%" align="center"&gt;4&lt;/td&gt;     &lt;td width="17%" align="center"&gt;8&lt;/td&gt;     &lt;td width="17%" align="center"&gt;16&lt;/td&gt;     &lt;td width="17%" align="center"&gt;9.33&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%" align="center"&gt; Student B&lt;/td&gt;     &lt;td width="16%" align="center"&gt;4&lt;/td&gt;     &lt;td width="16%" align="center"&gt;8&lt;/td&gt;     &lt;td width="17%" align="center"&gt;16&lt;/td&gt;     &lt;td width="17%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="17%" align="center"&gt;9.33&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%" align="center"&gt;It Mean&lt;/td&gt;     &lt;td width="16%" align="center"&gt;4&lt;/td&gt;     &lt;td width="16%" align="center"&gt;6&lt;/td&gt;     &lt;td width="17%" align="center"&gt;12&lt;/td&gt;     &lt;td width="17%" align="center"&gt;16&lt;/td&gt;     &lt;td width="17%" align="center"&gt;9.33&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;From the table, the effect of the adaptive component of the &lt;a href="http://www.interactived.com/jartest.htm"&gt;computer based arithmetic test&lt;/a&gt; has been similar to that of a very good handicapper in a horse race.  By presenting more difficult items to the more able student and easier items to the less able student, it has produced a dead heat in the result.  An examiner looking at the raw rates might be misled into thinking that both students had the same ability.  Hence the need to adjust the results to take into account the difficulty of the items presented to each student.&lt;/p&gt; &lt;p&gt;Similarly the adaptive component of &lt;a href="http://www.interactived.com/jartest.htm"&gt;the test&lt;/a&gt; has distorted the item mean scores of those items presented to only one student.  Take Item H.  The item mean scoring rate is shown as 4.  However, had the item been presented to Student A, from the stated assumptions of the example, one might have expected the scoring rate to have been 2 capm, and the item mean scoring rate would then have been 3, not 4.  In the case of Item K, the item mean scoring rate is shown as 16.  From the stated assumptions of the example, had this item been presented to Student B, one might have expected the scoring rate to have been 32 capm, and the item mean scoring rate would then have been 24.  Item H has been made to look relatively easier than it is, because it was only presented to the more able student, and Item K has been made to look relatively harder than it is, because it was only presented to the less able student.&lt;/p&gt;  &lt;p&gt;The scoring rate quotients calculate out as follows:&lt;/p&gt;  &lt;table width="95%" align="center" border="0" cellspacing="1"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="16%" align="center"&gt;Quotients&lt;/td&gt;     &lt;td width="16%" align="center"&gt;Item H&lt;/td&gt;     &lt;td width="16%" align="center"&gt;Item I&lt;/td&gt;     &lt;td width="17%" align="center"&gt;Item J&lt;/td&gt;     &lt;td width="17%" align="center"&gt;Item K&lt;/td&gt;     &lt;td width="17%" align="center"&gt;Session Mean&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%" align="center"&gt; Student A&lt;/td&gt;     &lt;td width="16%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="16%" align="center"&gt;0.43&lt;/td&gt;     &lt;td width="17%" align="center"&gt;0.86&lt;/td&gt;     &lt;td width="17%" align="center"&gt;1.71&lt;/td&gt;     &lt;td width="17%" align="center"&gt;1.00&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%" align="center"&gt; Student B&lt;/td&gt;     &lt;td width="16%" align="center"&gt;0.43&lt;/td&gt;     &lt;td width="16%" align="center"&gt;0.86&lt;/td&gt;     &lt;td width="17%" align="center"&gt;1.71&lt;/td&gt;     &lt;td width="17%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="17%" align="center"&gt;1.00&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%" align="center"&gt;It Mean&lt;/td&gt;     &lt;td width="16%" align="center"&gt;0.43&lt;/td&gt;     &lt;td width="16%" align="center"&gt;0.64&lt;/td&gt;     &lt;td width="17%" align="center"&gt;1.29&lt;/td&gt;     &lt;td width="17%" align="center"&gt;1.71&lt;/td&gt;     &lt;td width="17%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;The session rates can then be adjusted, using the item quotients to calculate the adjusted rate.  I am reversing the order here from my previous blog.  In the previous blog I adjusted the item rates first, but in this example, it is the session rates which most clearly "need" adjusting, and the item rates in fact cannot be adjusted.&lt;/p&gt; &lt;table width="95%" align="center" border="0" cellspacing="1"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="16%" align="center"&gt;Adjusted Rates&lt;/td&gt;     &lt;td width="16%" align="center"&gt;Item H&lt;/td&gt;     &lt;td width="16%" align="center"&gt;Item I&lt;/td&gt;     &lt;td width="17%" align="center"&gt;Item J&lt;/td&gt;     &lt;td width="17%" align="center"&gt;Item K&lt;/td&gt;     &lt;td width="17%" align="center"&gt;Session Mean&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%" align="center"&gt; Student A&lt;/td&gt;     &lt;td width="16%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="16%" align="center"&gt;6.22&lt;/td&gt;     &lt;td width="17%" align="center"&gt;6.22&lt;/td&gt;     &lt;td width="17%" align="center"&gt;9.33&lt;/td&gt;     &lt;td width="17%" align="center"&gt;7.26&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%" align="center"&gt; Student B&lt;/td&gt;     &lt;td width="16%" align="center"&gt;9.33&lt;/td&gt;     &lt;td width="16%" align="center"&gt;12.44&lt;/td&gt;     &lt;td width="17%" align="center"&gt;12.44&lt;/td&gt;     &lt;td width="17%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="17%" align="center"&gt;11.41&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="16%" align="center"&gt;It Mean&lt;/td&gt;     &lt;td width="16%" align="center"&gt;9.33&lt;/td&gt;     &lt;td width="16%" align="center"&gt;9.33&lt;/td&gt;     &lt;td width="17%" align="center"&gt;9.33&lt;/td&gt;     &lt;td width="17%" align="center"&gt;9.33&lt;/td&gt;     &lt;td width="17%" align="center"&gt;9.33&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;The adjusted mean scoring rate for Student B is now higher than that for Student A, but not by a factor of 2.  Just looking at the numbers for this example, it very clear that the data set is "incomplete".  The "missing" data from Student A on item H and from Student B on Item K is distorting the results.  The session quotient method of transforming the data offsets the distortion partially, but not completely.&lt;/p&gt; &lt;p&gt;And in this example, adjusting the item rates, using the session mean quotients, is not very useful, as the session means were identical, and the session mean quotients were all unity.  It follows that iterations would not achieve much, because no matter how many times you divide by one, you move no further forward.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-3782502324202246595?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/3782502324202246595/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=3782502324202246595' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3782502324202246595'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/3782502324202246595'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2009/10/more-on-scoring-rates.html' title='More on Scoring Rates'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-634738878975455799</id><published>2009-10-09T01:38:00.000-07:00</published><updated>2009-10-18T06:30:28.312-07:00</updated><title type='text'>A closer look at scoring rates</title><content type='html'>&lt;p&gt;In my &lt;a href="http://jhippjava.blogspot.com/2009/08/gui-for-thinking.html"&gt;blog of 25 August&lt;/a&gt;, I described some iterative transformations on scoring rate data from a &lt;a href="http://www.interactived.com/software.htm"&gt;computer based arithmetic test&lt;/a&gt;.  I said I would report the results of further iterations, &lt;i&gt;if I liked them&lt;/i&gt;, and from the time that has past it should be obvious to anyone reading this that I didn't. &lt;/p&gt; &lt;p&gt;The transformations were based on what I called the &lt;a href="http://jhippjava.blogspot.com/2009/08/scoring-rate-quotient-srq.html"&gt;scoring rate quotient (SRQ)&lt;/a&gt;.  Essentially I divided the scoring rate for every item in every test session by the mean of all scoring rates for every item in every test session to produce the SRQ for individual session-item combinations and to calculate the mean SRQ for every session and for every item. &lt;/p&gt;  &lt;p&gt;To illustrate, imagine two students, A and B, addressing two items, I and J.  Imagine in this case that Student B scores at twice the rate of Student A and that Item I is twice as difficult as Item J.  The raw scoring rates might look as follows: &lt;/p&gt;  &lt;table width="95%" align="center"&gt;      &lt;tbody&gt;&lt;tr&gt;     &lt;td width="25%" align="center"&gt;Raw       Rates&lt;/td&gt;     &lt;td width="25%" align="center"&gt;Item I&lt;/td&gt;     &lt;td width="25%" align="center"&gt;Item J&lt;/td&gt;     &lt;td width="25%" align="center"&gt;Session Mean&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="25%" align="center"&gt;Student A&lt;/td&gt;     &lt;td width="25%" align="center"&gt;4&lt;/td&gt;     &lt;td width="25%" align="center"&gt;8&lt;/td&gt;     &lt;td width="25%" align="center"&gt;6&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="25%" align="center"&gt;Student B&lt;/td&gt;     &lt;td width="25%" align="center"&gt;8&lt;/td&gt;     &lt;td width="25%" align="center"&gt;16&lt;/td&gt;     &lt;td fmla="=AVERAGE(B3:C3)" width="25%" align="center"&gt;12&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="25%" align="center"&gt;Item Mean&lt;/td&gt;     &lt;td fmla="=AVERAGE(B2:B3)" width="25%" align="center"&gt;6&lt;/td&gt;     &lt;td fmla="=AVERAGE(C2:C3)" width="25%" align="center"&gt;12&lt;/td&gt;     &lt;td fmla="=AVERAGE(D2:D3)" width="25%" align="center"&gt;9&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;The scoring rate quotients would then be as follows: &lt;/p&gt;  &lt;table width="95%" align="center"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="25%" align="center"&gt;Quotients&lt;/td&gt;     &lt;td width="25%" align="center"&gt;Item I&lt;/td&gt;     &lt;td width="25%" align="center"&gt;Item J&lt;/td&gt;     &lt;td width="25%" align="center"&gt;Session Mean&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="25%" align="center"&gt;Student A&lt;/td&gt;     &lt;td width="25%" align="center"&gt;0.44&lt;/td&gt;     &lt;td width="25%" align="center"&gt;0.89&lt;/td&gt;     &lt;td width="25%" align="center"&gt;0.67&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="25%" align="center"&gt;Student B&lt;/td&gt;     &lt;td width="25%" align="center"&gt;0.89&lt;/td&gt;     &lt;td width="25%" align="center"&gt;1.78&lt;/td&gt;     &lt;td fmla="=AVERAGE(B3:C3)" width="25%" align="center"&gt;1.33&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="25%" align="center"&gt;Item Mean&lt;/td&gt;     &lt;td fmla="=AVERAGE(B2:B3)" width="25%" align="center"&gt;0.67&lt;/td&gt;     &lt;td fmla="=AVERAGE(C2:C3)" width="25%" align="center"&gt;1.33&lt;/td&gt;     &lt;td fmla="=AVERAGE(D2:D3)" width="25%" align="center"&gt;1.00&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;The session quotients can then be used to recalculate the item rates. &lt;/p&gt;  &lt;table width="95%" align="center"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="25%" align="center"&gt;Adjusted       Rates&lt;/td&gt;     &lt;td width="25%" align="center"&gt;Item I&lt;/td&gt;     &lt;td width="25%" align="center"&gt;Item J&lt;/td&gt;     &lt;td width="25%" align="center"&gt;Session Mean&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="25%" align="center"&gt;Student A&lt;/td&gt;     &lt;td width="25%" align="center"&gt;6&lt;/td&gt;     &lt;td width="25%" align="center"&gt;12&lt;/td&gt;     &lt;td width="25%" align="center"&gt;9&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="25%" align="center"&gt;Student B&lt;/td&gt;     &lt;td width="25%" align="center"&gt;6&lt;/td&gt;     &lt;td width="25%" align="center"&gt;12&lt;/td&gt;     &lt;td fmla="=AVERAGE(B3:C3)" width="25%" align="center"&gt;9&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="25%" align="center"&gt;Item Mean&lt;/td&gt;     &lt;td fmla="=AVERAGE(B2:B3)" width="25%" align="center"&gt;6&lt;/td&gt;     &lt;td fmla="=AVERAGE(C2:C3)" width="25%" align="center"&gt;12&lt;/td&gt;     &lt;td fmla="=AVERAGE(D2:D3)" width="25%" align="center"&gt;9&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Or the item quotients can then be used to recalculate the session rates. &lt;/p&gt;  &lt;table width="95%" align="center"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="25%" align="center"&gt;Adjusted       Rates&lt;/td&gt;     &lt;td width="25%" align="center"&gt;Item I&lt;/td&gt;     &lt;td width="25%" align="center"&gt;Item J&lt;/td&gt;     &lt;td width="25%" align="center"&gt;Session Mean&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="25%" align="center"&gt;Student A&lt;/td&gt;     &lt;td width="25%" align="center"&gt;6&lt;/td&gt;     &lt;td width="25%" align="center"&gt;6&lt;/td&gt;     &lt;td width="25%" align="center"&gt;6&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="25%" align="center"&gt;Student B&lt;/td&gt;     &lt;td width="25%" align="center"&gt;12&lt;/td&gt;     &lt;td width="25%" align="center"&gt;12&lt;/td&gt;     &lt;td fmla="=AVERAGE(B3:C3)" width="25%" align="center"&gt;12&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="25%" align="center"&gt;Item Mean&lt;/td&gt;     &lt;td fmla="=AVERAGE(B2:B3)" width="25%" align="center"&gt;9&lt;/td&gt;     &lt;td fmla="=AVERAGE(C2:C3)" width="25%" align="center"&gt;9&lt;/td&gt;     &lt;td fmla="=AVERAGE(D2:D3)" width="25%" align="center"&gt;9&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Expressing this algebraically, the means are calculated as follows: &lt;/p&gt;  &lt;table width="95%" align="center" border="0" cellspacing="1"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Session Mean A&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; (R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA&lt;/sub&gt;)/2&lt;/td&gt;     &lt;td width="10%" align="right"&gt;(1)&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Session Mean B&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; (R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt; + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/2&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Item Mean I&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; (R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;IB&lt;/sub&gt;)/2&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Item Mean J&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; (R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;A&lt;/sub&gt; + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/2&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;table width="95%" align="center" border="0" cellspacing="1"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Grand Mean A&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; (R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/4&lt;/td&gt;     &lt;td width="10%" align="right"&gt;(2)&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;The scoring rate quotients are then calculated by dividing the raw scoring rates by the grand mean: &lt;/p&gt;  &lt;table width="95%" align="center" border="0" cellspacing="1"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;SRQ IA&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 4R&lt;sub&gt;IA&lt;/sub&gt;/(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;(3)&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;SRQ IB&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 4R&lt;sub&gt;IB&lt;/sub&gt;/(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;SRQ JA&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 4R&lt;sub&gt;JA&lt;/sub&gt;/(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;SRQ JB&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 4R&lt;sub&gt;JB&lt;/sub&gt;/(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;The session mean quotients are then: &lt;/p&gt;  &lt;table width="95%" align="center" border="0" cellspacing="1"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Session A Mean Quotient&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 4(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA&lt;/sub&gt;)/2(R&lt;sub&gt;IA&lt;/sub&gt;       + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt; + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;(4)&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 2(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA&lt;/sub&gt;)/(R&lt;sub&gt;IA&lt;/sub&gt;       + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt; + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Session B Mean Quotient&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 2(R&lt;sub&gt;IB&lt;/sub&gt; + R&lt;sub&gt;JB&lt;/sub&gt;)/(R&lt;sub&gt;IA&lt;/sub&gt;       + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt; + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;The item mean quotients are: &lt;/p&gt;  &lt;table width="95%" align="center" border="0" cellspacing="1"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Item I Mean Quotient&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 2(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;IB&lt;/sub&gt;)/(R&lt;sub&gt;IA&lt;/sub&gt;       + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt; + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Item J Mean Quotient&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 2(R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;A&lt;/sub&gt; + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/(R&lt;sub&gt;IA&lt;/sub&gt;       + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt; + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;And the grand mean of the quotients is: &lt;/p&gt;  &lt;table width="95%" align="center" border="0" cellspacing="1"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Grand Mean SRQ&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 4(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/4(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;(5)&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 1&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;The adjusted item rates are calculated by dividing the raw item rates by the session mean quotients. &lt;/p&gt;  &lt;table width="95%" align="center" border="0" cellspacing="1"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Adj Item IA&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; R&lt;sub&gt;IA&lt;/sub&gt;(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/2(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;(6)&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Adj Item JA&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; R&lt;sub&gt;JA&lt;/sub&gt;(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/2(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Adj Item IB&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; R&lt;sub&gt;IB&lt;/sub&gt;(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/2(R&lt;sub&gt;IB&lt;/sub&gt; + R&lt;sub&gt;JB&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Adj Item IB&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; R&lt;sub&gt;IB&lt;/sub&gt;(R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;JA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + R&lt;sub&gt;J&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/2(R&lt;sub&gt;IB&lt;/sub&gt; + R&lt;sub&gt;JB&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;now we have stipulated that item I is twice as hard as item J so: &lt;/p&gt;  &lt;table width="95%" align="center" border="0" cellspacing="1"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;R&lt;sub&gt;JA&lt;/sub&gt;&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 2R&lt;sub&gt;IA&lt;/sub&gt;&lt;/td&gt;     &lt;td width="10%" align="right"&gt;(7)&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;and&lt;/td&gt;     &lt;td width="25%" align="right"&gt;R&lt;sub&gt;JB&lt;/sub&gt;&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; 2R&lt;sub&gt;IB&lt;/sub&gt;&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;So we can re-write expression 6 as: &lt;/p&gt;  &lt;table width="95%" align="center" border="0" cellspacing="1"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Adj Item IA&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; R&lt;sub&gt;IA&lt;/sub&gt;(R&lt;sub&gt;IA&lt;/sub&gt; + 2R&lt;sub&gt;IA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + 2R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/2(R&lt;sub&gt;IA&lt;/sub&gt; + 2R&lt;sub&gt;IA&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; R&lt;sub&gt;IA&lt;/sub&gt;(3R&lt;sub&gt;IA&lt;/sub&gt; + 3R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/6R&lt;sub&gt;IA&lt;/sub&gt;&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; (3R&lt;sub&gt;IA&lt;/sub&gt; + 3R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/6&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; (R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/2&lt;/td&gt;     &lt;td width="10%" align="right"&gt;(8)&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Adj Item IB&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; R&lt;sub&gt;IB&lt;/sub&gt;(R&lt;sub&gt;IA&lt;/sub&gt; + 2R&lt;sub&gt;IA + &lt;/sub&gt;R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;       + 2R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/2(R&lt;sub&gt;IB&lt;/sub&gt; + 2R&lt;sub&gt;IB&lt;/sub&gt;)&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; R&lt;sub&gt;IB&lt;/sub&gt;(3R&lt;sub&gt;IA&lt;/sub&gt; + 3R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/6R&lt;sub&gt;IB&lt;/sub&gt;&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="25%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; (R&lt;sub&gt;IA&lt;/sub&gt; + R&lt;sub&gt;I&lt;/sub&gt;&lt;sub&gt;B&lt;/sub&gt;)/2&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td width="10%" align="center"&gt;so&lt;/td&gt;     &lt;td width="25%" align="right"&gt;Adj Item IA&lt;/td&gt;     &lt;td width="10%" align="center"&gt;=&lt;/td&gt;     &lt;td width="45%" align="left"&gt; Adj Item IB&lt;/td&gt;     &lt;td width="10%" align="right"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;Thus the adjusted item rate for item I is identical for both sessions, and also equal to the item mean for item I.  The same is true for item J.&lt;/p&gt; &lt;p&gt;Of course this is the special case envisaged by &lt;a href="http://jhippjava.blogspot.com/2009/08/scoring-rate-quotient-srq.html"&gt;Rasch&lt;/a&gt;, where all items are completed by all students.  It was nice to work through this special case, because, in my mind at least, it indicates that a single pass transformation is sufficient, and that there is no need for multiple iterations.&lt;/p&gt; &lt;p&gt;In my next blog, I shall have a closer look at the more general case where not all items are completed by all students.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-634738878975455799?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/634738878975455799/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=634738878975455799' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/634738878975455799'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/634738878975455799'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2009/10/closer-look-at-scoring-rates.html' title='A closer look at scoring rates'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-1675426761041003978</id><published>2009-10-08T21:16:00.001-07:00</published><updated>2009-10-08T21:16:42.449-07:00</updated><title type='text'>UK Car Hire - caveat emptor</title><content type='html'>&lt;p&gt;The Web is a great boon to travellers.  Where once you had to sit like a prune on a travel agents chair while they fiddled about for hours on a computer, now you can tailor make your own holiday from your own living room.&lt;/p&gt; &lt;p&gt;As well as the vendor sites, there are these web sites, which purport to search for and sort whatever you are looking for.  At the top of the list are what purport to be the best bargains, and the unwary might simply click on these and look no further.&lt;/p&gt; &lt;p&gt;If you type UK car hire into Google, an array of sites like &lt;a href="http://www.carrentals.co.uk/car-hire/unitedkingdom.html"&gt;this one&lt;/a&gt; appear high on the list.  It invites you to enter dates, a pickup location, and a car type, and then runs a search "of up to 40 companies" for you.&lt;/p&gt; &lt;p&gt;A couple of things should be born in mind when interpreting these results.  One is that only 4 companies actually have representation at the airport.  From memory these are Avis, Budget, Europcar, and Hertz.  The others are scattered through West London, take ages to pick you up, and are hellish difficult to find when you need to drop the car off.&lt;/p&gt; &lt;p&gt;Another is that the "search" website quotes a very bare hire  price.  When I ran a search a couple of weeks ago, Thrifty quoted £322 for 9  days, which is approximately £ 36 a day - and very reasonable it  seemed.  They told me in advance that 2 child seats would add £5 a day  each, bringing the rental to £46 a day - still quite reasonable.  What  they did not tell me that collision damage waiver, which used to be about £5  a day, was now an extra £18 a day.  That, and a few other extras,  brought the total price for the nine days to £649, which was more than  double the original quote at nearly £76 a day.  They also offered to  sting me for even more if I wanted automatic transmission.&lt;/p&gt;  &lt;p&gt;So while the "search" websites might be a useful first step to  identify suitable car models, the wary traveller should then go to the four  airport based companies and get detailed quotes including all extras, collision  damage waiver, and automatic transmission, if required.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-1675426761041003978?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/1675426761041003978/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=1675426761041003978' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/1675426761041003978'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/1675426761041003978'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2009/10/uk-car-hire-caveat-emptor.html' title='UK Car Hire - caveat emptor'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-8252915212093603837</id><published>2009-09-20T21:21:00.000-07:00</published><updated>2009-09-20T21:30:34.053-07:00</updated><title type='text'>Acronis True Image Hanging</title><content type='html'>&lt;p&gt;One of my clients uses Acronis True Image Home for their nightly back-up.  I don't know the product well, but I like what I've seen so far - mostly.  It seems pretty thorough.  The backups run like clockwork every night.  And I have successfully recovered a system which caught a nasty virus, such that a reformat was the only cost effective fix.&lt;/p&gt; &lt;p&gt;But the other day, the front end application, the management console, would not start.  It just froze, with a flash screen reporting that it was checking disk D.  Quite why it needs to check Disk D before opening is a mystery, especially because it is not included in the backup and it need never need be read from.  On the machine in question D is the manufacturer's "recovery" sector.  Quite frankly they are a waste of space, and the word recovery is a complete misnomer - "Factory Reset" sector would be more honest and appropriate.  And given that nothing useful is ever written there, it mystifies me that Acronis should hang while trying to read that disk sector.&lt;/p&gt; &lt;p&gt;Be that as it may, it was hanging and I was in a quandary as to what to do.  I tried going away and coming back a few hours later.  It was stress reducing, but it didn't fix the problem.  I tried searching on strings like "Acronis True Image Hanging", but all that told me was that Acronis seems to hang a lot, in a wide range of circumstances, and there doesn't seem to be any consensus on a fix.&lt;/p&gt; &lt;p&gt;So if there is something I would criticise about Acronis it is the heavy reliance on wizards.  Perhaps there is a setting somewhere, which gives an "expert" view, and enables manual editing of tasks, but I certainly haven't found it.&lt;/p&gt; &lt;p&gt;My dilemma was increased by the fact that the nightly backup was working perfectly.  All I wanted to do was change the backup folder, to initiate a new full backup and a new month long string of incremental backups.  I didn't want to fiddle around uninstalling and reinstalling Acronis, because then I'd lose my working scheduled task.  I was quite tempted to run away, and not tell the client that anything was wrong, and let the incremental backups just go on for years and years in the same folder.  But I decided that would be irresponsible.&lt;/p&gt; &lt;p&gt;After much deliberation I decided that there had to be a script somewhere, controlling the scheduled tasks, so I set about looking for it.  I had a look in the "program files" folder, but there was nothing very promising there.  All the dates were way too old.  So I changed the folder settings to show both hidden folders and protected operating system files, and went to hunt for application data in documents and settings (all of this is in XP pro by the way).  I first looked in the user folder, but there was nothing for Acronis there.&lt;/p&gt; &lt;p&gt;Then I remembered the option in the standard Windows install which says "Do you want this program to be available to all users?"  So I checked out All Users\Application Data and sure enough, there was a directory called "scripts".  Bingo!  The file had a very funny name, and I won't print it here in case some malicious bot is probing my blog, but sure enough it opened with notepad, and it was just an ordinary text file with a script in full English.  I hope no one from Acronis reads this and encrypts the next edition, because it made me like the product more.  The path to the backup file was easy to find, and I just had to modify two characters to change it to the new folder for the current month.&lt;/p&gt; &lt;p&gt;To my enormous surprise, the script ran perfectly that night, and left the new full backup in the new folder as I intended.  Next month I'll just go straight into the script and not bother with the GUI.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8882010943472432760-8252915212093603837?l=jhippjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhippjava.blogspot.com/feeds/8252915212093603837/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8882010943472432760&amp;postID=8252915212093603837' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8252915212093603837'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8882010943472432760/posts/default/8252915212093603837'/><link rel='alternate' type='text/html' href='http://jhippjava.blogspot.com/2009/09/acronis-true-image-hanging.html' title='Acronis True Image Hanging'/><author><name>Jonathan</name><uri>http://www.blogger.com/profile/15714263243558911815</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8882010943472432760.post-6328253816574199646</id><published>2009-09-19T00:24:00.001-07:00</published><updated>2009-09-19T00:28:29.061-07:00</updated><title type='text'>Building a financial mini-app</title><content type='html'>&lt;p&gt;Building a mini-app from scratch using only text files and the command line is a bit like building a piece of furniture from IKEA.  I find that after five steps I realise I made a mistake in step 2, and I have to pull everything apart again and start almost from scratch.&lt;/p&gt; &lt;p&gt;When I was creating the financial transaction table, I decided to dodge the  date conversion issue and make the dat
