Java.next -- Four languages that represent the future of Java
Blogger Stuart Halloway has begun a series of posts on trends that point to the future of the Java platform. In his first post, he compares Clojure, Groovy, JRuby, and Scala -- four wildly different languages that nonetheless all play together in the JRE. Find out what unites these languages and what they can tell us about the future of Java-based development ...

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Access the world's biggest database with Web DataBase Connectivity

Use SQL to query Web-based information

What's your hobby? Mine is amateur investing and the Web helps me a lot. I can log on to one of my favorite financial information sites and look up the latest share prices, or I can log on to a different site to see the news items for the stocks I hold. I have a secret recipe for choosing shares, which I can't tell you, but suppose it's something like: "I will buy shares in a company whose price drops to its 52-week low and has appeared in the news this week." For the first part of that formula, how do I find all companies at their 52-week low? In the past, I viewed the information for each company individually and did a mental calculation. Now I simply type something like this:

SELECT ... AS name, ... AS price, ... AS yearLow
FROM http://www.asharesite.com/lookup
WITHPOST symbol=ALL
WHERE price=yearLow


Besides my hobby, I also have a business -- the Java business. Therefore, I like to stay informed of the latest Java news and views, which I can do at this site, which might be familiar to you (Figure 1):

Figure 1. The JavaWorld homepage. Click on thumbnail to view full-size image (69 KB).

You will see from the picture that today I'm interested in Enterprise Java Beans, so I've typed "ejb" into the search box. The JavaWorld search engine does its job and rewards me with Figure 2:

Figure 2. Search Results for "ejb." Click on thumbnail to view full-size image (68 KB).

The results appear in descending date order and -- although you can't see it in the picture -- the result set contains entries for prior months as well as the current month. Now I want to see the results in ascending date order rather than descending date order but with results prior to December omitted. If I had some software capable of running it, I could express exactly what I want to see with this piece of SQL:

SELECT ... AS linkText, ... AS description, ... AS date
FROM http://search.itworld.com:8765/query.html
WITHGET qt=ejb
WHERE date MATCHES '*Dec*'
ORDER BY date


Figure 3. SQL results. Click on
thumbnail to view full size image (13 KB).

Look at how I've placed the Webpage URL in the FROM clause, in the space where a table name would usually go. You will also notice a new keyword, WITHGET, which I've introduced to trigger a form submission. The result of running this SQL statement would be as shown in Figure 3. I could export the data to another application, a RDBMS or a spreadsheet program. If I issued the query from within a Java program -- using something like JDBC -- I could present the data in my own style, manipulate the data, and combine it with results from other sites. Imagine the possibilities.

That's enough for setting the scene. You should have a fairly good idea of what I'm proposing and why I think it's such a great idea, so now I'll tell you a bit more about this new variation on the SQL theme.

From HTML to SQL

Figure 4. Hierarchy of HTML elements. Click on thumbnail to view full-size image (29 KB).

As designed, SQL works with regular two-dimensional tables with data arranged neatly into rows and columns. Web-based information -- in the form of HTML -- just isn't like that, as you can see from the hierarchy of elements comprising the JavaWorld search page (Figure 4).

Resources