搜索和搜索,修改并尝试了所有解决方案,但没有任何作用。
错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'stocktick' in 'field list'
表:
"CREATE TABLE portfolio ("
+ "idNum INT NOT NULL AUTO_INCREMENT,"
+ "stocktick VARCHAR(255),"
+ "stock VARCHAR(255),"
+ "ask DOUBLE(10,2), "
+ "bid DOUBLE(10,2), "
+ "amount INT,"
+ "fundsafter DOUBLE(10,2),"
+ "lastact VARCHAR(255),"
+ "PRIMARY KEY(idNum))";
INSERT查询:
public void stockPurchase(String stockCode, String stockAmount){
spent = amountInt;
funds = funds - spent;
LocalDate date = LocalDate.now();
System.out.println(date.toString());
System.out.println(stockAmount);
System.out.println(stockCode);
System.out.println(words[0]);
try {
//Get a connection to DB:
Connection con = DriverManager.getConnection(dbUrl, name, pw);
prepSt = con.prepareStatement("INSERT INTO portfolio (stocktick, stock, ask, bid, amount, fundsafter, lastact)"
+ " VALUES (?, ?, ?, ?, ?, ?, ?)");
//Set the parameters:
prepSt.setString(1, stockCode);
prepSt.setString(2, words[0]);
prepSt.setDouble(3, Double.parseDouble(words[1]));
prepSt.setDouble(4, Double.parseDouble(words[2]));
prepSt.setInt(5, Integer.parseInt(stockAmount));
prepSt.setDouble(6, funds);
prepSt.setString(7, date.toString());
prepSt.executeUpdate();
System.out.println("Insert Complete");
} catch (SQLException e) {
e.printStackTrace();
}
fundsLabel.setText("Funds: $" + (funds));
userPanel.remove(bpAction);
userPanel.remove(seAction);
}
所谓的方法:
stockPurchase(stock.getText(), amount.getText());
一切正常,直到我进入我的INSERT声明,特别是' stocktick'。即使我向其中输入一个简单的字符串或尝试用引号括起该字符串,它也会产生此错误。哪里哪儿我错了?