编辑:我发现这个错误是由于新的数据文件是 Visual Foxpor dbf 形式而引发的,而我的主文件是 dBaseIII。关于如何以编程方式将 VFP 更改为 dBaseIII 的任何建议?
我正在打开两个 .dbf 文件。一个是主文件,一个是包含新数据的文件。我希望将新数据插入主文件。
我正在连接到保存文件的目录,如下所示:
Connection connection = null;
String dbString = "jdbc:odbc:Driver={Microsoft dBASE Driver (*.dbf)};DBQ=" + dealerSNS + "\\";
try
{
System.out.println("Opening Database Directory " + dealerSNS );
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(dbString, "", "");
System.out.println("Connection established!");
}
catch (ClassNotFoundException cnfEx)
{
System.out.println("* Unable to load driver! *");
System.exit(1);
}
catch (SQLException sqlEx)
{
System.out.println(dbString);
System.out.println("* Cannot connect to database! * SQL = " + sqlEx);
System.exit(1);
}
然后我调用我准备好的声明:
try
{
String update = "INSERT INTO fullSNS SELECT * FROM newSNS";
PreparedStatement ps = connection.prepareStatement(update);
ps.executeUpdate();
System.out.println("query: " + ps+ " worked!");
}
catch (SQLException se)
{
se.printStackTrace();
}
两个 .dbf 具有完全相同的字段并且位于同一个目录中,所以我不确定我做错了什么,它不会将它们链接起来。
有什么建议/想法吗?
我的堆栈跟踪如下所示:
java.sql.SQLException: [Microsoft][ODBC dBase Driver] External table is not in the expected format.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6964)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7121)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3156)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:215)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(JdbcOdbcPreparedStatement.java:137)
at ads.SmooshNMoveFiles.checkNSmoosh(SmooshNMoveFiles.java:116)
at ads.ActiveTimer.reportToWork(ActiveTimer.java:82)
at ads.ActiveTimer.run(ActiveTimer.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)