Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

How can I write data from SQL to DBF file?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to write data from SQL table to DBF file in Java.
I found a DBF writer http://priede.bf.lu.lv/ftp/pub/DatuBazes/DBF/javadbf/javadbf-tutorial.html.
It is a useful DBF writer but it is not a flexible one. I mean I should declare the DBF fields in DBFFiled array in advance.
I do not know which data will be selected from SQL that I do not know the length and the indexes of the DBFField array in advance.
I tried to solve this to insert the java codes of javadbf in a string into one SQL table e.g:

fields[n] = new DBFField();
fields[n].setName( "TIME_ID");
field[n].setDataType( DBFField.FIELD_TYPE_C);
field[n].setFieldLength(20);

and the object rowData[] are in strings e.g:
rowData[n] = result.getDate("Time");

when I select the data from SQL these strings are also selected and put them into one String determined the strings with comma e.g.

String Fields is:

fields[n] = new DBFField();
fields[n].setName( "TIME_ID");
field[n].setDataType( DBFField.FIELD_TYPE_C);
field[n].setFieldLength(20); ,

fields[n] = new DBFField();
fields[n].setName("RH010");
field[n].setDataType(DBFField.FIELD_TYPE_F);
field[n].setFieldLength(20);

I tried to create an abstract class with strings where I used the DBFFileWriter.
The DBFFileWriter needs arrays. I tried to „create” arrays from strings with the following way:



where Filelds is the string which contains the java codes in strings and the resulted S or getFields(i) is e.g:

fields[n] = new DBFField();
fields[n].setName( "TIME_ID");
field[n].setDataType( DBFField.FIELD_TYPE_C);
field[n].setFieldLength(20);

unfortunately, the string S will not get the integer n value that I receive com.linuxense.javadbf.DBFException: Field 0 is null error.

Can someone suggest me a method to fix this issue or a better DBF writer which can write DBF in Java from data in SQL database?
Thank you for your help in advance!


 
Bartender
Posts: 21757
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DBF is the database file format used by DBase and later by Microsoft FoxPro. Later versions of FoxPro actually did support SQL, incidentally.

The DBF file format defines a single table in the database and contains the meta-data (column names) and data (row values) for that table. Indexes were kept in a separate file.

I think there might actually be a JDBC driver for DBF, but I'm not certain, since to be very intelligent it would have to handle all the SQL itself.

I don't really recommend using DBF unless you need to interface with some very old software (and by old, I mean that the software itself should be upgraded before it breaks entirely - software rots from the OS level down).  For new development, use a real DBMS.
 
Ranch Hand
Posts: 336
7
Tomcat Server Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to look a little broader than FoxPro. The tables use the xBase file format used by Ashton Tate dBase, Foxpro, Visual Foxpro. In 2015 I was still maintaining data in this format that we couldn't move to a true DBMS because the legacy software using the tables was running 10 manufacturing facilities. I was moving data from SQLserver to Foxpro but doing it in the Foxpro language with ODBC drivers.

Once you start looking for xBase utilities you'll find java classes.

Here's a few java class examples:

xBaseJ class

JavaDBF class

There are also JDBC drivers for foxpro such as this.


DB Schema driver

Here are threads in the Microsoft Developer lists about Java app and Foxpro tables, like this one. Posting to that site might help because many people there use Foxpro and SQLserver together. Here is an example conversation.

Java foxpro questions


Hope that helps a little.




 
See where your hand is? Not there. It's next to this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!