Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2007
    Posts
    7

    Unanswered: Create FoxPro table via ODBC/JDBC

    Can I create a FoxPro table fro java? The below code does not throw any errors and does not create a table. If I try to insert a row I will get an error saying the table file does not exist.

    Here is my code:

    Code:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    
    public class FoxProOdbc {
    
    	public static void main(String[] args) {
    		Connection conn = null;
    		Statement stmnt = null;
    
    		try {
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    			conn = DriverManager.getConnection("jdbc:odbc:FoxProTest", "", "");
    			stmnt = conn.createStatement();
    
    			String sql = "Create TABLE testtable (testme char(10))";
    			stmnt.executeUpdate(sql);
    			conn.commit();
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			try {if (stmnt != null) stmnt.close();} catch (Exception ignore) {}
    			try {if (conn != null) conn.close();} catch (Exception ignore) {}
    		}
    
    	}
    
    }

  2. #2
    Join Date
    Jan 2007
    Posts
    7
    Here I go answering my own questions. The above code did create the testtable.dbf file just not where I'd expect it. It was generated in the directory from which I started the java application not the specified location set in the ODBC driver. When I configured the ODBC driver I selected a directory and had Database Type "Free Table directory". This will work if I start my JVM in this directory. If I choose "Visual FoxPro database (.DBC)" as the Database type. I can get things to work. It still creates the .dbf files in the wrong location but now it can find them.

    So the 2 options are:

    Run your JVM in the directory where you have the ODBC driver pointed

    Use a .DBC file

    Please let me know if there are other options.

  3. #3
    Join Date
    Feb 2012
    Posts
    1

    Better fix

    create table c:\directory\table_name ( columns... ) works for me.

  4. #4
    Join Date
    Apr 2012
    Posts
    1
    Very interesting post, looked for it all over the web

    Quote Originally Posted by noclueu2 View Post
    Here I go answering my own questions. The above code did create the testtable.dbf file just not where I'd expect it. It was generated in the directory from which I started the java application not the specified location set in the ODBC driver. When I configured the ODBC driver I selected a directory and had Database Type "Free Table directory". This will work if I start my JVM in this directory. If I choose "Visual FoxPro database (.DBC)" as the Database type. I can get things to work. It still creates the .dbf files in the wrong location but now it can find them.

    So the 2 options are:

    Run your JVM in the directory where you have the ODBC driver pointed

    Use a .DBC file

    Please let me know if there are other options.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •