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

(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
compiled 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 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?

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) { }
        }
    }
}


____________________________________________________________________________

 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


Mime
View raw message