|
|
|
|
|
|
| Author |
Message |
saalar@gmail.com *nix forums beginner
Joined: 13 Apr 2005
Posts: 3
|
Posted: Wed Apr 13, 2005 6:41 pm Post subject:
Need help with simple java programs for Berkeley XML DB
|
|
|
Dear list,
I am just starting to work with Berkely XML database. I am very
impressed with this database. I would like to write two simple programs
that are very similar to the ones explained in the manual.
One program is meant to add a XML file to the database. And one program
to run xpath-2 queries against this XML file in the database.
So, below you can see the code for adding the file to the XML database.
But somehow nothing is happening. I dont even get any errors or
something. Also please take a look at the code for running the queries
against the database. Any help and suggestion is welcome. Thanks alot.
Saalar Saadatmand
*** This is for adding a file ***
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Properties;
import javax.xml.transform.OutputKeys;
import java.lang.Thread;
import com.sleepycat.dbxml.XmlContainer;
import com.sleepycat.dbxml.XmlException;
import com.sleepycat.dbxml.XmlInputStream;
import com.sleepycat.dbxml.XmlManager;
import com.sleepycat.dbxml.XmlUpdateContext;
public class dbxmlAdd
{
public static void main(String args[]) throws Throwable
{
// if there are not enough arguments stop the program and output error
to stderror
if(args.length < 2)
{
System.out.println("\n Use dbxmlAdd like this: java dbxmlAdd
collection path naming ");
System.out.println("\n Here is an example: java dbxmlAdd
dbxmlContainer /path/../../sources/0.001/benchmark.xml
benchmark_0.001.xml ");
System.out.println("\n The provided name for the document to add MUST
be unique \n");
Thread.sleep(3000);
System.exit(1);
}
XmlManager myManager0 = null;
XmlContainer myContainer0 = null;
String containerName0 = args[0];
String docString0 = args[1];
String docName0 = args[2];
try {
myManager0 = new XmlManager();
myContainer0 = myManager0.openContainer(containerName0);
XmlUpdateContext theContext0 = myManager0.createUpdateContext();
XmlInputStream theStream0 =
myManager0.createLocalFileInputStream(docName0);
myContainer0.putDocument(docName0,theStream0,theContext0,0);
}
catch (Exception e) {}
finally {
try
{
if (myContainer0 != null)
{
myContainer0.close();
}
if (myManager0 != null)
{
myManager0.close();
}
}
catch (Exception ce) {}
}
}
}
*** This is for running a query ***
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Properties;
import javax.xml.transform.OutputKeys;
import java.lang.Thread;
import com.sleepycat.dbxml.XmlContainer;
import com.sleepycat.dbxml.XmlException;
import com.sleepycat.dbxml.XmlInputStream;
import com.sleepycat.dbxml.XmlManager;
import com.sleepycat.dbxml.XmlUpdateContext;
import com.sleepycat.dbxml.XmlQueryContext;
import com.sleepycat.dbxml.XmlResults;
import com.sleepycat.dbxml.XmlDocumentConfig;
import com.sleepycat.dbxml.*;
public class dbxmlRun
{
public static void main(String args[]) throws Throwable
{
// if there are not enough arguments stop the program and output error
to stderror
if(args.length < 2)
{
System.out.println("\n Use dbxmlRun like this: java dbxmlRun
correct_container_name filename query ");
System.out.println("\n Here is an example: java dbxmlRun
dbxmlContainer benchmark_0.001.xml '//item/*' ");
Thread.sleep(3000);
System.exit(1);
}
XmlManager myManager0 = null;
XmlContainer myContainer0 = null;
String containerName0 = args[0];
String docName0 = args[1];
String query0 = args[2];
try {
myManager0 = new XmlManager();
myContainer0 = myManager0.openContainer(containerName0);
XmlUpdateContext theContext0 =
myManager0.createUpdateContext();
XmlQueryContext queryContext0 = myManager0.createQueryContext();
queryContext0.setReturnType(XmlQueryContext.DeadValues);
XmlDocumentConfig docConfig0 = new XmlDocumentConfig();
XmlResults results0 =
myManager0.query(query0,queryContext0,docConfig0);
}catch (Exception e) {}
finally {
try
{
if (myContainer0 != null)
{
myContainer0.close();
}
if (myManager0 != null)
{
myManager0.close();
}
}
catch (Exception ce) {}
}
}
} |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Thu Jan 08, 2009 3:13 am | All times are GMT
|
|
Loans | Secured Loans | Debt Help | Xbox Mod Chip | Loans
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|