java and xindice

Hello Experts, im attempting to execute xindice querys through jsp pages, what ive got working so far I have posted. Id just like to know how to add/delete/amend tables in the database with jsp.
Thanking you



<%@ page import="org.xmldb.api.base.*" %>
<%@ page import="org.xmldb.api.modules.*" %>
<%@ page import="org.xmldb.api.*" %>

<%
Collection col = null;

try {
     
         String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
         Class c = Class.forName(driver);

         Database database = (Database) c.newInstance();
         DatabaseManager.registerDatabase(database);

         col = DatabaseManager.getCollection("xmldb:xindice:///db/pebbles");

         String xpath = "///part[@sku='101']";
         XPathQueryService service =
            (XPathQueryService) col.getService("XPathQueryService", "1.0");
         ResourceSet resultSet = service.query(xpath);
         ResourceIterator results = resultSet.getIterator();
         while (results.hasMoreResources()) {
            Resource res = results.nextResource();
         out.print((String) res.getContent());
         }
      }
      catch (XMLDBException e) {
         System.err.println("XML:DB Exception occurred " + e.errorCode);
      }
      finally {
         if (col != null) {
            col.close();
         }
         }
 
%>
michaelfriesyAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
0
 
CEHJCommented:
>>add/delete/amend tables

Isn't that meant to be done as an admin task?
0
 
michaelfriesyAuthor Commented:

Well yes, this is the administration side of the system.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
CEHJConnect With a Mentor Commented:
Yes, it just seems a bit strange to be effectively doing the logical equivalent of adding and dropping tables through JSP.
0
 
michaelfriesyAuthor Commented:

Why is this strange?, my main operations will be adding/removing/listing the element in the xml files, as done in a relational database.

 
0
 
CEHJCommented:
These are two entirely different things. Please clarify:

1. DROP TABLE x
2. DELETE FROM x

Do you want the analog of 1. or 2.?
0
 
Mayank SConnect With a Mentor Associate Director - Product EngineeringCommented:
BTW, I think you should be able to drop a table by shooting a query with the Statement's execute () method.
0
 
michaelfriesyAuthor Commented:

>> These are two entirely different things. Please clarify:

Right, i want to be able to  

1. DELETE FROM x
2. Add to x
3. add new documents to the database

0
 
michaelfriesyAuthor Commented:

>>

To a collection I should say
0
 
michaelfriesyAuthor Commented:
Thanks for that link,
String data = readFileFromDisk(args[0]);


Will a command like this work?
String data = readFileFromDisk(c:\\myproject\\<%newfile.xml%>);
0
 
CEHJCommented:
Not necessarily from the web context, depending on your container security settings. Would be better if the file were below the web root
0
 
michaelfriesyAuthor Commented:

>>web root
do you mean somewhere in tomcat?

0
 
CEHJCommented:
Yes, below your web root in Tomcat
0
 
michaelfriesyAuthor Commented:

Ok, but to add an xmlfile to the table in a collection, do I have to create the file or can I just submit information to the table based on information entered into a form
0
 
CEHJCommented:
I'm not sure - i don't know this software. The user manuals seem to be quite informative to me.
0
 
michaelfriesyAuthor Commented:

Id imagine there is a method, it seems inefficient to have to create an xmlfile before it can be stored. Its like creating the same file twice when it's needed just once.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> Ok, but to add an xmlfile to the table in a collection

I don't understand what you mean. Can you clarify? If you want to read from an existing file, it is already there. If you want to create a file, then create it?
0
 
michaelfriesyAuthor Commented:

I want to add xml records to the xindice database, im unaware of the correct method.

>>Ok, but to add an xmlfile to the table in a collection, do I have to create the file or can I just submit information to the table based on information entered into a form

This is what im unsure of.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
0
 
michaelfriesyAuthor Commented:

That didnt really help me, can I wrap jsp commands around xindice statements like mysql?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Well, I don't know much about xindice to tell you about that. But I think that it should be possible.
0
 
michaelfriesyAuthor Commented:

Thanks for all your help
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.