Write a prj file according a given SRID code.
@param connection database connection
@param srid srid code
@param fileName path of the prj file
@throws SQLException
@throws FileNotFoundException
160575
public static void writePRJ(Connection connection, int srid, File fileName) throws SQLException, FileNotFoundException {
        if (srid != 0) {
            StringBuilder sb = new StringBuilder("SELECT SRTEXT FROM ");
            sb.append("PUBLIC.SPATIAL_REF_SYS ").append(" WHERE SRID = ?");
            PreparedStatement ps = connection.prepareStatement(sb.toString());
            ps.setInt(1, srid);
            PrintWriter printWriter = null;
            ResultSet rs = null;
            try {
                rs = ps.executeQuery();
                if (rs.next()) {
                    printWriter = new PrintWriter(fileName);
                    printWriter.println(rs.getString(1));
                } else {
                    log.warn("This SRID { "+ srid +" } is not supported. \n The PRJ file won't be created.");
                }
            } finally {
                if (printWriter != null) {
                    printWriter.close();
                }
                if (rs != null) {
                    rs.close();
                }
                ps.close();
            }
        }
    }
1023065
protected void writeConnectionIdEntry(StringBuilder sb, ExecutionInfo execInfo, List<QueryInfo> queryInfoList) {
        sb.append("Connection:");
        sb.append(execInfo.getConnectionId());
        sb.append(", ");
    }
641946
private void writeConnection(Definition def, Writer out, int indent) throws IOException
   {
      writeWithIndent(out, indent, "/**\n");
      writeWithIndent(out, indent, " * Creates a new connection handle for the underlying physical connection \n");
      writeWithIndent(out, indent, " * represented by the ManagedConnection instance. \n");
      writeWithIndent(out, indent, " *\n");
      writeWithIndent(out, indent, " * @param subject Security context as JAAS subject\n");
      writeWithIndent(out, indent, " * @param cxRequestInfo ConnectionRequestInfo instance\n");
      writeWithIndent(out, indent, " * @return generic Object instance representing the connection handle. \n");
      writeWithIndent(out, indent, " * @throws ResourceException generic exception if operation fails\n");
      writeWithIndent(out, indent, " */\n");

      writeWithIndent(out, indent, "public Object getConnection(Subject subject,\n");
      writeWithIndent(out, indent + 1, "ConnectionRequestInfo cxRequestInfo) throws ResourceException");
      writeLeftCurlyBracket(out, indent);
      writeLogging(def, out, indent + 1, "trace", "getConnection");
      writeIndent(out, indent + 1);
      if (def.getMcfDefs().get(getNumOfMcf()).isUseCciConnection())
         out.write(def.getMcfDefs().get(getNumOfMcf()).getCciConnClass() + " connection = new " +
               def.getMcfDefs().get(getNumOfMcf()).getCciConnClass() + "();\n");
      else
         out.write(def.getMcfDefs().get(getNumOfMcf()).getConnImplClass() + " connection = new " +
               def.getMcfDefs().get(getNumOfMcf()).getConnImplClass() + "(this, mcf);\n");
      writeWithIndent(out, indent + 1, "connections.add(connection);\n");
      writeWithIndent(out, indent + 1, "return connection;");
      writeRightCurlyBracket(out, indent);
      writeEol(out);

      writeWithIndent(out, indent, "/**\n");
      writeWithIndent(out, indent, " * Used by the container to change the association of an \n");
      writeWithIndent(out, indent, " * application-level connection handle with a ManagedConneciton instance.\n");
      writeWithIndent(out, indent, " *\n");
      writeWithIndent(out, indent, " * @param connection Application-level connection handle\n");
      writeWithIndent(out, indent, " * @throws ResourceException generic exception if operation fails\n");
      writeWithIndent(out, indent, " */\n");

      writeWithIndent(out, indent, "public void associateConnection(Object connection) throws ResourceException");
      writeLeftCurlyBracket(out, indent);
      writeLogging(def, out, indent + 1, "trace", "associateConnection", "connection\n");
      writeWithIndent(out, indent + 1, "if (connection == null)\n");
      writeWithIndent(out, indent + 2, "throw new ResourceException(\"Null connection handle\");\n\n");
      writeWithIndent(out, indent + 1, "if (!(connection instanceof ");
      if (def.getMcfDefs().get(getNumOfMcf()).isUseCciConnection())
         out.write(def.getMcfDefs().get(getNumOfMcf()).getCciConnClass());
      else
         out.write(def.getMcfDefs().get(getNumOfMcf()).getConnImplClass());
      out.write("))\n");
      writeWithIndent(out, indent + 2, "throw new ResourceException(\"Wrong connection handle\");\n\n");
      if (def.getMcfDefs().get(getNumOfMcf()).isUseCciConnection())
         writeWithIndent(out, indent + 1, def.getMcfDefs().get(getNumOfMcf()).getCciConnClass());
      else
         writeWithIndent(out, indent + 1, def.getMcfDefs().get(getNumOfMcf()).getConnImplClass());
      out.write(" handle = (");
      if (def.getMcfDefs().get(getNumOfMcf()).isUseCciConnection())
         out.write(def.getMcfDefs().get(getNumOfMcf()).getCciConnClass());
      else
         out.write(def.getMcfDefs().get(getNumOfMcf()).getConnImplClass());
      out.write(")connection;\n");
      writeWithIndent(out, indent + 1, "handle.setManagedConnection(this);\n");
      writeWithIndent(out, indent + 1, "connections.add(handle);");
      writeRightCurlyBracket(out, indent);
      writeEol(out);
   }
