1 package net.jaekl.squelch.db;
3 import java.sql.Connection;
4 import java.sql.DriverManager;
5 import java.sql.SQLException;
6 import java.util.Locale;
8 public abstract class DbDriver {
9 // Returns true iff. this DbDriver knows how to connect to the given JDBC URL
10 abstract public boolean handles(String jdbcUrl);
12 // Execute line as a statement of this type
13 abstract String getJdbcDriverClassName();
15 // Open a new Connection to the database. Note that the caller must close() this at some point.
16 public Connection connect(String jdbcUrl, String userName, String password) throws ClassNotFoundException, SQLException
18 Class.forName(getJdbcDriverClassName());
19 return DriverManager.getConnection(jdbcUrl, userName, password);
22 // If this database uses case-insensitive collation, then return an upper-cased version of the passed string.
23 // Otherwise (if this database is case-sensitive), return the string unchanged.
24 // Note that the default implementation assumes a case-insensitive DB.
25 public String adjustCase(String input) {
27 return ""; // Convert nulls to empty strings, so that we can safely use .equals() on the result
29 return input.toUpperCase(Locale.CANADA);