ENV: Apache Spark-1.4.1 with spark-shell
scala> def getConnection(){ | Class.forName("com.mysql.jdbc.Driver").newInstance(); | DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root"); | } scala> def convertRS(rs:ResutlSet){ | (rs.getInt(1),rs.getString(2)) | } scala> val result = new JdbcRDD(sc,getConnection,"SELECT * FROM emp WHERE ? > empid AND empid <= ?",0,20,2,maprow=convertRS) scala> result.collect().toList
No comments:
Post a Comment