2017-02-24 83 views
-1

我有一個spark接受值的sql查詢。如何將變量傳遞給SQL字符串

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

我想這一次是作爲變量像

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

$val1但它不工作嘗試。任何人都可以建議,如何在java中做到這一點?

+2

的可能的複製(HTTP://計算器。 com/questions/9643610/java-including-variables-within-strings) –

回答

0

,我認爲你應該寫查詢作爲

"select * from trafficdata where message_time between '" + val1 + "' and '" + val2 + "'" 
+3

sql injection alert – Reimeus

+0

是的,你應該照顧 – deenbandhu

+0

謝謝..我工作 –

-1

嘗試一下這樣的:[?爪哇 - 包括字符串中的變量]

getQuery = spark.sql(String.format("select * from trafficdata where message_time between %d and %d ", val1, val2)); 
相關問題