e.printStackTrace(); } finally { try { if (connection != null) connection.close(); } catch (SQLException se) { getLogger().log(Level.WARNING, "An error occured while trying to close a database connection", se); }
getLogger().log(Level.WARNING, "Input/Output exception", ioe);
	public void handle(Request request, Response response)	{		Connection connection = null;		try		{			// Parse the JDBC URI			String connectionURI = request.getResourceRef().toString();			// Parse the request to extract necessary info			DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance()					.newDocumentBuilder();			Document requestDoc = docBuilder.parse(request.getEntity().getStream());			Element rootElt = (Element) requestDoc.getElementsByTagName("request").item(0);			Element headerElt = (Element) rootElt.getElementsByTagName("header").item(0);			Element connectionElt = (Element) headerElt.getElementsByTagName("connection")					.item(0);			// Read the connection pooling setting			Node usePoolingNode = connectionElt.getElementsByTagName("usePooling").item(0);			boolean usePooling = usePoolingNode.getTextContent().equals("true") ? true					: false;			// Read the connection properties			NodeList propertyNodes = connectionElt.getElementsByTagName("property");			Node propertyNode = null;			Properties properties = null;			String name = null;			String value = null;			for (int i = 0; i < propertyNodes.getLength(); i++)			{				propertyNode = propertyNodes.item(i);				if (properties == null) properties = new Properties();				name = propertyNode.getAttributes().getNamedItem("name").getTextContent();				value = propertyNode.getTextContent();				properties.setProperty(name, value);			}			Node returnGeneratedKeysNode = headerElt.getElementsByTagName(					"returnGeneratedKeys").item(0);			boolean returnGeneratedKeys = returnGeneratedKeysNode.getTextContent().equals(					"true") ? true : false;			// Read the SQL body			Node sqlRequestNode = rootElt.getElementsByTagName("body").item(0);			String sqlRequest = sqlRequestNode.getTextContent();			if (request.getMethod().equals(Method.POST))			{				// Execute the SQL request				connection = getConnection(connectionURI, properties, usePooling);				Statement statement = connection.createStatement();				statement.execute(sqlRequest,						returnGeneratedKeys ? Statement.RETURN_GENERATED_KEYS								: Statement.NO_GENERATED_KEYS);				JdbcResult result = new JdbcResult(statement);				response.setEntity(new ObjectRepresentation(result));				// Commit any changes to the database				connection.commit();			}			else			{				throw new IllegalArgumentException("Only the POST method is supported");			}		}		catch (SQLException se)		{			getLogger().log(Level.WARNING, "Error while processing the SQL request", se);		}		catch (ParserConfigurationException pce)		{			getLogger().log(Level.WARNING, "Error with XML parser configuration", pce);		}		catch (SAXException se)		{			getLogger().log(Level.WARNING, "Error while parsing the XML document", se);		}		catch (IOException e)		{			// TODO Auto-generated catch block			e.printStackTrace();		}		finally		{			try			{				if (connection != null) connection.close();			}			catch (SQLException se)			{				getLogger().log(Level.WARNING,						"An error occured while trying to close a database connection", se);			}		}	}