Solved

java and xindice

Posted on 2004-04-14
23
271 Views
Last Modified: 2010-03-31
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();
         }
         }
 
%>
0
Comment
Question by:michaelfriesy
  • 11
  • 8
  • 4
23 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10822653
>>add/delete/amend tables

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

Author Comment

by:michaelfriesy
ID: 10822715

Well yes, this is the administration side of the system.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 50 total points
ID: 10822777
Yes, it just seems a bit strange to be effectively doing the logical equivalent of adding and dropping tables through JSP.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:michaelfriesy
ID: 10822879

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
 
LVL 86

Expert Comment

by:CEHJ
ID: 10822908
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
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 50 total points
ID: 10823191
BTW, I think you should be able to drop a table by shooting a query with the Statement's execute () method.
0
 

Author Comment

by:michaelfriesy
ID: 10823463

>> 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
 

Author Comment

by:michaelfriesy
ID: 10823514

>>

To a collection I should say
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 10823551
0
 

Author Comment

by:michaelfriesy
ID: 10823678
Thanks for that link,
String data = readFileFromDisk(args[0]);


Will a command like this work?
String data = readFileFromDisk(c:\\myproject\\<%newfile.xml%>);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10823781
Not necessarily from the web context, depending on your container security settings. Would be better if the file were below the web root
0
 

Author Comment

by:michaelfriesy
ID: 10825344

>>web root
do you mean somewhere in tomcat?

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10825965
Yes, below your web root in Tomcat
0
 

Author Comment

by:michaelfriesy
ID: 10825980

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
 
LVL 86

Expert Comment

by:CEHJ
ID: 10826071
I'm not sure - i don't know this software. The user manuals seem to be quite informative to me.
0
 

Author Comment

by:michaelfriesy
ID: 10826962

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
 
LVL 30

Expert Comment

by:Mayank S
ID: 10830101
>> 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
 

Author Comment

by:michaelfriesy
ID: 10831491

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
 
LVL 30

Expert Comment

by:Mayank S
ID: 10831723
0
 

Author Comment

by:michaelfriesy
ID: 10834210

That didnt really help me, can I wrap jsp commands around xindice statements like mysql?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10839378
Well, I don't know much about xindice to tell you about that. But I think that it should be possible.
0
 

Author Comment

by:michaelfriesy
ID: 10884749

Thanks for all your help
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10884756
:-)
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 95
expectj telnet failing 5 35
spring jars download 1 26
jsp login check 12 28
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now