A collection of Java test projects and examples

Sigh, so many broken links, so little time ... when I switched this website to Drupal, I didn't (couldn't) take the time to move all of my static content in the Drupal CMS, so a lot of great content is just sitting out there in static files. To help fix that problem a little bit, here's a link to a collection of Java test project (example projects) that demonstrate all sorts of cool and fun things with Java, including:

Java JDBC Postgresql Driver class and URL example

Here's a quick post to help anyone that needs a quick JDBC Driver and URL reference when using Postgresql (Postgres) with Java (and JDBC).

The basic Postgresql JDBC Driver and URL information you need is shown here:

Tomcat connection pool - a Tomcat JNDI DBCP connection pool example

Here's a quick demonstration of how to create a Tomcat connection pool (database connection pool) using the Tomcat DBCP library.

I'm not going to go into a detailed explanation here of how Tomcat DBCP works, other than to say that it works for me, and I've tried to include everything here that you'll need to implement your own Tomcat DBCP database connection pool in your web applications.

Java JDBC connection string examples

Table of Contents1 - JDBC connection string examples2 - MySQL JDBC connection string (JDBC URL)3 - Postgresql JDBC connection string example4 - SQL Server JDBC connection string example5 - DB2 on an As/400 (iSeries)

Java JDBC FAQ: Can you share Java JDBC connection string examples for the most popular relational databases?

Some days we all need something simple, and today I needed the example syntax for a JDBC connection string (the JDBC URL) for MySQL and Postgresql databases. While I was digging through my old examples, I found JDBC connection string examples for other databases, and thought I'd share them all here.

To that end, here are some example Java JDBC connection string examples for various databases, including MySQL, Postgres, SQL Server, and DB2.

Back to top

JDBC connection string examples

Here’s a table showing the syntax for JDBC URLs and drivers that I've used on recent projects.

How to perform a SQL query for fields that are null (or not null)

For some reason I can never remember how to search for database table fields that are either NULL or NOT NULL. I always try to use the = operator or something else.

So, for myself, here’s an example of how to perform a SQL query and find all records where a field in a database table is NULL:


And here’s how to perform a SQL query showing all records in a database table where a column is NOT NULL:

Postgresql error - must be owner of relation

If you get a Postgresql error message like this:

ERROR:  must be owner of relation [your_table_here]

don't worry too much, it probably means what it says: You don't own the table (or relation) you're trying to modify. Well, I guess you can worry if you can't get someone to fix the permissions, but if you can it's no big deal.

Postgresql - How to execute SQL commands from a file

With Postgresql (or Postgres, as I call it) you can execute commands from a file like this:

\i your_file_name_here

I just did that to run a subset of the restore commands from a backup file that I created, and it worked just fine. In my case I put the file in my current working directory, but I'll guess that you can also supply a path to the file and it will work from there as well.