niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Berkeley DB
Need help with simple java programs for Berkeley XML DB
Post new topic   Reply to topic Page 1 of 1 [1 Post] View previous topic :: View next topic
Author Message
saalar@gmail.com
*nix forums beginner


Joined: 13 Apr 2005
Posts: 3

PostPosted: Wed Apr 13, 2005 6:41 pm    Post subject: Need help with simple java programs for Berkeley XML DB Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [1 Post] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 3:13 am | All times are GMT
navigation Forum index » Databases » Berkeley DB
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts GIDS 2009 Java:: Save Big, Win Big, Learn Big: Act Before... Shaguf Apache 0 Tue Dec 23, 2008 7:41 am
No new posts question for JAVA developer who r using postgres sql as b... deepak pal PostgreSQL 1 Fri Jul 21, 2006 9:00 am
No new posts ECPG (usage of simple select statement) Jasbinder Bali PostgreSQL 0 Fri Jul 21, 2006 3:28 am
No new posts Is there C/C++ corresponding function in Linux for Java's... xiebopublic@gmail.com apps 4 Fri Jul 21, 2006 3:22 am
No new posts Is there C/C++ corresponding function in Linux for Java's... xiebopublic@gmail.com C++ 1 Fri Jul 21, 2006 2:44 am

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
[ Time: 0.1489s ][ Queries: 16 (0.0746s) ][ GZIP on - Debug on ]