Try including alias in the query.
val query="(select * from "+table+") a"
On Mon, Jul 6, 2015 at 3:38 AM Hafiz Mujadid
wrote:
> Hi!
> I am trying to load data from my sql database using following code
>
> val query="select * from "+table+" "
> val url = "jdbc:mysql://" + dataBaseHost + ":" + dataBasePort + "/" +
> dataBaseName + "?user=" + db_user + "&password=" + db_pass
> val sc = new SparkContext(new
> SparkConf().setAppName("SparkJdbcDs").setMaster("local[*]"))
> val sqlContext = new SQLContext(sc)
> val options = new HashMap[String, String]()
> options.put("driver", "com.mysql.jdbc.Driver")
> options.put("url", url)
> options.put("dbtable", query)
> options.put("numPartitions", "1")
> sqlContext.load("jdbc", options)
>
> And I get following exception
>
> Exception in thread "main"
> com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an
> error
> in your SQL syntax; check the manual that corresponds to your MySQL server
> version for the right syntax to use near 'select * from tempTable WHERE
> 1=0'
>
>
>
> --
> View this message in context:
> http://apache-spark-user-list.1001560.n3.nabble.com/com-mysql-jdbc-exceptions-jdbc4-MySQLSyntaxErrorException-in-spark-with-mysql-database-tp23643.html
> Sent from the Apache Spark User List mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: user-unsubscr...@spark.apache.org
> For additional commands, e-mail: user-h...@spark.apache.org
>
>