How might I fix my java databasing error?
I've narrowed down my problem to these lines of code and I know it ha开发者_如何转开发s something to do with the syntax. The error i get is: [Microsoft][ODBC Microsoft Access Driver] Syntax error in field definition the section of code I get the error from is:
try {
System.out.println("Creating StockTrades table...");
stmt.executeUpdate("CREATE TABLE StockTrades (userID TEXT(20) CONSTRAINT FK1_StockTrades REFERENCES "
+ "Users (userID), symbol TEXT(8), CONSTRAINT FK2_StockTrades FOREIGN KEY (symbol) "
+ "REFERENCES Stocks (symbol), numStocks INT, pricePerStock DECIMAL(5, 2), "
+ "stocksPurchased INT, stocksSold INT, totalCashPaid DECIMAL(9, 2), "
+ "totalCashReceived DECIMAL(9, 2))");
} catch(Exception ex) {
System.out.println("Exception creating StockTrades table: " + ex.getMessage());
}
try {
System.out.println("Creating StockTrades table primary key index...");
stmt.executeUpdate("CREATE UNIQUE INDEX PK_StockTrades ON StockTrades (userID, symbol) "
+ "WITH PRIMARY DISALLOW NULL");
} catch(Exception ex) {
System.out.println("Exception creating StockTrades index: " + ex.getMessage());
}
Solution: To save people from reading through all the comments, this issue was solved by switching from a Decimal field type to the Currency type. The underlying issue was never identified or solved for those who can't switch away from the decimal type.
If I were to guess, I'd say it's this line:
symbol TEXT(8), CONSTRAINT FK2_StockTrades FOREIGN KEY
It seems you have an extra comma between text(8) and the constraint.
Edit: I had posted this just before the other poster then voted to delete. After researching it, you can do it either way, with or without the comma. However, you have it done both ways in consecutive lines. Perhaps that's the issue?
CREATE TABLE StockTrades (userID TEXT(20) CONSTRAINT FK1_
^---
missing comma?
精彩评论