JDBC

Java Database Connectivity--a way to use SQL-based databases with Java

To use a database from a Java program, you’ll need to do (at least) these things:

  1. Identify a database host that you can connect to
  2. Set up your database tables in that database
  3. Set up your Java code to access that database

Identifying a database host that you can connect to

The easiest way, by far, to get started with using a SQL database is to use one called sqlite3.

The sqlite3 command is available on CSIL machines:

-bash-4.3$ sqlite3
SQLite version 3.11.0 2016-02-15 17:29:24
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> 

Using sqlite3 has certain disadvantages, as you’ll discover.

Pros/cons of sqlite3 vs. other options

The main “pro” of sqlite3 is that it is easy to set up:

Some disadvantages:

From http://talks.php.net/show/sqlite_jan/4:

  • It’s Slow
    • Locks whole file for writing.
    • No caching mechanism of it’s own.
  • Limited
    • Database size restricted to 2GB in most cases.
    • Not fully SQL92 compliant.
    • Not very scalable.

But, for small applications in CMPSC56, it is likely that none of those things will matter.

Here are some links to other discussions of pros/cons of sqlite:

Resources


https://ucsb-cs56-pconrad.github.io/topics/jdbc/