Add DbDriver, with support for a few popular JDBC drivers.
[squelch.git] / src / main / java / net / jaekl / squelch / db / DbDriver.java
1 package net.jaekl.squelch.db;
2
3 import java.sql.Connection;
4 import java.sql.DriverManager;
5 import java.sql.SQLException;
6
7 public abstract class DbDriver {
8         // Returns true iff. this DbDriver knows how to connect to the given JDBC URL
9         abstract public boolean handles(String jdbcUrl);
10         
11         // Execute line as a statement of this type
12         abstract String getJdbcDriverClassName();
13         
14         // Open a new Connection to the database.  Note that the caller must close() this at some point.
15         public Connection connect(String jdbcUrl, String userName, String password) throws ClassNotFoundException, SQLException 
16         {
17                 Class.forName(getJdbcDriverClassName());
18                 return DriverManager.getConnection(jdbcUrl, userName, password);
19         }
20 }