2013-05-04 70 views
0

嘿,我正在做我的第一個phonegap應用程序,並且我在sqlite db中遇到了一個問題db 其中,我有代碼在數據庫中創建表並從中讀取,但我需要插入數據庫,而不是靜態值的變量值,這裏是我的代碼中插入:在sqlite中使用變量插入數據db

tx.executeSql('INSERT INTO bus_stations (station_name,station_description,station_lat,station_long) VALUES ("6th October","", + "111" + ,"31.963522")'); 

的作品將但這並不工作,我能做些什麼??!

var x=111; 
tx.executeSql('INSERT INTO bus_stations (station_name,station_description,station_lat,station_long) VALUES ("6th October","", x ,"31.963522")'); 

回答

0

通過將您的INSERT成單qoutes '你實際上一個簡單的字符串或文本里面做一切。你的x inthere也只會變成字母x。我建議你分裂INSERT字符串並添加變量如下:

var x = 111; 
tx.executeSql('INSERT INTO bus_stations station_name,station_description,station_lat,station_long) VALUES ("6th October","",' + x + ',"31.963522")'); 

通知的' + x + '其中,之前,你有x