Oct 11

The DBUtil library from Apache provides a set of class for doing a variety of standard database tasks.

eg. To make a query becomes as simple as the following, providing the result set as a List of arrays where each list elements contains a row.


QueryRunner runner = new QueryRunner();
ArrayListHandler handler = new ArrayListHandler();
List<Object[]> result = runner.query(connection,
    "SELECT * FROM MyTable WHERE name=?", handler, "Joe Smith");
DbUtils.close(conn); 

written by objects \\ tags: , , , ,

Mar 27

To use anonymous access for an LDAP search or query set the value of Context.SECURITY_AUTHENTICATION to “none” in the environment used to create the initial context.

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, 
    "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, providerUrl);

// Use 'none' for anonymous access
env.put(Context.SECURITY_AUTHENTICATION, "none");

// Create the initial context
DirContext ctx = new InitialDirContext(env);

written by objects \\ tags: , , ,

Oct 01

You need to build it manually from the ServletRequest.


StringBuilder sb = new StringBuilder("?");
for (Enumeration e = request.getParameterNames(); 
   e.hasMoreElements();)
{
      String param = (String) e.nextElement();
      sb.append(param)
        .append("=")
        .append(request.getParameter(param))
        .append("&");
}
String queryString = sb.toString().
   substring(0, sb.length() - 1); 

written by objects \\ tags: , ,