java visual foxpro,使用ODBC从Java读取Visual Foxpro数据

I am trying to query a dbf table from my Java application. I put in reference this thread

I created a system data source using the ODBC Data Source Administrator, I set the data source name to be VFPDS and set the database type to .DBC finaly i set the path to the .dbc file.

the following is my java code:

import javax.swing.* ;

import java.awt.* ;

import java.awt.event.* ;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.SQLWarning;

import java.sql.Statement;

// Import custom library containing myRadioListener

import java.sql.DriverManager;

public class testodbc {

public static void main( String args[] )

{

try

{

// Load the database driver

Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ) ;

// Get a connection to the database

Connection conn = DriverManager.getConnection( "jdbc:odbc:VFPDS" ) ;

// Print all warnings

for( SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning() )

{

System.out.println( "SQL Warning:" ) ;

System.out.println( "State : " + warn.getSQLState() ) ;

System.out.println( "Message: " + warn.getMessage() ) ;

System.out.println( "Error : " + warn.getErrorCode() ) ;

}

// Get a statement from the connection

Statement stmt = conn.createStatement() ;

// Execute the query

ResultSet rs = stmt.executeQuery( "SELECT * FROM pmsquoteh" ) ;//code crashes here

// Loop through the result set

while( rs.next() )

System.out.println( rs.getString(1) ) ;

// Close the result set, statement and the connection

rs.close() ;

stmt.close() ;

conn.close() ;

}

catch( SQLException se )

{ se.printStackTrace();

System.out.println( "SQL Exception:" ) ;

// Loop through the SQL Exceptions

while( se != null )

{ se.printStackTrace();

System.out.println( "State : " + se.getSQLState() ) ;

System.out.println( "Message: " + se.getMessage() ) ;

System.out.println( "Error : " + se.getErrorCode() ) ;

se = se.getNextException() ;

}

}

catch( Exception e )

{

System.out.println( e ) ;

}

}

}

I got this exception :

java.sql.SQLException: [Microsoft][ODBC Visual FoxPro Driver]Not a table.

at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)

at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)

at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)

at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)

at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)

at UsingButtons.main(testodbc.java:38)

SQL Exception:

State : S0002

Message: [Microsoft][ODBC Visual FoxPro Driver]Not a table.

Error : 123

I am sure that the table pmsquoteh exits in the database and my machine is a 64 bit machine.

What am i doing wrong ? I would appreciate specific answers.

解决方案

I used the JDBC driver from here:

Works fine for me. In testing so far (about an hour), it reads MEMO files and seems to have had no issues with either DBC-containted tables or free DBFs.

Not sure how much this driver costs. The client will only probably pay $100 max since VFP is beyond obsolete.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值