Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to access dbase(dbf) files in java?

 
Scott Matthews
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to java (less than 6 months).
I have existing data in the dbaseIII format (.dbf). I would like to access this using java. This/these dbf file resides on my local PC. I do not need to go to a "server" to get the data.
Can someone be kind enough to describe the steps needed and possibly some lines of code to get me on my way. An example to use in reference is the following:
a. One database "C:\TestData\Names.dbf"
b. Fields are FirstName & LastName
I would like to write a java program that would open the
database and display the 5 records in the database to the screen.
FYI: I have tried to do this myself. I have been to the Sun On-line tutorial and also read some examples in books, but always they are going to a server in their examples. The SQL part seems straight forward, but the connection part has me scratching my head.
Thanks for your time and help.
Signed: "Spinning my wheels"
 
Daniel Dunleavy
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried to set up an odbc data source and then use the odbc driver?
If you are using an M$ machine, check in your odbc data sources under the drivers tab to see if one of them supports .dbf, and try one of them. Even the foxpro one might work, although it will not be able to use the indexes (i don't think).
Dan
 
Scott Matthews
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I set up an odbc data source as you described above?
I am using Windows98. I see under the Control Panel where there is an ODBC32 Data Sources Icon. I double click on this and get the following tabs: "User DSN", "System DSN", and "File DSN". What do I need to do from there? DBF files are supported here, but I am lost as to what to do?
Could you give me more specific instructions and then show in source code as to how this comes into play?
Again, I have tried to experiment myself and am not getting anywhere. I was hoping someone that had done this before could enlighten me on the "cookbook" approach they used.
Thanks for your time.
 
Daniel Dunleavy
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should be a drivers tab too which would show you if you have a .dbf driver on your machine which may handle it.
But you can just do and ADD in the user dsn tab.
next you make up a name for your dsn and provide a description.
Select the version of dbase and choose the directory your files are in. I believe when you do your select/etc, it will pick the file name + .dbf for the table name in your sql.
HTH
Dan
 
fengzixuan zheng
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody tell the way to connect to a database without creating a 32bit ODBC source .
Please mail me fengzixuan@21cn.com
Thank U!
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fengzixuan zheng:
Can somebody tell the way to connect to a database without creating a 32bit ODBC source .
Please mail me fengzixuan@21cn.com
Thank U!

buy/download a third party jdbc driver. Follow their documentation to connect.
OR
use the search functionality of this forum:
this was the first match on my search http://www.javaranch.com/ubb/Forum3/HTML/000908.html
Jamie
[This message has been edited by Jamie Robertson (edited September 04, 2001).]
 
fengzixuan zheng
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank U, Jamie Robertson.
I find the solution!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic