if(rs != null) try { rs.close(); } catch(SQLException e) {  } if(descIdStmt != null) try { descIdStmt.close(); } catch(SQLException e) {  } if(stmt != null) try { stmt.close(); } catch(SQLException e) {  }
close(rs); close(descIdStmt); close(stmt);
	public static void addClassImages(Connection conn, int jarId, InputStream urlStream)	throws SQLException	{		PreparedStatement stmt = null;		PreparedStatement descIdStmt = null;		ResultSet rs = null;		try		{			int deployImageId = -1;			byte[] buf = new byte[1024];			ByteArrayOutputStream img = new ByteArrayOutputStream();			stmt = conn.prepareStatement(				"INSERT INTO sqlj.jar_entry(entryName, jarId, entryImage) VALUES(?, ?, ?)");			JarInputStream jis = new JarInputStream(urlStream);			Manifest manifest = jis.getManifest();			if(manifest != null)			{				ByteArrayOutputStream out = new ByteArrayOutputStream();				manifest.write(out);				PreparedStatement us = conn.prepareStatement(					"UPDATE sqlj.jar_repository SET jarManifest = ? WHERE jarId = ?");				try				{					us.setString(1, new String(out.toByteArray(), "UTF8"));					us.setInt(2, jarId);					if(us.executeUpdate() != 1)						throw new SQLException("Jar repository update did not update 1 row");				}				catch (UnsupportedEncodingException e)				{					// Excuse me? No UTF8 encoding?					//					throw new SQLException("JVM does not support UTF8!!");				}				finally				{					try { us.close(); } catch(SQLException e) { /* ignore close errors */ }				}			}			for(;;)			{				JarEntry je = jis.getNextJarEntry();				if(je == null)					break;				if(je.isDirectory())					continue;				String entryName = je.getName();				Attributes attrs = je.getAttributes();								boolean isDepDescr = false;				if(attrs != null)				{						isDepDescr = "true".equalsIgnoreCase(								attrs.getValue("SQLJDeploymentDescriptor"));					if(isDepDescr && deployImageId >= 0)						throw new SQLException("Only one SQLJDeploymentDescriptor allowed");				}				int nBytes;				img.reset();				while((nBytes = jis.read(buf)) > 0)					img.write(buf, 0, nBytes);				jis.closeEntry();				stmt.setString(1, entryName);				stmt.setInt(2, jarId);				stmt.setBytes(3, img.toByteArray());				if(stmt.executeUpdate() != 1)					throw new SQLException("Jar entry insert did not insert 1 row");								if(isDepDescr)				{					descIdStmt = conn.prepareStatement(							"SELECT entryId FROM sqlj.jar_entry" +							" WHERE jarId = ? AND entryName = ?");					descIdStmt.setInt(1, jarId);					descIdStmt.setString(2, entryName);					rs = descIdStmt.executeQuery();					if(!rs.next())						throw new SQLException("Failed to refecth row in sqlj.jar_entry");										deployImageId = rs.getInt(1);				}			}			if(deployImageId >= 0)			{				stmt.close();				stmt = conn.prepareStatement(					"UPDATE sqlj.jar_repository SET deploymentDesc = ? WHERE jarId = ?");				stmt.setInt(1, deployImageId);				stmt.setInt(2, jarId);				if(stmt.executeUpdate() != 1)					throw new SQLException("Jar repository update did not insert 1 row");			}		}		catch(IOException e)		{			throw new SQLException("I/O exception reading jar file: " + e.getMessage());		}		finally		{			if(rs != null)				try { rs.close(); } catch(SQLException e) { /* ignore */ }			if(descIdStmt != null)				try { descIdStmt.close(); } catch(SQLException e) { /* ignore */ }			if(stmt != null)				try { stmt.close(); } catch(SQLException e) { /* ignore */ }		}	}