Hi, everybody!
who could tell me how to write my own application using java and xml-dbms ?I
want a completely example which can describe the develop steps.i hava a
example ,but it have some errors which i can not correct them.the code is
as follow:
import org.xmlmiddleware.db.*;
import org.xmlmiddleware.utils.XMLMiddlewareException;
import org.xmlmiddleware.xmldbms.*;
import org.xmlmiddleware.xmldbms.tools.*;
import org.xmlmiddleware.xmldbms.actions.ActionCompiler;
import org.xmlmiddleware.xmldbms.actions.*;
import org.xmlmiddleware.xmldbms.datahandlers.*;
import org.xmlmiddleware.xmldbms.filters.*;
import org.xmlmiddleware.xmldbms.keygenerators.*;
import org.xmlmiddleware.xmldbms.maps.*;
import org.xmlmiddleware.xmldbms.maps.factories.*;
import org.xmlmiddleware.xmlutils.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import java.io.*;
import java.util.*;
import javax.sql.*;
public class XMLToDBMSAndViceVersa
{
// Service objects
private DOMToDBMS domToDBMS = null;
private DBMSToDOM dbmsToDOM = null;
private DBMSDelete dbmsDelete = null;
// Credentials for connecting to database
private static String JDBC_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
private static String JDBC_URL = "jdbc:odbc:xmldbms";
private static String JDBC_DBNAME = "test";
private static String JDBC_USER = "sa";
private static String JDBC_PASSWORD = "sa";
// Some file names
private static String mapFilename = "Listing-A.map";
private static String actionFilename = "Listing-C.act";
private static String filterFilename = "Listing-D.act";
// Datahandler class
private static String GENERICHANDLER =
"org.xmlmiddleware.xmldbms.datahandlers.GenericHandler";
// Key generation class
private static String KEYGENERATOR =
"org.xmlmiddleware.xmldbms.keygenerators.KeyGenerator";
// Parser utils class; XML-DBMS does not yet support JAXP, so such operations as
XML parsing and serializing
// needs to be a little customized for each parser. this is the class for
supporting Xerces parser.
private static String PARSERUTILSCLASS =
"org.xmlmiddleware.xmlutils.external.ParserUtilsXerces";
private static boolean VALIDATING_PARSER = false;
public static void main(String [] args) {
// Tell the JVM to run finalizers on exit. This is necessary to ensure
// that database connections are properly closed.
System.runFinalizersOnExit(true);
// Creating parser utilities
ParserUtils utils = (ParserUtils)Class.forName(PARSERUTILSCLASS).newInstance();
// Creating a data source and data handler.
DataSource dataSource = new JDBC1DataSource(JDBC_DRIVER, JDBC_URL);
DataHandler dataHandler =
(DataHandler)Class.forName(GENERICHANDLER).newInstance();
dataHandler.initialize(dataSource, JDBC_USER, JDBC_PASSWORD);
// Compiling and instantiating a Map object
MapCompiler compiler1 = new MapCompiler(utils.getXMLReader(VALIDATING_PARSER));
XMLDBMSMap map = compiler1.compile(new InputSource(new
FileReader(mapFilename)));
// Create an object containing information needed to transfer data
TransferInfo transferInfo = new TransferInfo(map);
transferInfo.addDataHandler(JDBC_DBNAME, dataHandler);
// Compiling and instantiating an Action object
ActionCompiler compiler2 = new
ActionCompiler(utils.getXMLReader(VALIDATING_PARSER));
Actions actions = compiler2.compile(map, new InputSource(new
FileReader(actionFilename)));
// Creating and configuring service object
domToDBMS = new DOMToDBMS();
domToDBMS.setCommitMode(DataHandler.COMMIT_AFTERSTATEMENT);
domToDBMS.stopOnException(true);
domToDBMS.setFilterSetReturned(false);
KeyGenerator keyGen = (KeyGenerator)Class.forName(KEYGENERATOR).newInstance();
domToDBMS.addKeyGenerator("UID", keyGen); // Adding used in Listing-A key
generator named UID
// Getting our XML document into DOM document
Document doc = utils.openDocument(new InputSource(new
StringReader(xmlString)),VALIDATING_PARSER);
// Ooops... and our XML file is already in the database!
domToDBMS.storeDocument(transferInfo, doc, actions);
// Creating FilterSet object for retrieving data
FilterCompiler compiler = new FilterCompiler(utils.getXMLReader(validate));
FilterSetfilterSet = compiler.compile(map, new InputSource(new
FileReader(filterFilename)));
// Creating and configuring another service object
dbmsToDOM = new DBMSToDOM(utils);
dbmsToDOM.setDTDInfo(null, null);
Hashtableparams = new Hashtable();
// And now we are getting a DOM document from database
doc = dbmsToDOM.retrieveDocument(transferInfo, filterSet, params, null);
}
}
---------------------------------
ÑÅ»¢ÓÊÏ䣬ÖÕÉú»ï°é£¡
[Non-text portions of this message have been removed]