What is the best opensource dbf driver for java? [closed]
Asked Answered
S

3

20

Can anybody please mention the best available opensource odbc:jdbc driver to read / write dbf.? I have a dbf file which I would like to query (select/update) via a web application (Tomcat app).

Any help/tips would be appreciative.

Thank you.

Stirpiculture answered 9/11, 2011 at 12:20 Comment(2)
Related: #2278023Tillford
github.com/jamel/dbfHavener
S
16
try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String connString="jdbc:odbc:Driver={Microsoft dBASE Driver (*.dbf)};DefaultDir=E:\\db";//DeafultDir indicates the location of the db
            Connection connection=DriverManager.getConnection(connString);
            String sql="SELECT * FROM table_name where condition";// usual sql query
            Statement stmt=connection.createStatement();
            ResultSet resultSet=stmt.executeQuery(sql);
            while(resultSet.next())
            {
                System.out.println();
            }
            System.out.println();
        }
        catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }

It works. And I guess there will be no need to explore for other (open/closed) apis as Java has provided an excellent way to read/write dbf.

Thank you all.

Stirpiculture answered 10/11, 2011 at 13:10 Comment(7)
can you tell how with this driver to disable autocommit? Because using connection.setAutoCommit(false) method throws java.sql.SQLException: [Microsoft][ODBC dBase Driver]Optional feature not implementedBettinabettine
@XCoder Could you say if there were some special configuration steps involved in getting it to run on 64bit machine? I am having a issue here that when I use the driver with Win7 64bit it simply returns the SQLException with the following message: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, when all worked on my old 32bit machine?Bettinabettine
@Bettinabettine DSN setting is different in win64, but it has nothing to do with java code. The DSN that you set up ain't the 64-bit one, this link might help further : support.microsoft.com/kb/942976Leukoderma
@XCoder thanks for the link. It was very helpful. I also found an easier to read explanation over here on SO https://mcmap.net/q/224292/-the-specified-dsn-contains-an-architecture-mismatch-between-the-driver-and-application-java I basically set the User DSN and connect using it rather than the driver directly. Thanks again for the info.Bettinabettine
This didn't work for me. I was trying to acces a Visual FoxPro database. I managed to do it and posted how to do itInstrumentalism
The JDBC ODBC Bridge is now deprecated and will be gone in JDK 8.Erhart
Drawback: this code is limited to Windows and not portable to other platforms. OK for a quick hack, or something that already has Windows dependencies—for other purposes, one of the libraries suggested in the other answers is probably the better choice.Cinderellacindi
C
13

You can try to use https://github.com/iryndin/jdbf - a simple Java library to read/write DBF files. I am the author of this library and it works quite good in my production apps. It is very simple.

Please give it a try.

Cristoforo answered 2/10, 2012 at 13:55 Comment(7)
What is the license policy of your beautiful tool?Propitious
@Andremoniy, license is not specified on the project page, right. I am thinking about either Apache 2.0 license or another license which allows to charge for commercial usage. May be Apache 2.0 license will win.Cristoforo
Thx! Worked for fireBird dbfs.Teddman
Great work! Thank you very much!Bushmaster
hi @iryndin, is there an example on how to write and edit dbf records?Hexone
@Cristoforo is it able to query?Kuehnel
no, it is not able to query.Cristoforo
T
3

dans-dbf is a good option to access dbf files, but it has a custom api (ie: not sql).

I would recommend you to dump the dbf files into db tables (mysql with myisam engine will do the trick or innodb if transaction/consistency checking is required).

Then you can dump back to dbf as needed.

Tinishatinker answered 9/11, 2011 at 14:23 Comment(1)
Depending on the size of the data on hand, I'd favor an in-memory Java database such as hsqldb or h2 and write a little wrapper using dans-dbf.Ludicrous

© 2022 - 2024 — McMap. All rights reserved.