This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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!


 
Saloon Keeper
Posts: 21603
147
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.
 
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!