Setting up a connection

The SQLConnection class

At the core of the SQuelized library, there is the SQLConnection class. This is the main object representing the connection to an SQL-based database, and you must instantiate at least one to use the SQuelized functionality.
Each SQL flavour uses a different type, or extension, of the SQLConnection class, mainly:

  1. MySQLConnection: used for MySQL databases
  2. SQLiteConnection: used for SQLite databases
  3. PostgreSQLConnection: used for PostgreSQL databases

SQuelized has made a conscious choice of design to remain explicit as to the connection type being used. This is also for pedagogical purposes. Each type of connection needs or accepts different parameters, and the users will need to be familiar with the SQL flavour they are using in order to discern which parameters are needed to make a succesfull connection. For more information on the different parameters needed for a connection, such as how to construct a connection url, we reccommend reading the documentation for the appropriate JDBC driver. Some of the most typical cases are described below.

Usernames and Passwords

Some database types, such as MySQL or PostgreSQL, usually require a username and a password to make a successful connection. While it is possible to specify these in the url, we reccommend to specify them separately through the constructor, so as to avoid url errors due to typos or incorrect ordering of parameters. For example:

Props and the Properties object

SQLConnection constructors that have optional parameters also accept Property objects. These objects can be constructed and customized using key-value pairs to specify different settings for the connection, including username and password settings, as discussed above.
This might be a cleaner and preferred way to specify connection settings, as the Property objects can be reused for different connections.

Using the connection

Once the connection object has been instantiated, we can use this object to access and modify the database through queries, as you will see in the following sections!