2015-04-24 98 views
0

嗨,我已經得到,說 E/SQLiteLog SQL錯誤:(1)附近的 「月」:語法錯誤SQLITE錯誤E/SQLiteLog:(1)附近的 「月」:語法錯誤

我相信它可能有一些待辦事項與我的CREATE TABLE語句

private static final String CREATE_TABLE2 = "CREATE TABLE " + TABLE_NAME2 + " (" + UID + 
     " INTEGER PRIMARY KEY AUTOINCREMENT, " + POST_CODE + " VARCHAR(255)," + FIRST_LINE + 
     " VARCHAR(255)," + TOWN + " VARCHAR(255)," + COUNTY + " VARCHAR(255)," + ROOM_NO + 
     " INTEGER ," + ASKING_PRICE + " INTEGER ," + CURRENT_OFFER + " INTEGER ," + AGREED_PRICE + 
     " INTEGER ," + AGENT_NAME + " VARCHAR(255)," + AGENT_PHO_NUM + " VARCHAR(255)," + ESTATE_AGENT_NAME + 
     " VARCHAR(255), " + REFURB_COST + " VARCHAR(255), " + TIME_OF_APPOINTMENT + " VARCHAR(255), " 
     + DONE_UP_VALUE + " INTEGER ," +WEEKLY_ROOM_RATE+ " INTEGER ," +EXPECTED_RENT + " INTEGER ," + MAX_OFFER + " INTEGER ," 
     + DISCOUNT_PERCENT + " DECIMAL(3,2) ," + LOAN_TO_VALUE + " DECIMAL(3,2) ,"+ MORTGAGE_Interest + "DECIMAL(3,2) ," + 
     MAX_MORTGAGE + " INTEGER ," + DESPOSIT_NEEDED + " INTEGER ," + DESPOSIT_REPAYMENT_MONTHLY+ " INTEGER ," + REPAYMENT_ANNAUL + " INTEGER ," 
     +STAMP_DUTY_PER + " DECIMAL(3,2) ," + STAMP_DUTY_ACT + " INTEGER ," +INSURENCES+ " INTEGER ," + TOTAL_PURCHASE_COSTS + 
     " INTEGER ," + TOTAL_MONEY_NEEDED + " INTEGER ," + MORTGAGE_REPAYMENT + " INTEGER ," + 
     BILLS_UTILS + " INTEGER ," + TOTAL_COST_PER_MONTH + " INTEGER ," + TOTAL_REFURB_COST + " INTEGER ," + TOTAL_PROJECT_COST + 
     " INTEGER ,"+ TOTAL_PROFIT + " INTEGER ,"+ RENTAL_PROFIT + " INTEGER);"; 

這是我添加到我的數據庫

public long insertData2(String posCode, String firstLine, String town, String county, int roomNum, 
         int askingPrice, int currentOffer, int agreedPrice, String agentName, 
         String agentPhone, String estateAgentNam, int refurb, String Time, int doneUp,int expectedRent 
         , int weeklyRent, int maxOffer,double discountPercent, double LoanToValue,Double mortgageInterest 
         , int maxMOrtgage , int despositNeeded, int despositRepayment, int despositRepaymentAnnual, double stampDutyPer, 
         int stampDutyAct , int insurances, int totalPurchaseCost,int moneyNeeded, int mortgageRepayments,int billsUtils, 
         int costPerMonth, int refurbCost , int projectCost, int totalProfit, int rentProfit) { 

    ContentValues contentValues = new ContentValues(); 
    contentValues.put(POST_CODE, posCode); 
    contentValues.put(FIRST_LINE, firstLine); 
    contentValues.put(TOWN, town); 
    contentValues.put(COUNTY, county); 
    contentValues.put(ROOM_NO, roomNum); 
    contentValues.put(ASKING_PRICE, askingPrice); 
    contentValues.put(CURRENT_OFFER, currentOffer); 
    contentValues.put(AGREED_PRICE, agreedPrice); 
    contentValues.put(AGENT_NAME, agentName); 
    contentValues.put(AGENT_PHO_NUM, agentPhone); 
    contentValues.put(ESTATE_AGENT_NAME, estateAgentNam); 
    contentValues.put(REFURB_COST, refurb); 
    contentValues.put(TIME_OF_APPOINTMENT, Time); 
    contentValues.put(DONE_UP_VALUE,doneUp); 
    contentValues.put(WEEKLY_ROOM_RATE,weeklyRent); 
    contentValues.put(EXPECTED_RENT,expectedRent); 
    contentValues.put(MAX_OFFER,maxOffer); 
    contentValues.put(DISCOUNT_PERCENT,discountPercent); 
    contentValues.put(LOAN_TO_VALUE,LoanToValue); 
    contentValues.put(MORTGAGE_Interest,mortgageInterest); 
    contentValues.put(MAX_MORTGAGE,maxMOrtgage); 
    contentValues.put(DESPOSIT_NEEDED,despositNeeded); 
    contentValues.put(DESPOSIT_REPAYMENT_MONTHLY,despositRepayment); 
    contentValues.put(REPAYMENT_ANNAUL,despositRepaymentAnnual); 
    contentValues.put(STAMP_DUTY_PER,stampDutyPer); 
    contentValues.put(STAMP_DUTY_ACT,stampDutyAct); 
    contentValues.put(INSURENCES,insurances); 
    contentValues.put(TOTAL_PURCHASE_COSTS,totalPurchaseCost); 
    contentValues.put(TOTAL_MONEY_NEEDED,moneyNeeded); 
    contentValues.put(MORTGAGE_REPAYMENT,mortgageRepayments); 
    contentValues.put(BILLS_UTILS,billsUtils); 
    contentValues.put(TOTAL_COST_PER_MONTH,costPerMonth); 
    contentValues.put(TOTAL_REFURB_COST,refurbCost); 
    contentValues.put(TOTAL_PROJECT_COST,projectCost); 
    contentValues.put(TOTAL_PROFIT,totalProfit); 
    contentValues.put(RENTAL_PROFIT,rentProfit); 




    long id = db.insert(TABLE_NAME2, null, contentValues); 
    return id; 


} 

