Use the JDBC ODBC Driver, I found from your previous question that you got an error like "Data Source Name Not Found". The DSN name which you gave "VFPDS" is not created in your control panel.
I will explain you the steps which you need to do for establishing the connection in Windows.
Create a DSN(Data Source Name) through Control Panel. Goto Control Panel->Administrative Tools->Data Sources(ODBC)->User DSN->Add->Microsoft FoxPro VFP Driver(*.dbf)->Click Finsih Button
If you cannot create a DSN then you need to download Visual Fox Pro Driver from MicroSoft Website
Now you need to type a DSN name there and select "Database Type->Free Table Directory". Browse the path to your .dbf file location.
Now use the DSN name in your "DriverManager"
Eg. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:dsnname");
- If this dosen't work then you need to download new ODBC Driver from Microsoft Website.
I'll Post my code to make you understand completely.
package javaapplication2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/**
*
* @author Ajeesh
*/
public class JavaApplication2
{
public static void main(String[] args)
{
Connection con=null;
Statement st=null;
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:testdsn");
st=con.createStatement();
rs=st.executeQuery("SELECT * FROM TESTFOXD");
while(rs.next())
{
System.out.println("Results Field-1: "+rs.getString("FIELD1"));
System.out.println("Results Field-2: "+rs.getString("FIELD2"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Here "TESTFOXD" is my database name and "testdsn" is my Data Source Name.