If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > Create FoxPro table via ODBC/JDBC

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-06-07, 11:08
noclueu2 noclueu2 is offline
Registered User
 
Join Date: Jan 2007
Posts: 7
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) {}
		}

	}

}
Reply With Quote
  #2 (permalink)  
Old 03-06-07, 11:25
noclueu2 noclueu2 is offline
Registered User
 
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.
Reply With Quote
  #3 (permalink)  
Old 02-08-12, 15:51
RickPoleshuck RickPoleshuck is offline
Registered User
 
Join Date: Feb 2012
Posts: 1
Better fix

create table c:\directory\table_name ( columns... ) works for me.
Reply With Quote
  #4 (permalink)  
Old 04-01-12, 08:09
qmatteuws qmatteuws is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On