Categories
General

Playing with the James e-mail server

I love e-mail.
E-mail probably loves me back.
Anyhu, James wants to be your e-mail server. I will report more on how it works and how much fun it is (maybe this helps) but you might encounter the following, arcane error:

Error building configuration from file:/C:/Documents and Settings/yzukerman/My D
ocuments/downloads/java/James/james-2.2.0/apps/james/SAR-INF/config.xml.

It appears James really hates having spaces in the directory structure in which it is located.
This examines this is a bug report.

Share
Categories
Java SQL Server

Sending null values as parameters into a SQLServer stored procedure using JDBC

When calling a SQL Server stored procedure using JDBC’s CallableStatement object one uses its setXXX methods to set input parameters. XXX is the name of the type the input parameter is assumed to be of.
SQL Server does not support the setNull() method, throwing this exception:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC] The specified SQL type is not supported by this driver.

One way we went around this unpleasantry was to instead set the null value to be a different type, so instead of
setNull(position, variable)

There is an entry in the SQL Server JDBC newsgroup about this issue.
we create a new null String object and then call:
setString(position, nullString)

Share
Categories
Java

Servlets and submitting form using the POST method with enctype “multipart/form-data”

Uploading files from forms into a servlet appears to be a common sore in J2EE that was left to be addressed by developers. Apache has what appears to be a solid package in their org.apache.commons.fileupload package (get it here).

What is not clear (or if you merely forgot) is that when you use the form encoding (which you basically must when you are uploading a file) multipart/form-data is that the HttpServletRequest object will no longer hold the parameters from the form. You must use the a mechanism I found to be non-intuitive (if for the class names used if not anything else):

DiskFileUpload upload = new DiskFileUpload();
upload.setSizeMax(2000000); //max. file size 2M
List items = upload.parseRequest(portletRequest);
Iterator iter = items.iterator();
while (iter.hasNext()) {
// although it is named a FileItem it is actually a form input
FileItem item = (FileItem)iter.next();
// check whether it is the file being uploaded or a mere form input field
if (!item.isFormField()) {
// this is a file
String fileName = item.getName();
File location = new File(destinationDirectory + "/" + fileName);
item.write(location);
}
else
{
// this is a plain form field
String formFieldName = item.getFieldName();
String formFieldValue = item.getString();

}
}

Awkward.

Share
Share