On Fri, 12 Dec 2003 19:27:27 -0800 (PST), David Graham <[EMAIL PROTECTED]> wrote:

This is by design. Some databases store names in all lowercase, others in
all uppercase. MapHandler uses a special Map implementation that stores
all keys as lowercase strings and performs case insensitive lookups to
allow your code to be portable between database implementations.

This definitely makes sense.


--
John Zoetebier
Web site: http://www.transparent.co.nz


David


--- John Zoetebier <[EMAIL PROTECTED]> wrote:
I made a small test program for DbUtils to checkout MapHandler.
As it turns out the field names in the map are changed to lowercase.
Maybe this is intentional as it simplifies handling the returned map.
Can anybody shed some lich ton this ?

The test program is:
==>
package test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.MapHandler;

import util.Constants;

import db.DatabaseConnectionPool;

/**
  * @author johnz
  *
  */
public class TestDbUtils {

        private DatabaseConnectionPool databaseConnectionPool = new
DatabaseConnectionPool();
        /**
         *
         */
        public TestDbUtils() {
                super();
                // TODO Auto-generated constructor stub
        }
        
        public void go() {
                
                Connection conn = null;
                try {
                        conn = DriverManager.getConnection(Constants.JDBC_URL);
                } catch (SQLException se) {
                        System.out.println(se.getMessage());
                        return;
                }
                
                QueryRunner runner = new QueryRunner();
                ResultSetHandler rsh = new MapHandler();
                String sql = "select * from Client where (ClientID=1)";
                Map clientMap = null;
                try {
                        clientMap = (Map) runner.query(conn, sql, null, rsh);
                } catch (SQLException se) {
                        System.out.println(se.getMessage());
                        return;
                }
                
                Set fieldSet = clientMap.keySet();
                Iterator iterator = fieldSet.iterator();
                String fieldName = null;
                
                while (iterator.hasNext()) {
                        fieldName = (String) iterator.next();
                        System.out.println("Field name = " + fieldName);
                        System.out.println("Field value = " + 
clientMap.get(fieldName));
                }
                
        }
        

        public static void main(String[] args) {
                new TestDbUtils().go();
        }
}
==>

DataBaseConnectionPool is a wraper class for DBCP and can be left out.
In that case replace the connection URL to something valid for your
database server.
Some of the test putput:
==>
Field name = comments
Field value = This is a test
Comment
More text
Even more text.
Field name = referrer
Field value = null
==>

--
John Zoetebier
Web site: http://www.transparent.co.nz

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to