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 private boolean m_suppressNulls = false;
11 // Returns true iff. this DbDriver knows how to connect to the given JDBC URL
12 abstract public boolean handles(String jdbcUrl);
14 // Execute line as a statement of this type
15 abstract String getJdbcDriverClassName();
17 // -------------------
18 // Getters and setters
20 public boolean isSuppressNulls() { return m_suppressNulls; }
21 public void setSuppressNulls(boolean value) { m_suppressNulls = value; }
24 // Open a new Connection to the database. Note that the caller must close() this at some point.
25 public Connection connect(String jdbcUrl, String userName, String password) throws ClassNotFoundException, SQLException
27 Class.forName(getJdbcDriverClassName());
28 return DriverManager.getConnection(jdbcUrl, userName, password);
31 // If this database uses case-insensitive collation, then return an upper-cased version of the passed string.
32 // Otherwise (if this database is case-sensitive), return the string unchanged.
33 // Note that the default implementation assumes a case-insensitive DB.
34 public String adjustCase(String input) {
36 return ""; // Convert nulls to empty strings, so that we can safely use .equals() on the result
38 return input.toUpperCase(Locale.CANADA);