commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arjen van der Weijden <Arjen.van.der.Weij...@rivm.nl>
Subject Re: Please explain DBCP
Date Fri, 22 Apr 2005 12:39:49 GMT
Never mind,

I finally got it working.

cheers,


Arjen





I've been trying hard to get the example files (commons dbcp site) running.

After setting my jar-lib extensions (sax2.jar and the like) and running the
simple example file:

(Jocl.java is like the poolingDriverExample.java)

java
-Djdbc.drivers=com.mysql.jdbc.Driver:org.apache.commons.dbcp.PoolingDriver
Jocl -cp . "jdbc:apache:commons:dbcp:/CON"

I got the following SQLException: "Configuration file not found".

Which is awkward since the CON.jocl file is right there in the classpath.
So I looked at the source-code for dbcp
recompiled it, ran it and what do you know it found the CON.jocl file. But
now another error popped up "org.xml.sax.driver not specified". Now
ran it using:

java
-Djdbc.drivers=com.mysql.jdbc.Driver:org.apache.commons.dbcp.PoolingDriver
-Dorg.xml.sax.driver=org.apache.xerces.parsers.SAXParser  -cp
.:/root/commons-dbcp-1.2.1/src/java/ Jocl "jdbc:apache:commons:dbcp:/CON"

Now a parse error occurs:
org.apache.commons.dbcp.SQLNestedException: Could not parse configuration
file
        at
org.apache.commons.dbcp.PoolingDriver.getConnectionPool(PoolingDriver.java:115)

        at
org.apache.commons.dbcp.PoolingDriver.connect(PoolingDriver.java:171)
        at java.sql.DriverManager.getConnection(DriverManager.java:512)
        at java.sql.DriverManager.getConnection(DriverManager.java:193)
        at Jocl.main(Jocl.java:121)
Caused by: java.lang.NullPointerException
        at
org.apache.commons.jocl.JOCLContentHandler.endElement(JOCLContentHandler.java:508)

        at
org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1315)
        at
org.apache.xerces.framework.XMLParser.callEndElement(XMLParser.java:1950)
        at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1245)

        at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)

        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1208)
        at
org.apache.commons.jocl.JOCLContentHandler.parse(JOCLContentHandler.java:335)

        at
org.apache.commons.jocl.JOCLContentHandler.parse(JOCLContentHandler.java:264)

        at
org.apache.commons.dbcp.PoolingDriver.getConnectionPool(PoolingDriver.java:112)

        ... 4 more


But what to do now to make the thing work?

cheers,

Arjen


Listing of Jocl.java
________________________________________________________________


import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class Jocl {

      static String URL = "jdbc:apache:commons:dbcp:";
      static int LEN = URL.length();


    public static void main(String[] args) {

        Connection conn = null;
        Statement stmt = null;
        ResultSet rset = null;
        try {
            System.out.println("Creating connection.");
            conn = DriverManager.getConnection(args[0]);
            System.out.println("Creating statement.");
            stmt = conn.createStatement();
            String $toDay = "2005-04-06";
            String $query = "SELECT id, userid, event FROM calendar where
recieved like '" +
            $toDay + "%'\n";
            rset = stmt.executeQuery($query);
            System.out.println("Executing statement.");
            rset = stmt.executeQuery($query);
            System.out.println("Results:");
            int numcols = rset.getMetaData().getColumnCount();
            while(rset.next()) {
                for(int i=1;i<=numcols;i++) {
                    System.out.print("\t" + rset.getString(i));
                }
                System.out.println("");
            }
        } catch(SQLException e) {
            e.printStackTrace();
        } finally {
            try { rset.close(); } catch(Exception e) { }
            try { stmt.close(); } catch(Exception e) { }
            try { conn.close(); } catch(Exception e) { }
        }
    }
}

____________________________________________________________________________



The jocl file:
____________________________________________________________________________


<object class="org.apache.commons.dbcp.PoolableConnectionFactory"
xmlns="http://apache.org/xml/xmlns/jakarta/commons/jocl">
   <object class="org.apache.commons.dbcp.DriverManagerConnectionFactory">
      <string value="jdbc:mysql://localhost/itrex"/>
      <string value="root"/>
      <string value="qwerty67"/>
      <!--<object class="java.util.Properties" null="true"/>-->
   </object>
   <object class="org.apache.commons.pool.impl.StackObjectPool"/>
   <object class="org.apache.commons.pool.KeyedObjectPoolFactory"
null="true"/>
   <string null="true"/>
   <boolean value="false"/>
   <boolean value="true"/>
</object>

______________________________________________________________________________________






 DISCLAIMER:  http://www.rivm.nl/disclaimer


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message