一直使用市面上流行資料庫(Oracle,SqlServer,MySql,Sysbase),但最近公司有跟其他軟體相關需要到FoxPro上面採集資料,不得已就自個兒先調試一個小的簡易橋串連(odbc)方式,加上網路上這方面資料少而且多半是皮毛,在此我就先記錄下這個,學習ing...
java代碼:
- package com.test;
- import java.sql.*;
-
- /**
- *
- * ERIC 開源開發實驗
- * 2008-6-9 - 下午04:44:38
- * @author zxb
- */
- public class TestFoxPro {
- String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
- //String url="jdbc:odbc:driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C://Program Files//Microsoft Visual Studio//Vfp98//";
- String url="jdbc:odbc:driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDB=C://Program Files//Microsoft Visual Studio//Vfp98//BOOKS.DBC";
- String user = "";
- String pwd = "";
- Connection conn;
- Statement stmt;
- ResultSet rs;
-
- public TestFoxPro(){
- try{
- Class.forName(driver);
- }catch(Exception ex){
- ex.printStackTrace();
- }
- }
-
- public void getConn(){
- try{
- conn = DriverManager.getConnection(url,"","");
- stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
- }catch(Exception ex){
- ex.printStackTrace();
- }
- }
-
- public void close(){
- try{
- if(stmt!=null){
- stmt.close();
- }
- if(conn!=null){
- conn.close();
- }
- }catch(Exception ex){
- ex.printStackTrace();
- }
- }
-
- public ResultSet executeQuery(String sql){
- try{
- if(stmt==null){
- getConn();
- }
- rs = stmt.executeQuery(sql);
- }catch(Exception ex){
- ex.printStackTrace();
- }
- return rs;
- }
-
- public static void main(String[] args){
- TestFoxPro ta=new TestFoxPro();
- String sql="select * from books where date_purchased>={^2008-05-23} ORDER BY book_ID";
- ResultSet rs=ta.executeQuery(sql);
- try{
- while(rs.next()){
- System.out.println(rs.getString(1)+"====="+rs.getString(2)+"==="+rs.getString("date_purchased"));
- }
- rs.close();
- ta.close();
- }catch(Exception ex){
- ex.printStackTrace();
- }
- }
- }
使用FoxPro6.0內建的預設資料庫表, 使用日期比較查詢...
http://xiaobo.javaeye.com/blog/243687