URL constructor for XML query

I can't seem to construct an http SQL query correctly using the Java URL constructor. When I enter the following string in the browser window, everything works fine:

"http://aaaa.bbb.ccc.com/nwind?sql=select * from employees for xml auto&root=root". The results of the query are displayed in the browser window. I would like to get this to work using the URL and URLConnection classes. It seems I always get some sort of error with a response length of -1. I would appreciate any insight into this problem. Thanks for your help.

Paul J. Lay

pjlay@msn.com

[591 byte] By [pjlay] at [2007-9-26 2:10:53]
# 1
Try...URL url = new URL(" http://aaaa.bbb.ccc.com/nwind?sql=" + java.net.URLEncoder.encode("select * ..."));
neville_sequeira at 2007-6-29 9:02:18 > top of Java-index,Archived Forums,Java Programming...
# 2

Thanks for your prompt reply. I tried your suggestion immediately. It didn't change the results. I still get a response length of -1. You can actually try this yourself by keying in a browser window the following string: www.itsmagical.com/nwind?sql=select * from employees for xml auto&root=root. I can't imagine what the problem could be. Thanks again for your prompt reply.

Best Regards,

Paul J. Lay

pjlay at 2007-6-29 9:02:18 > top of Java-index,Archived Forums,Java Programming...
# 3

Well no, I pasted that into my IE5 address box, typed "http://" before it, pressed Enter and received an XML file of employees starting with Nancy Davolio. Perhaps somebody fixed something on the server? By the way, what would have happened if I had changed it to

www.itsmagical.com/nwind?sql=delete from employees&root=root

?

DrClap at 2007-6-29 9:02:18 > top of Java-index,Archived Forums,Java Programming...
# 4

Great! You executed the query from the browser as I have here. My problem is that I can't send that string correctly using the Java URL and URLConnection classes. This should be simple. I can't image why this is so difficult using Java. Surely there is some expert out there that can show me the way. Thanks for your prompt reply.

Best Regards,

Paul J. Lay

pjlay@msn.com

pjlay at 2007-6-29 9:02:18 > top of Java-index,Archived Forums,Java Programming...
# 5
Success! I am now getting the response expected by ignoring the output of URLConnection::getContentLength which is always -1. This appears to be a bug.
pjlay at 2007-6-29 9:02:18 > top of Java-index,Archived Forums,Java Programming...