使用 Apache Derby 创建表时出现 SQLSyntaxErrorException
我的项目中有以下使用 Apache Derby 的代码行:
stmt.executeUpdate("CREATE table "+productName+" (Time FLOAT NOT NULL PRIMARY KEY, AcidNo FLOAT, Viscosity FLOAT, Temperature FLOAT)");
当变量 ProductName 以字母开头(即“RedProduct”)时,一切正常。当productName以数字开头(即“6Green”)时,表已创建,但我收到以下错误:
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "6" at line 1, column 15.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown Source)
有什么想法吗?顺便说一句,将表名放在括号中并没有帮助。谢谢!
I have the following line of code in my project which uses Apache Derby:
stmt.executeUpdate("CREATE table "+productName+" (Time FLOAT NOT NULL PRIMARY KEY, AcidNo FLOAT, Viscosity FLOAT, Temperature FLOAT)");
When the variable productName begins with a letter (ie "RedProduct"), everything works fine. When productName begins with a digit (ie "6Green"), the table is created, but I get the following error:
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "6" at line 1, column 15.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown Source)
Any ideas?? By the way, putting the table name in brackets did not help. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过在奇怪的名称周围加上双引号?
Have you tried putting double quotes around the weird names?