You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Hafiz Mujadid <ha...@gmail.com> on 2015/07/06 09:38:06 UTC

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException in spark with mysql database

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-unsubscribe@spark.apache.org
For additional commands, e-mail: user-help@spark.apache.org


Re: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException in spark with mysql database

Posted by Sathish Kumaran Vairavelu <vs...@gmail.com>.
Try including alias in the query.

val query="(select * from  "+table+") a"

On Mon, Jul 6, 2015 at 3:38 AM Hafiz Mujadid <ha...@gmail.com>
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-unsubscribe@spark.apache.org
> For additional commands, e-mail: user-help@spark.apache.org
>
>