1216481
public static void writeGeoJson(Connection connection, String fileName, String tableReference, String encoding) throws IOException, SQLException {
        GeoJsonDriverFunction geoJsonDriver = new GeoJsonDriverFunction();
        geoJsonDriver.exportTable(connection,tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(),encoding);
    }
91301
private static void generateToCConnection(Map<String, List<TraceEvent>> events, FileWriter fw)
      throws Exception
   {
      writeString(fw, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"");
      writeEOL(fw);
      writeString(fw, "                      \"http://www.w3.org/TR/html4/loose.dtd\">");
      writeEOL(fw);

      writeString(fw, "<html>");
      writeEOL(fw);

      writeString(fw, "<head>");
      writeEOL(fw);

      writeString(fw, "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">");
      writeEOL(fw);

      writeString(fw, "<title>Reference: Connection</title>");
      writeEOL(fw);

      writeString(fw, "</head>");
      writeEOL(fw);

      writeString(fw, "<body style=\"background: #D7D7D7;\">");
      writeEOL(fw);

      writeString(fw, "<h1>Reference: Connection</h1>");
      writeEOL(fw);

      writeString(fw, "<ul>");
      writeEOL(fw);

      for (String id : events.keySet())
      {
         writeString(fw, "<li><a href=\"#" + id + "\">" + id + "</a></li>");
         writeEOL(fw);
      }

      writeString(fw, "</ul>");
      writeEOL(fw);

      for (Map.Entry<String, List<TraceEvent>> entry : events.entrySet())
      {
         writeString(fw, "<a name=\"" + entry.getKey() + "\"><h2>" + entry.getKey() + "</h2></a>");
         writeEOL(fw);

         writeString(fw, "<table>");
         writeEOL(fw);
      
         writeString(fw, "<tr>");
         writeEOL(fw);

         writeString(fw, "<td><b>Timestamp</b></td>");
         writeEOL(fw);

         writeString(fw, "<td><b>ConnectionListener</b></td>");
         writeEOL(fw);

         writeString(fw, "<td><b>ManagedConnectionPool</b></td>");
         writeEOL(fw);

         writeString(fw, "<td><b>Pool</b></td>");
         writeEOL(fw);

         writeString(fw, "</tr>");
         writeEOL(fw);

         for (TraceEvent te : entry.getValue())
         {
            writeString(fw, "<tr>");
            writeEOL(fw);

            writeString(fw, "<td>" + te.getTimestamp() + "</td>");
            writeEOL(fw);
      
            writeString(fw, "<td><a href=\"" + te.getPool() + "/" + te.getConnectionListener() + "/index.html\">" +
                        te.getConnectionListener() + "</a></td>");
            writeEOL(fw);
         
            writeString(fw, "<td>" + te.getManagedConnectionPool() + "</td>");
            writeEOL(fw);
      
            writeString(fw, "<td><a href=\"" + te.getPool() + "/index.html\">" + te.getPool() + "</a></td>");
            writeEOL(fw);
      
            writeString(fw, "</tr>");
            writeEOL(fw);
         }
         
         writeString(fw, "</table>");
         writeEOL(fw);

         writeString(fw, "<p>");
         writeEOL(fw);
      }

      writeString(fw, "<p>");
      writeEOL(fw);

      writeString(fw, "<a href=\"index.html\">Back</a>");
      writeEOL(fw);

      writeString(fw, "</body>");
      writeEOL(fw);

      writeString(fw, "</html>");
      writeEOL(fw);
   }
118815
public void write(ProgressVisitor progress, String tableName, File fileName, String encoding) throws SQLException, IOException {
        String regex = ".*(?i)\\b(select|from)\\b.*";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(tableName);
        if (matcher.find()) {
            if (tableName.startsWith("(") && tableName.endsWith(")")) {
                PreparedStatement ps = connection.prepareStatement(tableName, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                ResultSet resultSet = ps.executeQuery();
                write(progress, resultSet, fileName, encoding);
            } else {
                throw new SQLException("The select query must be enclosed in parenthesis: '(SELECT * FROM ORDERS)'.");
            }
        } else {
            if (FileUtil.isExtensionWellFormated(fileName, "geojson")) {
                JsonEncoding jsonEncoding =  JsonEncoding.UTF8;
                if (encoding != null) {
                    try {
                        jsonEncoding = JsonEncoding.valueOf(encoding);
                    } catch (IllegalArgumentException ex) {
                        throw new SQLException("Only UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF-32LE encoding is supported");
                    }
                }
                
                FileOutputStream fos = null;
                try {
                    fos = new FileOutputStream(fileName);
                    int recordCount = JDBCUtilities.getRowCount(connection, tableName);
                    if (recordCount > 0) {
                        ProgressVisitor copyProgress = progress.subProcess(recordCount);
                        // Read Geometry Index and type
                        final TableLocation parse = TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData()));
                        List<String> spatialFieldNames = SFSUtilities.getGeometryFields(connection, parse);
                        if (spatialFieldNames.isEmpty()) {
                            throw new SQLException(String.format("The table %s does not contain a geometry field", tableName));
                        }

                        try ( // Read table content
                            Statement st = connection.createStatement()) {
                            JsonFactory jsonFactory = new JsonFactory();
                            JsonGenerator jsonGenerator = jsonFactory.createGenerator(new BufferedOutputStream(fos), jsonEncoding);

                            // header of the GeoJSON file
                            jsonGenerator.writeStartObject();
                            jsonGenerator.writeStringField("type", "FeatureCollection");
                            writeCRS(jsonGenerator, SFSUtilities.getAuthorityAndSRID(connection, parse, spatialFieldNames.get(0)));
                            jsonGenerator.writeArrayFieldStart("features");

                            ResultSet rs = st.executeQuery(String.format("select * from %s", tableName));

                            try {
                                ResultSetMetaData resultSetMetaData = rs.getMetaData();
                                int geoFieldIndex = JDBCUtilities.getFieldIndex(resultSetMetaData, spatialFieldNames.get(0));
                                cacheMetadata(resultSetMetaData);
                                while (rs.next()) {
                                    writeFeature(jsonGenerator, rs, geoFieldIndex);
                                    copyProgress.endStep();
                                }
                                copyProgress.endOfProgress();
                                // footer
                                jsonGenerator.writeEndArray();
                                jsonGenerator.writeEndObject();
                                jsonGenerator.flush();
                                jsonGenerator.close();

                            } finally {
                                rs.close();
                            }
                        }
                    }
                } catch (FileNotFoundException ex) {
                    throw new SQLException(ex);

                } finally {
                    try {
                        if (fos != null) {
                            fos.close();
                        }
                    } catch (IOException ex) {
                        throw new SQLException(ex);
                    }
                }
            } else {
                throw new SQLException("Only .geojson extension is supported");
            }
        }
    }
