Add DbDriver, with support for a few popular JDBC drivers.
[squelch.git] / src / main / java / net / jaekl / squelch / db / DbDriver.java
diff --git a/src/main/java/net/jaekl/squelch/db/DbDriver.java b/src/main/java/net/jaekl/squelch/db/DbDriver.java
new file mode 100644 (file)
index 0000000..5e73885
--- /dev/null
@@ -0,0 +1,20 @@
+package net.jaekl.squelch.db;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+public abstract class DbDriver {
+       // Returns true iff. this DbDriver knows how to connect to the given JDBC URL
+       abstract public boolean handles(String jdbcUrl);
+       
+       // Execute line as a statement of this type
+       abstract String getJdbcDriverClassName();
+       
+       // Open a new Connection to the database.  Note that the caller must close() this at some point.
+       public Connection connect(String jdbcUrl, String userName, String password) throws ClassNotFoundException, SQLException 
+       {
+               Class.forName(getJdbcDriverClassName());
+               return DriverManager.getConnection(jdbcUrl, userName, password);
+       }
+}