Loading ...
Sorry, an error occurred while loading the content.

Re: [xml-dbms] just creating Map from database

Expand Messages
  • rpbourret@rpbourret.com
    1) I suspect the table is not found because you have not used the correct case. The functions used by MapFactory_Database quote identifiers, so you must use
    Message 1 of 6 , Jan 29, 2005
    • 0 Attachment
      1) I suspect the table is not found because you have not used the correct case.
      The functions used by MapFactory_Database quote identifiers, so you must use the
      exact case in which they are stored in the database. For example, if your
      database stores table names in all upper case, use the table name UNTERSUCHT. If
      it stores table names in mixed case, use the table name Untersucht. And so on.

      2) The database name in XML-DBMS is not the same as the database name you use in
      MySQL. The database name in XML-DBMS is a logical name used in map documents and
      API calls to distinguish between multiple databases. (This allows XML-DBMS to
      perform heterogenous joins, updates, and inserts.) Since you are using only one
      database, it is easiest to set this to null.

      3) If you just want to create a map from your database, use the
      org.xmlmiddleware.xmldbms.tools.MapManager tool. It's much easier than calling
      the methods directly. You will need to set the following properties when you
      call MapManager:

      # Usually placed in the db.props file -- see samples subdirectory
      URL=<your database URL>
      Driver=<your JDBC driver class>
      DataSourceClass=org.xmlmiddleware.db.JDBC1DataSource
      User=<user-name>
      Password=<password>

      # Usually placed in the parser.props file -- see samples subdirectory
      ParserUtilsClass=<your parser class>

      Input=Database
      Output1=Map
      Output2=DTD
      MapFile=wollny.map
      DTDFile=wollny.dtd
      RootTable=Untersucht

      For more information, see section 3.3 of the readme.htm document and the
      JavaDocs for MapManager.

      4) If you want to write your own code to do this, I've appended a short program
      that shows two different ways to call createMap. Both worked for me. If you want
      to see more ways in which MapFactory_Database can be used, see
      MapManager.createMapFromDatabase.

      -- Ron

      TEST PROGRAM:
      -------------
      import java.io.*;
      import java.sql.*;
      import org.xmlmiddleware.utils.*;
      import org.xmlmiddleware.xmldbms.maps.*;
      import org.xmlmiddleware.xmldbms.maps.factories.*;
      import org.xmlmiddleware.xmldbms.maps.utils.*;
      import org.w3c.dom.*;

      public class xmldbmstest
      {
      public static void main (String[] argv)
      {
      try
      {
      xmldbmstest x = new xmldbmstest();
      x.run();
      }
      catch(Exception e)
      {
      e.printStackTrace();
      }
      }

      public void run() throws Exception
      {
      Connection conn = getConnection();
      XMLDBMSMap map = createMapFromDatabase(conn);
      writeMap(map, "map.map");
      }

      public Connection getConnection() throws Exception
      {
      String driver = "org.xmlmiddleware.db.jdbc.MSAccessDriver";
      String url =
      "jdbc:xmlmiddleware-access:c:\\rpb\\work\\databases\\test;jdbc:odbc:test";
      String user = "ron";
      String password = "password";
      Class.forName(driver);
      return DriverManager.getConnection(url, user, password);
      }

      public XMLDBMSMap createMapFromDatabase(Connection conn) throws Exception
      {
      MapFactory_Database factory;
      String[] databases, catalogs, schemas, tables;

      factory = new MapFactory_Database(conn);

      databases = new String[1];
      databases[0] = null;
      catalogs = new String[1];
      catalogs[0] = null;
      schemas = new String[1];
      schemas[0] = null;
      tables = new String[1];
      tables[0] = "Untersucht";

      return factory.createMap(databases, catalogs, schemas, tables);
      }

      /*
      public XMLDBMSMap createMapFromDatabase(Connection conn) throws Exception
      {
      MapFactory_Database factory;

      factory = new MapFactory_Database(conn);
      return factory.createMap(null, null, "Untersucht");
      }
      */

      public void writeMap(XMLDBMSMap map, String mapFilename) throws Exception
      {
      Writer writer;
      MapSerializer serializer;

      writer = new FileWriter(mapFilename);
      serializer = new MapSerializer(writer);

      serializer.setPrettyPrinting(true, 3);
      serializer.serialize(map);
      writer.close();
      }
      }

      jan.wollny@... wrote:

      > here it is! by the way, calling createMap() with null-valued arrays causes a
      >
      > java.sql.SQLException: Base table or view not found, message from server:
      "Table 'default.untersucht' doesn't exist"
      >
      > but calling it with String[] db = {"krankenhaus"} causes a
      >
      > java.lang.NullPointerException
      > at
      org.xmlmiddleware.xmldbms.maps.factories.MapFactory_Database.getDatabaseMetaData(MapFactory_Database.java:1174)
      > at
      org.xmlmiddleware.xmldbms.maps.factories.MapFactory_Database.processTable(MapFactory_Database.java:656)
      > at
      org.xmlmiddleware.xmldbms.maps.factories.MapFactory_Database.processTables(MapFactory_Database.java:567)
      > at
      org.xmlmiddleware.xmldbms.maps.factories.MapFactory_Database.createMap(MapFactory_Database.java:417)
      > at XMLDBMSTest.main(XMLDBMSTest.java:73)
    Your message has been successfully submitted and would be delivered to recipients shortly.