405839
private void setSchemaOnConnection(Connection connection) throws SQLException {
		logger.finest("Entering " + CLASSNAME +".setSchemaOnConnection()");

		String dbProductName = connection.getMetaData().getDatabaseProductName();
		if (!"Oracle".equals(dbProductName) && !"Microsoft SQL Server".equals(dbProductName)) {
			PreparedStatement ps = null;
			if ("MySQL".equals(dbProductName)) {
				ps = connection.prepareStatement("USE " + schema);
			} else {
				ps = connection.prepareStatement("SET SCHEMA ?");
				ps.setString(1, schema);
			}
			ps.executeUpdate(); 
			ps.close();
		}

		logger.finest("Exiting " + CLASSNAME +".setSchemaOnConnection()");
	}
9574
public void writeFile(String filePath, byte[] data) throws IOException
   {
      Object lock = retrieveLock(filePath);      
      synchronized (lock) 
      {
         IO.writeFile(filePath, data);
      }
   }
353280
public void addConnection (Connection connection) {
		if (connection == null) throw new IllegalArgumentException("connection cannot be null.");

		synchronized (connectionsLock) {
			Connection[] newConnections = new Connection[connections.length + 1];
			newConnections[0] = connection;
			System.arraycopy(connections, 0, newConnections, 1, connections.length);
			connections = newConnections;
		}

		connection.addListener(invokeListener);

		if (TRACE) trace("kryonet", "Added connection to ObjectSpace: " + connection);
	}
