commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arjen van der Weijden <>
Subject dbcp, jocl and mysql
Date Wed, 20 Apr 2005 14:32:44 GMT
I've been trying hard to get the example files (commons dbcp site) running.

After setting my jar-lib extensions and running the simple example file:

( is like the

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
compiled it using:

-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 the error SAXParseException occurs: "The reference to entity "password"
must end with the ";" delimiter." Which make perfect sense as the CON.jocl
file has the line "jdbc:mysql......user=mysql@password=secret" So the
parser trips over the non-encoded &.

But what to do now to make the thing work?



Listing of

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);
            int numcols = rset.getMetaData().getColumnCount();
            while( {
                for(int i=1;i<=numcols;i++) {
                    System.out.print("\t" + rset.getString(i));
        } catch(SQLException e) {
        } finally {
            try { rset.close(); } catch(Exception e) { }
            try { stmt.close(); } catch(Exception e) { }
            try { conn.close(); } catch(Exception e) { }



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message