You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by John Zoetebier <jo...@transparent.co.nz> on 2003/12/13 03:44:08 UTC
[DbUtils] MapHandler changes field names to lowercase
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [DbUtils] MapHandler changes field names to lowercase
Posted by John Zoetebier <jo...@transparent.co.nz>.
On Fri, 12 Dec 2003 19:27:27 -0800 (PST), David Graham
<gr...@yahoo.com> 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 <jo...@transparent.co.nz> 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: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>
>
> __________________________________
> Do you Yahoo!?
> Free Pop-Up Blocker - Get it now
> http://companion.yahoo.com/
>
> ---------------------------------------------------------------------
> 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
Re: [DbUtils] MapHandler changes field names to lowercase
Posted by David Graham <gr...@yahoo.com>.
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.
David
--- John Zoetebier <jo...@transparent.co.nz> 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: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org