98300
@Override
    public void writeJoinTableData(String tableName, Object rowId, Map<String, Object> columns, String columnFamilyName)
            throws IOException
    {
        HTableInterface hTable = gethTable(tableName);

        hbaseWriter.writeColumns(hTable, rowId, columns, columnFamilyName);

        puthTable(hTable);
    }
1049659
private void createTables(Connection conn) throws DatabaseException {
        LOGGER.debug("Creating database structure");

        try (InputStream is = FileUtils.getResourceAsStream(DB_STRUCTURE_RESOURCE)) {
            final String dbStructure = IOUtils.toString(is, StandardCharsets.UTF_8);

            Statement statement = null;
            try {
                statement = conn.createStatement();
                statement.execute(dbStructure);
            } catch (SQLException ex) {
                LOGGER.debug("", ex);
                throw new DatabaseException("Unable to create database statement", ex);
            } finally {
                DBUtils.closeStatement(statement);
            }
        } catch (IOException ex) {
            throw new DatabaseException("Unable to create database schema", ex);
        }
    }
345536
private void writeConnection(Definition def, Writer out, int indent) throws IOException
   {
      writeWithIndent(out, indent, "/** \n");
      writeWithIndent(out, indent, " * Get connection from factory\n");
      writeWithIndent(out, indent, " *\n");
      writeWithIndent(out, indent,
            " * @return " + def.getMcfDefs().get(getNumOfMcf()).getConnInterfaceClass() + " instance\n");
      writeWithIndent(out, indent, " * @exception ResourceException Thrown if a connection can't be obtained\n");
      writeWithIndent(out, indent, " */\n");

      writeWithIndent(out, indent, "@Override\n");
      writeWithIndent(out, indent, "public " + def.getMcfDefs().get(getNumOfMcf()).getConnInterfaceClass() +
            " getConnection() throws ResourceException");
      writeLeftCurlyBracket(out, indent);
      writeLogging(def, out, indent + 1, "trace", "getConnection");

      writeWithIndent(out, indent + 1, "return (" + def.getMcfDefs().get(getNumOfMcf()).getConnInterfaceClass() +
            ")connectionManager.allocateConnection(mcf, null);");
      writeRightCurlyBracket(out, indent);
      writeEol(out);
   }
