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

Apache 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: Apache License 

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {
    public static final String SQLITE_JDBC_DRIVER = "org.sqlite.JDBC";

    /**//  w ww  .  j a  va2s  .co m
     * 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 = DriverManager.getConnection(jdbcConnectionString);
        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();
        byte[] tileData = new byte[0];
        while (rs.next()) {
            tileData = rs.getBytes("tile_data");
        }
        rs.close();
        stat.close();
        conn.close();

        return tileData;
    }
}

Related

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