O'Reilly logo

Database Programming with JDBC & Java, Second Edition by George Reese

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

An Introduction to SQL

Note

SQL keywords are case-insensitive, meaning that SELECT and select are treated exactly the same. Depending on your database, however, table and column names may or may not be case-insensitive. In addition, the space between words in a SQL statement is unimportant. You can have a newline after each word, several spaces, or just a single space. Throughout this book I use the convention of placing SQL keywords in all capitals and separating single SQL statements across multiple lines for readability.

How do you get the data into the database? And how do you get it out once it is in there? All major databases support a standard query language called Structured Query Language (SQL). SQL is not much like any programming language you might be familiar with. Instead, it is more of a structured English for talking to a database. A SQL query to the album titles from your database would look like this:

SELECT title FROM albums

In fact, much of the simplest database access comes in the form of equally simple SQL statements. Most of what you will do in SQL boils down to four SQL commands: SELECT, INSERT, UPDATE, and DELETE. You can issue SQL statements in several ways. The simplest, quickest way is through a SQL command-line tool. Each database engine comes with its own. Throughout most of this book, however, you will send your SQL as Java strings to JDBC methods.

Note

I should also make a couple of other syntactic notes. First, the single quotation mark (') is used ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required