1126065
public void write(ProgressVisitor progress, ResultSet rs, File fileName, String encoding) throws SQLException, IOException {
        if (FileUtil.isExtensionWellFormated(fileName, "json")) {
            JsonEncoding jsonEncoding = JsonEncoding.UTF8;
            if (encoding != null) {
                try {
                    jsonEncoding = JsonEncoding.valueOf(encoding);
                } catch (IllegalArgumentException ex) {
                    throw new SQLException("Only UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF-32LE encoding is supported");
                }
            }
            FileOutputStream fos = null;
            try {
            fos = new FileOutputStream(fileName);
            int rowCount = 0;
                int type = rs.getType();
                if (type == ResultSet.TYPE_SCROLL_INSENSITIVE || type == ResultSet.TYPE_SCROLL_SENSITIVE) {
                    rs.last();
                    rowCount = rs.getRow();
                    rs.beforeFirst();
                }
                ProgressVisitor copyProgress = progress.subProcess(rowCount);   
                try ( // Read table content
                    Statement st = connection.createStatement()) {
                    JsonFactory jsonFactory = new JsonFactory();
                    JsonGenerator jsonGenerator = jsonFactory.createGenerator(new BufferedOutputStream(fos), jsonEncoding);                    
                    try {
                        ResultSetMetaData rsmd = rs.getMetaData();
                        int numColumns = rsmd.getColumnCount();
                        while (rs.next()) {
                            jsonGenerator.writeStartObject();
                            for (int i = 1; i < numColumns + 1; i++) {
                                String column_name = rsmd.getColumnName(i);
                                switch (rsmd.getColumnType(i)) {
                                    case java.sql.Types.ARRAY:
                                        Object[] values = (Object[]) rs.getArray(i).getArray();
                                        if(values !=null){
                                            jsonGenerator.writeArrayFieldStart(column_name);
                                            for (Object value : values) {
                                                jsonGenerator.writeObject(value);
                                            }
                                            jsonGenerator.writeEndArray();
                                        }
                                        break;
                                    case java.sql.Types.BIGINT:
                                        jsonGenerator.writeObjectField(column_name, rs.getLong(i));
                                        break;
                                    case java.sql.Types.REAL:
                                        jsonGenerator.writeObjectField(column_name, rs.getFloat(i));
                                        break;
                                    case java.sql.Types.BOOLEAN:
                                        jsonGenerator.writeObjectField(column_name, rs.getBoolean(i));
                                        break;
                                    case java.sql.Types.BLOB:
                                        jsonGenerator.writeObjectField(column_name, rs.getBlob(i));
                                        break;
                                    case java.sql.Types.DOUBLE:
                                        jsonGenerator.writeObjectField(column_name, rs.getDouble(i));
                                        break;
                                    case java.sql.Types.FLOAT:
                                        jsonGenerator.writeObjectField(column_name, rs.getDouble(i));
                                        break;
                                    case java.sql.Types.INTEGER:
                                        jsonGenerator.writeObjectField(column_name, rs.getInt(i));
                                        break;
                                    case java.sql.Types.NVARCHAR:
                                        jsonGenerator.writeObjectField(column_name, rs.getNString(i));
                                        break;
                                    case java.sql.Types.VARCHAR:
                                        jsonGenerator.writeObjectField(column_name, rs.getString(i));
                                        break;
                                    case java.sql.Types.CHAR:
                                        jsonGenerator.writeObjectField(column_name, rs.getString(i));
                                        break;
                                    case java.sql.Types.NCHAR:
                                        jsonGenerator.writeObjectField(column_name, rs.getNString(i));
                                        break;
                                    case java.sql.Types.LONGNVARCHAR:
                                        jsonGenerator.writeObjectField(column_name, rs.getNString(i));
                                        break;
                                    case java.sql.Types.LONGVARCHAR:
                                        jsonGenerator.writeObjectField(column_name, rs.getString(i));
                                        break;
                                    case java.sql.Types.TINYINT:
                                        jsonGenerator.writeObjectField(column_name, rs.getByte(i));
                                        break;
                                    case java.sql.Types.SMALLINT:
                                        jsonGenerator.writeObjectField(column_name, rs.getShort(i));
                                        break;
                                    case java.sql.Types.DATE:
                                        jsonGenerator.writeObjectField(column_name, rs.getDate(i));
                                        break;
                                    case java.sql.Types.TIME:
                                        jsonGenerator.writeObjectField(column_name, rs.getTime(i));
                                        break;
                                    case java.sql.Types.TIMESTAMP:
                                        jsonGenerator.writeObjectField(column_name, rs.getTimestamp(i));
                                        break;
                                    case java.sql.Types.BINARY:
                                        jsonGenerator.writeObjectField(column_name, rs.getBytes(i));
                                        break;
                                    case java.sql.Types.VARBINARY:
                                        jsonGenerator.writeObjectField(column_name, rs.getBytes(i));
                                        break;
                                    case java.sql.Types.LONGVARBINARY:
                                        jsonGenerator.writeObjectField(column_name, rs.getBinaryStream(i));
                                        break;
                                    case java.sql.Types.BIT:
                                        jsonGenerator.writeObjectField(column_name, rs.getBoolean(i));
                                        break;
                                    case java.sql.Types.CLOB:
                                        jsonGenerator.writeObjectField(column_name, rs.getClob(i));
                                        break;
                                    case java.sql.Types.NUMERIC:
                                        jsonGenerator.writeObjectField(column_name, rs.getBigDecimal(i));
                                        break;
                                    case java.sql.Types.DECIMAL:
                                        jsonGenerator.writeObjectField(column_name, rs.getBigDecimal(i));
                                        break;
                                    case java.sql.Types.DATALINK:
                                        jsonGenerator.writeObjectField(column_name, rs.getURL(i));
                                        break;
                                    case java.sql.Types.REF:
                                        jsonGenerator.writeObjectField(column_name, rs.getRef(i));
                                        break;
                                    case java.sql.Types.STRUCT:
                                        jsonGenerator.writeObjectField(column_name, rs.getObject(i));
                                        break;
                                    case java.sql.Types.DISTINCT:
                                        jsonGenerator.writeObjectField(column_name, rs.getObject(i));
                                        break;
                                    case java.sql.Types.JAVA_OBJECT:
                                        jsonGenerator.writeObjectField(column_name, rs.getObject(i));
                                        break;
                                    default:
                                        jsonGenerator.writeObjectField(column_name, rs.getString(i));
                                        break;
                                }
                            }
                            jsonGenerator.writeEndObject();

                            copyProgress.endStep();
                        }
                        copyProgress.endOfProgress();
                        jsonGenerator.flush();
                        jsonGenerator.close();
                    } finally {
                        rs.close();
                    }
                }
            
        } catch (FileNotFoundException ex) {
            throw new SQLException(ex);

        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
                } catch (IOException ex) {
                    throw new SQLException(ex);
                }
            }
        } else {
            throw new SQLException("Only .json extension is supported");
        }
    }
