Print

Print


Eric -

Sounds like you might need to set the CLASSPATH environment variable to include the com.sleepycat.dbxml.* libraries.  That would be either a directory of class files or a .jar file.  Make sure that the sleepycat stuff is in your classpath then try compiling it again with:

   javac tool.java

-Peter

-----Original Message-----
From: Eric Lease Morgan <[log in to unmask]>
Sent: Jul 5, 2004 12:16 PM
To: [log in to unmask]
Subject: [CODE4LIB] compiling a BerkeleyDBXML  Java program

Can y'all help me compile a BerkeleyDBXML Java program?

I have compiled and installed BerkeleyDB (version 4.2) and
BerkeleyDBXML (version 1.2) on my Linux host with the Java (version
1.4.2-rc1), I think. I know nothing about Java. I found a simple Java
program that should allow me to to add, update, delete, get, and query
XML files using the BerkeleyDBXML libraries (see
http://www.linux-mag.com/2004-02/berkeley_01.html), below:

   import java.io.*;
   import com.sleepycat.dbxml.*;

   public class Tool {
        XmlContainer db = null;
        public static void main(String[] args) throws
          Exception {
          String database = args[0];
          String action = args[1];
          String param = args[2];
          Database db = new Database(database);
          if (action.equalsIgnoreCase("add")) {
                int id = db.insertDocument(readFile(param));
                System.out.println("Inserted document " +
                  param +
                  " as id: " + id);
          }
          else if (action.equalsIgnoreCase("delete")) {
                int key = Integer.parseInt(param);
                db.deleteDocument(key);
                System.out.println("Document id " + key +
                  " deleted.");
          }
          else if (action.equalsIgnoreCase("get")) {
                int key = Integer.parseInt(param);
                XmlDocument document = db.getDocument(key);
   System.out.println(document.getContentAsString());
          }
          else if (action.equalsIgnoreCase("update")) {
                int key = Integer.parseInt(param);
                String newContent = readFile(args[3]);
                db.updateDocument(key, newContent);
                System.out.println("Document id " + key +
                  " updated.");
          }
          else if (action.equalsIgnoreCase("query")) {
                String result = db.xpathQueryAsString(param);
                System.out.println(result);
          }
          db.close();
        }
        public static String readFile(String param)
          throws Exception {
          BufferedReader in = new BufferedReader(new
                FileReader(param));
          StringBuffer buffer = new StringBuffer();
          String line;
          while ((line = in.readLine()) != null) {
                buffer.append(line);
          }
          in.close();
          return buffer.toString();
        }
   }

I try to compile this code with the following command:

   javac Tool.java

But it returns the following error:

   Tool.java:11: cannot resolve symbol
   symbol  : class Database
   location: class Tool
          Database db = new Database(database);
          ^
   Tool.java:11: cannot resolve symbol
   symbol  : class Database
   location: class Tool
          Database db = new Database(database);

What do I need to do (with line #11) in order to make a Tool.jar file?
Does the error mean that "Database" is not a valid function call in the
BerkeleyDBXML libraries?

--
Eric "Clueless" Morgan