Dear all,
Can I use java to access Foxpro database?
If yes, how?
Thanks for helps~
Regards
Victoria
Raquel - 23 Jun 2004 04:35 GMT
While I have no idea about Foxpro, a general method is to define your
Foxpro database as an ODBC data source. Once you have done that, load a
JDBC-ODBC driver in the java program (I believe this driver comes
intrinsically packed with JDK) and access that Foxpro database.
Raquel.
Raquel - 23 Jun 2004 05:54 GMT
A sample program for your reference. This connects and retrieves data from
a database "SAMPLE" which has been already defined as a ODBC datasource.
import java.sql.*;
public class jdbc3
{
public static void main(String[] args)
{
String data = "jdbc:odbc:SAMPLE";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn =
DriverManager.getConnection(data,"userid","password");
Statement st = conn.createStatement();
ResultSet rec = st.executeQuery( "SELECT DEPTNO FROM
schema.DEPARTMENT");
while(rec.next())
{
System.out.println(rec.getString("DEPTNO"));
}
st.close();
} catch (Exception e)
{
System.out.println("Error -" + e.toString());
}
}
}
Tobias Besch - 24 Jun 2004 06:32 GMT
The URL of the connection from a JDBC ODBC bridge can contain optional
arguments.
I use for instance the followin URL to connect to a FoxPro table via the
JDBC ODBC bridge:
String url = "jdbc:odbc:VFP;"+
"Deleted=No;"+
"Exclusive=No;"+
"SourceType=DBF;"+
"SourceDB=F:\\dbase\\DATA";
try {
conn = DriverManager.getConnection(url);
A documentation of all parameters can be found on
<http://msdn.microsoft.com/library/en-
us/odbc/htm/vfpodbcsqldriverconnect.asp>
and
<http://msdn.microsoft.com/library/en-
us/odbc/htm/vfpodbcodbcvisualfoxprosetupdialogbox.asp>
Cheers,
Tobias
Roedy Green - 23 Jun 2004 06:10 GMT
>Can I use java to access Foxpro database?
If Foxpro supports ODBC, you can use an ODBC-JDBC bridge.
See http://mindprod.com/jgloss/jdbc.html

Signature
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.