我一直在尋找的教程和檢查在線BU insertData方法我似乎無法看到哪裏出了問題誰能請幫忙?

UPDATE FULL錯誤消息

總翻新成本= 0總的貨幣所需= 1501 Insurences = 1印花稅實際= 0 EstateAgentName =測試租賃利潤= 11按揭利息= 1.0 AgreedPrice = 0 AddressFirstLine =測試抵押的消滅還款= 0印花稅率= 0.0總項目成本= 1503 AskingPrice = 3000每月總成本= 1 max_offer = -24 RefurbCost = 0總利潤= 3565275需要存款= 0 discount_percent = 0.0 doneUpValue = 3566778 county = test PostCode =測試貸款價值= 1.0 NumberOfRooms = 3 bills utils = 1 Town = stevenage timeOfAppointment = 27 AgentName = 27 Max Mortgage = -24還款年度= 0預期租金= 12 AgentPhoneNumber = test

android.database.sqlite .SQLiteException:接近「每月」:語法錯誤(代碼1):,編譯時:INSERT INTO查看(每月還款,CurrentOffer,總採購成本,每週房費,總再造成本,總貨幣需求,保險,實際印花稅, EstateAgentName,租金利潤,抵押貸款利息,AgreedPrice,地址FirstLine,抵押還款,印花稅率,項目總成本,AskingPrice,每月總費用,max_offer,RefurbCost,總利潤,所需的存款,discount_percent,doneUpValue,縣,PostCode,貸款價值,NumberOfRooms,票據utils,鎮,timeOfAppointment,代理名稱,最大按揭,還款年限,預期租金,代理PhoneNumber)VALUES(?,?,?,?,?,?,?,?,?,?,?,?, ...,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,))

+1

顯示CREATE_TABLE2值 –

+0

的字符串@PiotrGolinski嗨對不起我是一個有點新的你是什麼意思? – BeginnerJavaDev

+1

如果在使用val'CREATE_TABLE2'的行添加斷點,您可以看到它的外觀(在調試模式下)。然後粘貼在這裏 –

回答

0

基本上,你沒有正確地構造你的sql,它會在你的長串串聯元素串中發生在「每月」附近。

有這個SQL這麼多的冤屈:

INSERT INTO Viewed(repayment monthly,CurrentOffer,Total Purchase 
costs,weekly room rate,total refurb cost,Total Money Needed, ...) 

您正在使用的列名的空間。

我有兩個技巧可以用來構建更簡單的sql。

  1. 首先使用像Workbench這樣的MySql客戶端,藉助其GUI工具(但確保數據類型與Sqlite兼容),更容易地構建您的表。當查詢即將執行時,您可以看到稍後可以複製粘貼到項目的原始SQL。
  2. 不要像那樣使用字符串連接。使用String.format

    String sql = String.format(
          "CREATE TABLE %s (%s,%s)", 
          TABLE_NAME2, 
          UID + " INTEGER PRIMARY KEY AUTOINCREMENT", 
          POST_CODE + " VARCHAR(255)"); 
    
+0

任何想法如何我可以修復這個我創建了一個SQL表1工作,我試圖複製該進程 – BeginnerJavaDev

+0

這就像在乾草堆找到一根針。問題是你可能錯過了一個「)」或類似的東西在字符串中。不過,我有幾個技巧,你可以找到有用的。我將編輯答案 – inmyth

+0

謝謝,我真的很感謝任何幫助 – BeginnerJavaDev

相關問題