-1

I have one spark sql query which is accepting value as long.

Dataset getQuery = spark.sql("select * from trafficdata where message_time between 1486036800000 and 1486108800000 ")

i want this time to be as variables like

Long val1 = 1486036800000
Long val2 = 1486108800000
Dataset getQuery = spark.sql("select * from trafficdata where message_time between $val1 and $val2 ")

i tried with $val1 but its not working. Could anyone suggest, how to do that in java?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
priyanka Dhiman
  • 95
  • 3
  • 11
  • 2
    Possible duplicate of [Java - Including variables within strings?](http://stackoverflow.com/questions/9643610/java-including-variables-within-strings) – OneCricketeer Feb 24 '17 at 12:05

2 Answers2

0

i think you should write the query as

"select * from trafficdata where message_time between '" + val1 + "' and '" + val2 + "'"
deenbandhu
  • 599
  • 5
  • 18
  • 5
    sql injection alert – Reimeus Feb 24 '17 at 11:39
  • SQL Injection: meaning this answer is only good for demonstration or your personal app not accessible over the public web - otherwise code is vulnerable to the most novice hacker. – hB0 May 11 '20 at 08:36
-1

Try it out like this:

getQuery = spark.sql(String.format("select * from trafficdata where message_time between %d and %d ", val1, val2));
FaigB
  • 2,271
  • 1
  • 13
  • 22