1717
1818package org .apache .spark .sql .execution .datasources .jdbc
1919
20- import java .sql .{Connection , Date , DriverManager , ResultSet , ResultSetMetaData , SQLException , Timestamp }
20+ import java .sql .{Connection , Date , ResultSet , ResultSetMetaData , SQLException , Timestamp }
2121import java .util .Properties
2222
2323import scala .util .control .NonFatal
@@ -41,7 +41,6 @@ private[sql] case class JDBCPartition(whereClause: String, idx: Int) extends Par
4141 override def index : Int = idx
4242}
4343
44-
4544private [sql] object JDBCRDD extends Logging {
4645
4746 /**
@@ -120,7 +119,7 @@ private[sql] object JDBCRDD extends Logging {
120119 */
121120 def resolveTable (url : String , table : String , properties : Properties ): StructType = {
122121 val dialect = JdbcDialects .get(url)
123- val conn : Connection = getConnector(properties.getProperty( " driver " ), url, properties)()
122+ val conn : Connection = JdbcUtils .createConnectionFactory( url, properties)()
124123 try {
125124 val statement = conn.prepareStatement(s " SELECT * FROM $table WHERE 1=0 " )
126125 try {
@@ -201,36 +200,13 @@ private[sql] object JDBCRDD extends Logging {
201200 case _ => null
202201 }
203202
204- /**
205- * Given a driver string and an url, return a function that loads the
206- * specified driver string then returns a connection to the JDBC url.
207- * getConnector is run on the driver code, while the function it returns
208- * is run on the executor.
209- *
210- * @param driver - The class name of the JDBC driver for the given url, or null if the class name
211- * is not necessary.
212- * @param url - The JDBC url to connect to.
213- *
214- * @return A function that loads the driver and connects to the url.
215- */
216- def getConnector (driver : String , url : String , properties : Properties ): () => Connection = {
217- () => {
218- try {
219- if (driver != null ) DriverRegistry .register(driver)
220- } catch {
221- case e : ClassNotFoundException =>
222- logWarning(s " Couldn't find class $driver" , e)
223- }
224- DriverManager .getConnection(url, properties)
225- }
226- }
203+
227204
228205 /**
229206 * Build and return JDBCRDD from the given information.
230207 *
231208 * @param sc - Your SparkContext.
232209 * @param schema - The Catalyst schema of the underlying database table.
233- * @param driver - The class name of the JDBC driver for the given url.
234210 * @param url - The JDBC url to connect to.
235211 * @param fqTable - The fully-qualified table name (or paren'd SQL query) to use.
236212 * @param requiredColumns - The names of the columns to SELECT.
@@ -243,7 +219,6 @@ private[sql] object JDBCRDD extends Logging {
243219 def scanTable (
244220 sc : SparkContext ,
245221 schema : StructType ,
246- driver : String ,
247222 url : String ,
248223 properties : Properties ,
249224 fqTable : String ,
@@ -254,7 +229,7 @@ private[sql] object JDBCRDD extends Logging {
254229 val quotedColumns = requiredColumns.map(colName => dialect.quoteIdentifier(colName))
255230 new JDBCRDD (
256231 sc,
257- getConnector(driver, url, properties),
232+ JdbcUtils .createConnectionFactory( url, properties),
258233 pruneSchema(schema, requiredColumns),
259234 fqTable,
260235 quotedColumns,
0 commit comments