Java SQL Type getMBTileData(int column, int row, int zoomLevel, String jdbcConnectionString)

Here you can find the source of getMBTileData(int column, int row, int zoomLevel, String jdbcConnectionString)

Description

Loads the MBTile data from the database as blob, and returns it as byte array.

License

Open Source License

Parameter

Parameter Description
column The column of the tile.
row The row of the tile.
zoomLevel The zoom level of the tile.

Return

The tile as byte array with image information, or an empty array if not found.

Declaration

protected static byte[] getMBTileData(int column, int row,
        int zoomLevel, String jdbcConnectionString) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static final String SQLITE_JDBC_DRIVER = "org.sqlite.JDBC";
    protected static Map<String, Connection> connectionsMap = new HashMap<String, Connection>();

    /**/*from   ww  w  .j  ava2s.  com*/
     * Loads the MBTile data from the database as blob, and returns it as byte array.
     * 
     * @param column
     *            The column of the tile.
     * @param row
     *            The row of the tile.
     * @param zoomLevel
     *            The zoom level of the tile.
     * @return The tile as byte array with image information, or an empty array if not found.
     */
    protected static byte[] getMBTileData(int column, int row,
            int zoomLevel, String jdbcConnectionString) throws Exception {
        Class.forName(SQLITE_JDBC_DRIVER);

        Connection conn = null;
        byte[] tileData = null;

        try {
            conn = connectionsMap.get(jdbcConnectionString);
            if (conn == null) {
                conn = DriverManager.getConnection(jdbcConnectionString);
                connectionsMap.put(jdbcConnectionString, conn);
            }

            Statement stat = conn.createStatement();
            PreparedStatement prep = conn
                    .prepareStatement("SELECT * FROM tiles WHERE tile_column = ? AND tile_row = ? AND zoom_level = ?;");
            prep.setInt(1, column);
            prep.setInt(2, row);
            prep.setInt(3, zoomLevel);

            ResultSet rs = prep.executeQuery();

            while (rs.next()) {
                tileData = rs.getBytes("tile_data");
            }
            rs.close();
            stat.close();
        } catch (SQLException e) {
            System.err.println(e.getMessage());
        } finally {
            //         try {
            //            if (conn != null)
            //               conn.close();
            //         } catch (SQLException e) {
            //            // connection close failed.
            //            System.err.println(e);
            //         }
        }
        return tileData;
    }
}

Related

  1. getJdbcTypeNames()
  2. getJDBCTypes()
  3. getLength(String format, String columnTypeName)
  4. getLong(Object object)
  5. getMBTileData(int column, int row, int zoomLevel, String jdbcConnectionString)
  6. getMessages(Array arr)
  7. getNameByType(int sqlType)
  8. getNameFromJdbcType(int jdbcType)
  9. getNextQuotes(String lastQuotes, int lastType)