0

I'm trying to read data from DB2 table using spark jdbc, but getting the below error.

Exception in thread "main" com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=*;SELECT * FROM select;UNION, DRIVER=4.19.26

Code:

val df = spark.sqlContext.read.format("jdbc")
      .option("driver", "com.ibm.db2.jcc.DB2Driver")
      .option("url", "jdbc:db2://server/database")
      .option("user", "user")
      .option("password", "password")
      .option("dbtable","select * from schema.table limit 10").load()

Any help is appreciated. Thank you.

BHC
  • 77
  • 9
  • [docs](https://spark.apache.org/docs/1.6.1/sql-programming-guide.html) say `dbtable` The JDBC table that should be read. Note that anything that is valid in a FROM clause of a SQL query can be used. For example, instead of a full table you could also use a subquery **in parentheses**. – nfgl Apr 29 '22 at 14:54
  • 1
    Does this answer your question? [How to use SQL query to define table in dbtable?](https://stackoverflow.com/questions/32628717/how-to-use-sql-query-to-define-table-in-dbtable) – nfgl Apr 29 '22 at 15:01

0 Answers0