i use c3po to connect jdbc(impala),but it failed.Could you give me help:)
ConnectPool.scala
class ConnectPool extends Serializable{
private val cpds: ComboPooledDataSource = new ComboPooledDataSource(true)
private val conf = Utils.getPropmap("env.properties")
try {
cpds.setJdbcUrl(conf("kudu.produce.url"))
cpds.setDriverClass(conf("jdbc.driver"))
cpds.setMaxPoolSize(400)
cpds.setMinPoolSize(20)
cpds.setAcquireIncrement(5)
cpds.setMaxStatements(380)
} catch {
case e: Exception => e.printStackTrace()
}
def getConnection: Connection = {
try {
return cpds.getConnection()
} catch {
case ex: Exception =>
ex.printStackTrace()
null
}
}
}
object ConnectManager {
var kuduManager: ConnectPool = _
def getConnectManager: ConnectPool = {
synchronized {
if (kuduManager == null) {
kuduManager = new ConnectPool
}
}
kuduManager
}
}
messages.foreachRDD(rdd => {
val conn = ConnectManager.getConnectManager.getConnection
val stmt = conn.createStatement
if(!rdd.isEmpty() && rdd.count() >0){
//初始化spark
val spark = SparkSession.builder.config(rdd.sparkContext.getConf).getOrCreate()
try{
// use stmt
}catch {
case e: Exception => print("\ntest\n")
} finally {
stmt.close()
conn.close()}
}
})
18/03/16 16:56:00 INFO c3p0.SQLWarnings: [Simba]ImpalaJDBCDriver Error setting default connection property values: {0} java.sql.SQLWarning: [Simba]ImpalaJDBCDriver Error setting default connection property values: {0} at com.cloudera.jdbc.common.SWarningListener.createSQLWarning(Unknown Source) at com.cloudera.jdbc.common.SWarningListener.postWarning(Unknown Source) at com.cloudera.jdbc.common.SConnection.(Unknown Source) at com.cloudera.jdbc.common4.C4SConnection.(Unknown Source) at com.cloudera.jdbc.jdbc41.S41Connection.(Unknown Source) at com.cloudera.impala.jdbc41.ImpalaJDBC41Connection.(Unknown Source) at com.cloudera.impala.jdbc41.ImpalaJDBC41ObjectFactory.createConnection(Unknown Source) at com.cloudera.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source) at com.cloudera.jdbc.common.AbstractDriver.connect(Unknown Source) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:119) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:143) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:132
The output you are seeing is a warning, not an error. c3p0 resets and prints any warnings that a Connection experiences prior to checking them back into the pool. This surprises developers sometimes, as very few developers bother to check for warnings, and so they often go unnoticed.
I don't know what this warning means, exactly. But JDBC Connection warnings often occur for nonserious conditions. Is your application working properly, besides the warning output?
If you decide you can live with the warnings, you can redirect them or shut them down by configuring the special logger com.mchange.v2.c3p0.SQLWarnings
. Setting the log level of this logger to anything more severe than INFO will prevent the appearance of these messages.