383587
public void write(ProgressVisitor progress, ResultSet rs, File fileName, String encoding) throws SQLException, IOException {
        if (FileUtil.isExtensionWellFormated(fileName, "geojson")) {
            FileOutputStream fos = null;
            JsonEncoding jsonEncoding = JsonEncoding.UTF8;
            if (encoding != null) {
                try {
                    jsonEncoding = JsonEncoding.valueOf(encoding);
                } catch (IllegalArgumentException ex) {
                    throw new SQLException("Only UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF-32LE encoding is supported");
                }
            }
            try {                
                fos = new FileOutputStream(fileName);
                int rowCount = 0;
                int type = rs.getType();
                if (type == ResultSet.TYPE_SCROLL_INSENSITIVE || type == ResultSet.TYPE_SCROLL_SENSITIVE) {
                    rs.last();
                    rowCount = rs.getRow();
                    rs.beforeFirst();
                }
                ProgressVisitor copyProgress = progress.subProcess(rowCount);                
                // Read Geometry Index and type
                List<String> spatialFieldNames = SFSUtilities.getGeometryFields(rs);
                if (spatialFieldNames.isEmpty()) {
                    throw new SQLException("The resulset %s does not contain a geometry field");
                }

                JsonFactory jsonFactory = new JsonFactory();
                JsonGenerator jsonGenerator = jsonFactory.createGenerator(new BufferedOutputStream(fos), jsonEncoding);

                // header of the GeoJSON file
                jsonGenerator.writeStartObject();
                jsonGenerator.writeStringField("type", "FeatureCollection");
                jsonGenerator.writeArrayFieldStart("features");
                try {
                    ResultSetMetaData resultSetMetaData = rs.getMetaData();
                    int geoFieldIndex = JDBCUtilities.getFieldIndex(resultSetMetaData, spatialFieldNames.get(0));
                    cacheMetadata(resultSetMetaData);
                    while (rs.next()) {
                        writeFeature(jsonGenerator, rs, geoFieldIndex);
                        copyProgress.endStep();
                    }
                    copyProgress.endOfProgress();
                    // footer
                    jsonGenerator.writeEndArray();
                    jsonGenerator.writeEndObject();
                    jsonGenerator.flush();
                    jsonGenerator.close();
                } finally {
                    rs.close();
                }

            } catch (FileNotFoundException ex) {
                throw new SQLException(ex);

            } finally {
                try {
                    if (fos != null) {
                        fos.close();
                    }
                } catch (IOException ex) {
                    throw new SQLException(ex);
                }
            }
        } else {
            throw new SQLException("Only .geojson extension is supported");
        }
    }
