Question

Does anyone know of a free/opensource JDBC driver for fox pro dbf?

because the jdbc-odbc bridge is not working for me ! check my previous question click here

Was it helpful?

Solution

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.

  1. 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

  2. Now you need to type a DSN name there and select "Database Type->Free Table Directory". Browse the path to your .dbf file location.

  3. Now use the DSN name in your "DriverManager"

    Eg.
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:dsnname");
    
  4. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top