gpt4 book ai didi

java - dbf 表插入时出现语法错误

转载 作者:行者123 更新时间:2023-12-01 14:19:38 26 4
gpt4 key购买 nike

我试图使用 jdbc 在 dbf 表上进行插入,但每次执行系统时都会出现此错误:

Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Visual FoxPro Driver]Syntax error.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)
at addProduct.test.main(test.java:29)

这是代码:

public static void main(String[] args) throws ClassNotFoundException, SQLException {
// TODO Auto-generated method stub
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String connString="jdbc:odbc:Driver={Microsoft Visual FoxPro Driver};SourceDB=C:\\RestBar\\DBC;SourceType=DBF";//DeafultDir indicates the location of the db
Connection connection=DriverManager.getConnection(connString);
Statement query = connection.createStatement();

ResultSet result;
String sql="INSERT INTO CUENTAS (NUM_CTA, NUB_CTA, CAJ_CTA, FEC_CTA, HOR_CTA, " +
"OPE_CTA, MES_CTA, NOM_CTA, UBI_CTA, PER_CTA, ACU_CTA, USU_CTA, KDI_CTA) " +
"VALUES('0000001', SELECT DES_MEZ FROM MESAS WHERE COD_MEZ = 'T01', '01', " +
"'2013/07/18', '16:50:33', 0,'002', SELECT DES_MES FROM MESEROS WHERE COD_MES = '002'," +
" 'T01', '2',0.00, 01, 0.00)";
query.execute(sql);


}

最佳答案

如果您想使用子查询,则需要将它们用作 SELECT 的一部分,而不是作为 VALUES 中列出的标量值的一部分。 FoxPro 不允许没有 FROMSELECT

您的简化查询如下(请注意,当您将字符串发送到 VFP 时,您需要删除换行符或插入分号以将字符串换行):

INSERT INTO CUENTAS (
NUM_CTA,
NUB_CTA,
CAJ_CTA, FEC_CTA, HOR_CTA, OPE_CTA, MES_CTA,
NOM_CTA,
UBI_CTA, PER_CTA, ACU_CTA, USU_CTA, KDI_CTA
)
SELECT
'0000001',
DES_MEZ ,
'01', '2013/07/18', '16:50:33', 0,'002',
(SELECT DES_MES FROM MESEROS WHERE COD_MES = '002'),
'T01', '2',0.00, 01, 0.00
FROM MESAS WHERE COD_MEZ = 'T01'

请注意,在编写 INSERT...SELECT 语句时,向 SELECT 添加正确的列名称是有效且良好的做法。

关于java - dbf 表插入时出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17733762/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com