diff -r 837370f791ba -r afdd66815ee3 samples/livedb/src/org/apidesign/livedb/impl/LiveDBProcessor.java --- a/samples/livedb/src/org/apidesign/livedb/impl/LiveDBProcessor.java Wed Jul 14 20:56:33 2010 +0200 +++ b/samples/livedb/src/org/apidesign/livedb/impl/LiveDBProcessor.java Thu Jul 15 00:40:37 2010 +0200 @@ -15,7 +15,11 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.Enumeration; +import java.util.Properties; +import java.util.ServiceLoader; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.Processor; import javax.annotation.processing.RoundEnvironment; @@ -46,7 +50,7 @@ try { JavaFileObject src = processingEnv.getFiler().createSourceFile(clsName, pe); Writer w = src.openWriter(); - Connection c = DriverManager.getConnection(db.url(), db.user(), db.password()); + Connection c = getConnection(db.url(), db.user(), db.password()); CallableStatement s = c.prepareCall(db.query()); ResultSet rs = s.executeQuery(); ResultSetMetaData md = rs.getMetaData(); @@ -103,12 +107,19 @@ return true; } - static { - // init drivers - Enumeration en; - en = DriverManager.getDrivers(); - while (en.hasMoreElements()) { - Driver driver = en.nextElement(); + private static Connection getConnection(String url, String user, String password) + throws SQLException { + final ClassLoader cl = LiveDBProcessor.class.getClassLoader(); + for (Driver d : ServiceLoader.load(Driver.class, cl)) { +// System.out.println("looked up: " + d); + if (d.acceptsURL(url)) { + //System.out.println("accepts: " + d); + Properties p = new Properties(); + p.put("user", user); + p.put("password", password); + return d.connect(url, p); + } } + throw new SQLException("No driver found for " + url); } }