Rob Bamforth's Blog
Java, SQL, MySQL, Networking, SQL Server, PHP, COM, DBA + ODBC

Archive for June, 2009

JAVA – How To Calculate An Age From A Date Of Birth (DOB)

June 15, 2009

The following code illustrates how to derive an age from a given DOB.
This example uses the DOB format YYYY-MM-DD.
This can be altered to any format by changing the substrings taken from the original DOB input.
String dob = “1984-09-20″;
//TAKE SUBSTRINGS OF THE DOB SO SPLIT OUT YEAR, MONTH AND DAY
//INTO SEPERATE VARIABLES
int yearDOB = Integer.parseInt(dob.substring(0, 4));
int [...]

Java – Random Number Generator / How To Generate A Random Number

June 9, 2009

This is a simple method for generating a random number between zero (0) and a given number.
The following code example with generate a random number between 0 and 49.
Although the value of maxNumber is set to 50, Java will start the count at 0.
If you want a number between 0 and 50, set the value [...]

JAVA – Set The Position Of The ScrollBar In JScrollPane()

June 4, 2009

The following codes assumes that you have created a JScrollPane() called scrollPane

int x = 0;
int y = 10;
scrollPane.getViewport().setViewPosition(new java.awt.Point(x, y));

In this example x sets the horizontal position of a horizontal scroll bar.
y sets the vertical position of a vertical scroll bar – in this case the vertical scroll bar will appear 10 pixels down from [...]

How Fast Is A USB Connection?

June 4, 2009

Data transfer speed table

USB 1.0:
> 2 MPPS

USB 2.0 FULL SPEED:
12 MBPS

USB 2.0 HIGH SPEED:
180 MBPS

FIREWIRE-400:
400 MBPS

FIREWIRE-800:
800 MBPS

ENTERNET [10BASE-T]:
10 MBPS

FAST ETHERNET [100BASE-T]:
100 MBPS

GIGABIT ETHERNET [1000BASE-X]:
1000 MBPS

ATA-133:
1064 MBPS

SATA-150:
1200 MBPS

NOTE: these are rough speeds that may be possible.
The typical sustained transfer rate will be lower. Data rate is also dependent on the system architecture, the PCI bus and [...]

SQL / T-SQL CASE SENSITIVE SELECT

June 3, 2009

A very simple method to force case sensitivity in a select statement:

SELECT * FROM DBusers WHERE username = ‘AGENT1′ AND password = ‘paSSworD’ COLLATE SQL_Latin1_General_Cp1_CS_AS

The above statement will only return rows where the password value is exactly paSSworD, case specific.