我想從我的Java應用程序中查詢dbf表。我把這個參考thread使用ODBC從Java讀取Visual Foxpro數據
我使用ODBC數據源管理員創建了一個系統數據源,我將數據源名稱設置爲VFPDS並將數據庫類型設置爲.DBC finaly我將路徑設置爲.dbc文件。
下面是我的Java代碼:
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
// Import custom library containing myRadioListener
import java.sql.DriverManager;
public class testodbc {
public static void main(String args[])
{
try
{
// Load the database driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
// Get a connection to the database
Connection conn = DriverManager.getConnection("jdbc:odbc:VFPDS") ;
// Print all warnings
for(SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning())
{
System.out.println("SQL Warning:") ;
System.out.println("State : " + warn.getSQLState() ) ;
System.out.println("Message: " + warn.getMessage() ) ;
System.out.println("Error : " + warn.getErrorCode()) ;
}
// Get a statement from the connection
Statement stmt = conn.createStatement() ;
// Execute the query
ResultSet rs = stmt.executeQuery("SELECT * FROM pmsquoteh") ;//code crashes here
// Loop through the result set
while(rs.next())
System.out.println(rs.getString(1)) ;
// Close the result set, statement and the connection
rs.close() ;
stmt.close() ;
conn.close() ;
}
catch(SQLException se)
{ se.printStackTrace();
System.out.println("SQL Exception:") ;
// Loop through the SQL Exceptions
while(se != null)
{ se.printStackTrace();
System.out.println("State : " + se.getSQLState() ) ;
System.out.println("Message: " + se.getMessage() ) ;
System.out.println("Error : " + se.getErrorCode()) ;
se = se.getNextException() ;
}
}
catch(Exception e)
{
System.out.println(e) ;
}
}
}
我得到這個異常:
java.sql.SQLException: [Microsoft][ODBC Visual FoxPro Driver]Not a table.
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 UsingButtons.main(testodbc.java:38)
SQL Exception:
State : S0002
Message: [Microsoft][ODBC Visual FoxPro Driver]Not a table.
Error : 123
我相信pmsquoteh退出在數據庫中,我的機器是64位機的表。 我在做什麼錯?我將不勝感激具體的答案。
VFP錯誤「不是表」可能意味着很多不同的事情。這可能意味着表格已損壞。這也可能意味着該表已被加密。你有VFP的副本嗎?如果是這樣,你可以在那裏打開桌子嗎?如果是這樣,你知道問題出在你的連接代碼上。如果不是,那就是桌子。 – 2013-05-10 20:48:28
@ TamarE.Granor,我可以打開表並查看它的記錄。所以它不是桌子 – user1912404 2013-05-13 06:27:04