Posts

Showing posts from July, 2011

Microsoft Internet Information Services (IIS)

Image
When I referred to my last post on Microsoft IIS , 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. 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, and for it to have the same Service Pack level as your current OS (and with XP this should be SP3). Once installed you can open IIS via Administrative Tools in the Control Panel (see above). Expand the local computer node and the websites node to find the default web site (which contains the IIS help files - see above). Right click over this and, from the context menu, select New and Virtual Directory (see above). This opens the Virtual directory creation wizard (

Running Code for a GUI Applet

On my first attempt at running the modified Applet from within a web page, I was delighted to observe that it worked. I then noticed the following lines of code: /** * These are implementation variables */ boolean dbDEBUG = false; boolean mathDEBUG = false; boolean LIVE = false; 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 boolean LIVE and boolean dbDEBUG to true, recompiled, and tried again. Again to my delight, the applet opened, and there was even a debug message saying: starting... driver succeeds... However my joy subsided when I clicked the " Click to begin " button, entered an answer clicked "Check Answer" and the debug fie

Creating a MySQL database for a GUI applet

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. 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 something sitting on a website , 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. 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 s

Further Diagnostics with MySQL

I shall now go back to the diagnostic class ( FindbSDiag1 shown below), and bring back some but not all of the commented out code. My first screen dump was very fussy, but it confirmed that the buy queries were running successfully: Buy Query = SELECT * FROM TransRaw where TrType = 'Buy' and StCode = 'ABS' for update try Buy Query Buy Query succeeds fBCumQ= 0.0 fSQ= 2000.0 Buy Query = SELECT * FROM TransRaw where TrType = 'Buy' and StCode = 'TIM' for update try Buy Query Buy Query succeeds fBCumQ= 0.0 fSQ= 7000.0 So I took out the rubbish and was left with a nice neat buy query screen dump, mirroring the one for the sell queries: SELECT * FROM TransRaw where TrType = 'Buy' and StCode = 'ZFX' for update SELECT * FROM TransRaw where TrType = 'Buy' and StCode = 'BIL' for update SELECT * FROM TransRaw where TrType = 'Buy' and StCode = 'QCH' for update SELECT * FROM TransRaw where TrType = 'Buy&

References to the MySQL manual

Image
The MySQL manual can be downloaded from the MySQL Documentation: MySQL Reference Manuals page of the MySQL web site. A wide range of formats and versions are offered. I chose a PDF file for version 5.5. 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: 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. 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: and the dataset should now look like th

Diagnostics with MySQL

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. 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. 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

More ambitious MySQL-JDBC examples

Image
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: 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. 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. 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. The pane above is the pa

More simple MySQL-JDBC examples

In order to consolidate my understanding of JDBC using the MySQL Connector/J driver, I shall convert all of the files from my financial mini-application , for which I described the JDBC-Derby connection in detail here . 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. In the first example I shall add a user to my dbFin database. R.G. Baldwin , 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. The class having been created, the code was as follows: import java.sql.*; public class FindbUAdd { public static void main(

Encoding a local connection to MySQL

The code, which I intend to modify, is described in detail on this page . My first task is to modify the batch file which sets the path to the binaries directories to incorporate the current jdk version: cd My Documents\DDrive\CodeLocal\Fin set path=C:\Program Files\Java\jdk1.6.0_26\bin 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: // Load database driver Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); with // Load database driver Class.forName("com.mysql.jdbc.Driver"); The second modification is to replace: // Make connection String connn = "jdbc:derby:dbFin;create=true"; connect = DriverManager.getConnection( connn ); with // Make connection String url = "jdbc:mysql://localhost:3306/mysql"; connect = DriverManager.getConnection(url,"root", "my password"); The thir

MySQL versus Derby - file locations

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 financial mini-app 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. According to my understanding of MySQL: The server has to running. By default, when you install it starts as a service with Windows. R.G. Baldwin, in 2004 , 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. The JDBC driver, MySQL Connector/J, needs to be installed

MySQL versus Derby - JDBC code

I have mentioned that I am using a developer.com article 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 connection to a Derby database . The article rather neatly summarises the five critical steps in encoding any JDBC connection to a database: Load and register the JDBC driver classes (programming interface) for the database server that you intend to use. Get a Connection object that recodesents a connection to the database server (analogous to logging onto the server). Get one or more Statement objects for use in manipulating the database. Use the Statement objects to manipulate the database. Close the connection to the database. The first section of code from the article runs as follows: public class Jdbc11 { public static void main(String args[]){ System.out.println( "Copyright 2004, R.G.Baldwin"); try { Statement stmt; The approximately corresp

Running MySQL from the command screen

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 developer.com , there is an article entitled " JDBC and MySQL: Installation and Preparation of MySQL ". I could have done with this when I was first learning JDBC . It is very well written - concise, yet thorough. I visited the MySQL download page 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 my own installation instructions . I picked up one ambiguity. I recommended "Custom Installation" from the Server Instance Configuration Wizard. I should have noted for clarity that this wizar