Saturday, February 27, 2010

Reading data from Internet

This URL seems to be pretty useful for this purpose.

Always use BufferedReader while reading InputStreams. Not using BufferedReader would lead to corrupt data and may not give correct results.

Code snippet is as given below :

HttpURLConnection hpCon;
hp = new URL(url);
hpCon = (HttpURLConnection)hp.openConnection();
InputStream in = hpCon.getInputStream();
InputStreamReader inStream = new InputStreamReader(in);
BufferedReader input = new BufferedReader(inStream);

String tempString="";

tempString = input.readLine();
if(tempString == null) break;
hp = null;
hpCon = null;

Tuesday, February 9, 2010

Not all named parameters have been set

Problem : I am getting one exception while trying to execute a query using hibernate

org.hibernate.QueryException: Not all named parameters have been set: [] [from FunctionPointDO f where f.workPackage='work package : id1' and f.workPackageIdentifier='work : ref1' and f.startDate='03-Jan-2010' and f.goLiveDate='04-Feb-2010' and!='1000100']
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(
at org.hibernate.impl.QueryImpl.list(
at Source)
at Source)
at Source)

It seems that this error is due to the “:” which is used as a value in f.workPackage='work package : id1' and f.workPackageIdentifier='work : ref1'. I checked on net and hibernate considers anything starting with colon (: ) as a variable, and here id1 and ref1 are treated as variable whose value is not set anywhere. This error comes only when colon has spaces around it.

How can I escape colon. As these values are entered by users, I don’t have any control over whatever input they provide.