727752
public static void createTables( Connection connection ) throws IOException, SQLException {
        StringBuilder sB = new StringBuilder();
        sB.append("CREATE TABLE ");
        sB.append(TABLE_NOTES);
        sB.append(" (");
        sB.append(NotesTableFields.COLUMN_ID.getFieldName());
        sB.append(" INTEGER PRIMARY KEY, ");
        sB.append(NotesTableFields.COLUMN_LON.getFieldName()).append(" REAL NOT NULL, ");
        sB.append(NotesTableFields.COLUMN_LAT.getFieldName()).append(" REAL NOT NULL,");
        sB.append(NotesTableFields.COLUMN_ALTIM.getFieldName()).append(" REAL NOT NULL,");
        sB.append(NotesTableFields.COLUMN_TS.getFieldName()).append(" DATE NOT NULL,");
        sB.append(NotesTableFields.COLUMN_DESCRIPTION.getFieldName()).append(" TEXT, ");
        sB.append(NotesTableFields.COLUMN_TEXT.getFieldName()).append(" TEXT NOT NULL, ");
        sB.append(NotesTableFields.COLUMN_FORM.getFieldName()).append(" CLOB, ");
        sB.append(NotesTableFields.COLUMN_STYLE.getFieldName()).append(" TEXT,");
        sB.append(NotesTableFields.COLUMN_ISDIRTY.getFieldName()).append(" INTEGER");
        sB.append(");");
        String CREATE_TABLE_NOTES = sB.toString();

        sB = new StringBuilder();
        sB.append("CREATE INDEX notes_ts_idx ON ");
        sB.append(TABLE_NOTES);
        sB.append(" ( ");
        sB.append(NotesTableFields.COLUMN_TS.getFieldName());
        sB.append(" );");
        String CREATE_INDEX_NOTES_TS = sB.toString();

        sB = new StringBuilder();
        sB.append("CREATE INDEX notes_x_by_y_idx ON ");
        sB.append(TABLE_NOTES);
        sB.append(" ( ");
        sB.append(NotesTableFields.COLUMN_LON.getFieldName());
        sB.append(", ");
        sB.append(NotesTableFields.COLUMN_LAT.getFieldName());
        sB.append(" );");
        String CREATE_INDEX_NOTES_X_BY_Y = sB.toString();

        sB = new StringBuilder();
        sB.append("CREATE INDEX notes_isdirty_idx ON ");
        sB.append(TABLE_NOTES);
        sB.append(" ( ");
        sB.append(NotesTableFields.COLUMN_ISDIRTY.getFieldName());
        sB.append(" );");
        String CREATE_INDEX_NOTES_ISDIRTY = sB.toString();

        try (Statement statement = connection.createStatement()) {
            statement.setQueryTimeout(30); // set timeout to 30 sec.

            statement.executeUpdate(CREATE_TABLE_NOTES);
            statement.executeUpdate(CREATE_INDEX_NOTES_TS);
            statement.executeUpdate(CREATE_INDEX_NOTES_X_BY_Y);
            statement.executeUpdate(CREATE_INDEX_NOTES_ISDIRTY);
        } catch (Exception e) {
            throw new IOException(e.getLocalizedMessage());
        }
    }
1353611
public void save(String fileName)
      throws FileNotFoundException, UnsupportedEncodingException {
    try (PrintWriter writer = new PrintWriter(fileName, "UTF-8")) {
      for (Map.Entry<String, Integer> entry : data.entrySet()) {
        writer.println(String.format("%d;%s", entry.getValue(), entry.getKey()));
      }
    }
  }
338478
public static boolean isSRIDValid(int srid, Connection connection) throws SQLException {
        PreparedStatement ps = null;
        ResultSet rs = null;
        String queryCheck = "SELECT count(SRID) from PUBLIC.SPATIAL_REF_SYS WHERE SRID = ?";
        try {
            ps = connection.prepareStatement(queryCheck);
            ps.setInt(1, srid);
            rs = ps.executeQuery();
            if (rs.next()) {
                return rs.getInt(1) != 0;
            }
        } finally {
            if (rs != null) {
                rs.close();
            }
            if (ps != null) {
                ps.close();
            }
        }
        return false;
    }