JdbcRDD rdd = new org.apache.spark.rdd.JdbcRDD(
sparkConf,
()= > {
Class.forName ("com.mysql.jdbc.Driver")
sql.DriverManager.getConnection("jdbc:mysql://mysql.example.com/?user=batman&password=alfred")
},
"SELECT * FROM BOOKS WHERE ? <= KEY AND KEY <= ?",
0, 1000, 10,
row = > row.getString("BOOK_TITLE")
)
I tried above scala code changing classes to java 8,but so many errors coming.
I met the same problem before, it turns out it's the problem of SQL parameters, basically you need to use sql like:
sql
select * from books limit ?, ?
the two parameters for lowerBound
and upperBound
which are required by JdbcRdd constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With