Lecture 9: Using SQL from Java

This is the first of three lectures on integrating domain-specific languages with general-purpose programming languages. In particular, SQL for database queries.

SQL is a domain-specific language for programming queries over relational databases. Queries may be complex, with declarative and imperative components, and are often constructed by other programs rather than by hand.

Standard frameworks for creating these queries build them out of plain strings, taking little account of their rich structure. This can also happen in other settings where a program in one language is used to manipulate code written in another.

The lecture demonstrates this using examples from the SkyServer database, as well as recent Google Buzz and Twitter vulnerabilities. We look at the basics of the JDBC framework for database access in Java, and how prepared strings introduce some structure. There is also some mention of NoSQL architectures, and the general issue of why one might use one language from another.

The next two lectures will look at ways to better integrate such domain-specific languages within general-purpose programming; in ways that can help both the programmer and the compiler.

SQL queries are programs in a rich high-level language; when we treat them as unstructured text we lose all we know about programming.

Link: Slides


Friday’s lecture will be about the LINQ framework on C#. In preparation for that, carry out the following homework.

  1. Find an online tutorial about C#.
  2. Read it.
  3. Post its URL, and your comments on the tutorial, here on the blog.

Coursework office hour

If you have questions or problems you wish to raise regarding the course or your coursework, you can bring them to me on Wednesday afternoon.

Office Hour: 1.30–2.30pm Wednesday 27 October, Informatics Forum 5.04

If the turnstile gates are closed and your student card does not open them, ask at the front desk for admission.

Otherwise, please post any questions here on the blog or by email either to the mailing list apl-students@inf.ed.ac.uk or to me Ian.Stark@ed.ac.uk.

4 Responses to Lecture 9: Using SQL from Java

  1. Ian Stark says:

    That looks good, and focused on learning C# from no programming background at all. Did you find it useful?

    Note that “learn in 24 hours” still makes for a substantial programme: although it always sounds like that means you should be able to learn it in a day. Compare, for example, that there are no more than 20 hours of lectures in this course.

  2. Laurentiu says:

    I found this as being a quick, albeit incomplete intro : http://www.mactech.com/articles/mactech/Vol.20/20.03/PrimeronC/index.html
    and this http://www.csharp-station.com/Tutorial.aspx somewhat longer but I use it to search things that weren’t clear

    • Ian Stark says:

      Yes, I find C# station has quite a lot of useful material that guides you round the various language features.

      Relating to today’s lecture, I’ve just seen that C# station also offers LINQ2Twitter, which lets you write LINQ queries that access twitter (all of it) as the database backend. http://linqtotwitter.codeplex.com/