Help coderanch get a
new server
by contributing to the fundraiser

Colin Olphert

Greenhorn
+ Follow
since Feb 07, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Colin Olphert

Hi

I'm writing an applet that sends an SQL statement to a servlet accross a network and then receives the results as a vector. Here is the code I use:

try{

URL sqlServlet = new URL("http://193.61.149.35/smarthome/SmartHomeSQLServer");
URLConnection servletConnection = sqlServlet.openConnection();
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
servletConnection.setRequestProperty("Accept", "text/html");
servletConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

// Send POST output.
OutputStreamWriter printout = new OutputStreamWriter(servletConnection.getOutputStream());
String sql = "SELECT * FROM test WHERE number='1';";
String content = "SQL=" + URLEncoder.encode(sql);
printout.write(content);
printout.flush();

// Get the response
ObjectInputStream ois = new ObjectInputStream(servletConnection.getInputStream());
Vector v = (Vector) ois.readObject();
printout.close();
ois.close();

}catch( Exception E){

JOptionPane.showMessageDialog(null, E.getMessage());}

The problem is that when the line: OutputStreamWriter printout = new OutputStreamWriter(servletConnection.getOutputStream()); is executed an exception is thrown. The exception is: access denied(java.net SocketPermission)

Can anyone tell me why this is happening and how I can fix it.
19 years ago