The actual answer is that it is impossible to return to Oracle using the existing implementation of DataFrame.write.jdbc () in version 1.4.0. But if you do not mind to upgrade to Spark 1.5, there is a slightly hacky way to do this. As described here , there are two problems:
simple - the spark way of checking the existence of a table is incompatible with the oracle
SELECT 1 FROM $table LIMIT 1
which can be easily avoided with the direct save table utility
org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils.saveTable(df, url, table, props)
and complex (you guessed it right) - there is no Oracle data type dialog type available out of the box. Adopted from the decision of the same article:
import org.apache.spark.sql.jdbc.{JdbcDialects, JdbcType, JdbcDialect} import org.apache.spark.sql.types._ val OracleDialect = new JdbcDialect { override def canHandle(url: String): Boolean = url.startsWith("jdbc:oracle") || url.contains("oracle") override def getJDBCType(dt: DataType): Option[JdbcType] = dt match { case StringType => Some(JdbcType("VARCHAR2(255)", java.sql.Types.VARCHAR)) case BooleanType => Some(JdbcType("NUMBER(1)", java.sql.Types.NUMERIC)) case IntegerType => Some(JdbcType("NUMBER(10)", java.sql.Types.NUMERIC)) case LongType => Some(JdbcType("NUMBER(19)", java.sql.Types.NUMERIC)) case DoubleType => Some(JdbcType("NUMBER(19,4)", java.sql.Types.NUMERIC)) case FloatType => Some(JdbcType("NUMBER(19,4)", java.sql.Types.NUMERIC)) case ShortType => Some(JdbcType("NUMBER(5)", java.sql.Types.NUMERIC)) case ByteType => Some(JdbcType("NUMBER(3)", java.sql.Types.NUMERIC)) case BinaryType => Some(JdbcType("BLOB", java.sql.Types.BLOB)) case TimestampType => Some(JdbcType("DATE", java.sql.Types.DATE)) case DateType => Some(JdbcType("DATE", java.sql.Types.DATE))
so finally a working example should look something like this:
val url: String = "jdbc:oracle:thin:@your_domain:1521/dbname" val driver: String = "oracle.jdbc.OracleDriver" val props = new java.util.Properties() props.setProperty("user", "username") props.setProperty("password", "userpassword") org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils.saveTable(dataFrame, url, "table_name", props)