I probably found solution, fieldAdress looks wrong. This counter
begins with 0 but dbf repair program increased this counter by 1 and
this it enough to let openoffice work with the dbf.
On 10/16/06, Jan Gregor <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I'm using classes in in org.geotools.data.shapefile.dbf package to
> convert oracle table into dbf file. Problem is that some applications
> such as openoffice can't read generated dbf file, only dbf headers are
> shown without any rows.
>
> Did I miss something or is it a bug in
> org.geotools.data.shapefile.dbf package that affects shapefile writing
> too ?
>
>
> thanks,
> Jan
>
> There's actual class :
>
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.sql.Connection;
> import java.sql.ResultSet;
> import java.sql.ResultSetMetaData;
> import java.sql.SQLException;
> import java.sql.Statement;
>
> import org.geotools.data.shapefile.dbf.DbaseFileHeader;
> import org.geotools.data.shapefile.dbf.DbaseFileWriter;
>
> public class Oracle2Dbf {
>
> public void transform (String sqlstr, String j2EEDataSource,
> String dbfFileName) {
>
> }
>
> public void transform (String sqlstr, Connection conn, String
> dbfFileName) throws SQLException, IOException {
>
> Statement stmt = null;
> ResultSet rs = null;
> try {
> //conn = ds.getConnection();
> stmt = conn.createStatement();
> stmt.execute(sqlstr);
> rs = stmt.getResultSet();
> ResultSetMetaData mdata = rs.getMetaData();
> DbaseFileHeader header = new DbaseFileHeader();
> for (int col=1; col <= mdata.getColumnCount(); ++col) {
> String colType = mdata.getColumnTypeName(col);
> char type = 'C';
> int length = 0;
> int scale = mdata.getScale(col);
> if (colType.equals("NUMBER")) {
> if (scale==-127) {
> type = 'F';
> length = 20;
> scale = 2;
> } else {
> type = 'N';
> length = 18;
> }
> } else {
> if (colType.equals("VARCHAR2")) {
> type = 'C';
> // length = 254;
> length = mdata.getColumnDisplaySize(col);
> if (length > 254)
> length = 254;
> } else {
> if (colType.equals("DATE")) {
> type = 'D';
> length = 8;
> }
> }
> }
> header.addColumn(mdata.getColumnName(col), type, length,
> scale);
> }
>
> FileOutputStream os = new FileOutputStream(dbfFileName);
> DbaseFileWriter writer = new DbaseFileWriter(header,
> os.getChannel());
>
> Object[] record = new Object[mdata.getColumnCount()];
> while (rs.next()) {
> for (int icol=1; icol <= mdata.getColumnCount(); ++icol) {
> record[icol-1] = rs.getObject(icol);
> }
> writer.write(record);
> record[0]=null;
> record[1]=null;
> record[2]=null;
> record[3]=null;
> }
> writer.close();
>
> } finally {
> try {
> if (rs!=null)
> rs.close();
> if (stmt!=null)
> stmt.close();
> } catch (SQLException e) {
> e.printStackTrace();
> }
> }
> }
> }
>
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users