KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > sps > pocketpc > util > CEDatabaseExport


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.sps.pocketpc.util;
20
21 import sync4j.syncclient.sps.pocketpc.RapiDB;
22
23 /**
24  * This class exports a Windows CE database into a CSV file. Volume and database
25  * names are passed on the command line.
26  *
27  * @author Stefano Fornari
28  * @version $Id: CEDatabaseExport.java,v 1.2 2005/01/19 11:18:37 fabius Exp $
29  */

30 public class CEDatabaseExport {
31
32
33     /**
34      * Syntax:
35      * sync4j.syncclient.sps.common.util.CEDatabaseExport volume database key_field status_field
36      * @param args the command line arguments
37      */

38     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
39         if (args.length != 4) {
40             syntax(args);
41             System.exit(-1);
42         }
43
44         RapiDB db = new RapiDB(args[0], args[1]);
45         int keyField = 1;
46         int statusField = 2;
47
48         keyField = Integer.parseInt(args[2]);
49         statusField = Integer.parseInt(args[3]);
50
51         if (db.openDB(keyField, statusField, keyField) == false) {
52             System.out.println("Error opening the database!");
53             System.exit(-1);
54         }
55
56         Object JavaDoc[][] data = db.getAllRecords();
57
58         for(int i=0; i<data.length; ++i) {
59             System.out.print(data[i][keyField-1]);
60             for (int j=0; j<data[i].length; ++j) {
61                 System.out.print(" , " + data[i][j]);
62             }
63             System.out.println("");
64         }
65     }
66
67     private static void syntax(String JavaDoc[] args) {
68         System.out.println("Wrong syntax.");
69         System.out.println("Syntax:");
70         System.out.println("sync4j.syncclient.sps.common.util.CEDatabaseExport volume database key_field status_field\n");
71         System.out.println("Provided args:");
72         for (int i=0; i< args.length; ++i) {
73             System.out.println(args[i]);
74         }
75     }
76
77 }
Popular Tags