GithubHelp home page GithubHelp logo

miles-x / spatialite4-jdbc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from benstadin/spatialite4-jdbc

0.0 2.0 0.0 179.73 MB

JDBC library for SpatiaLite 4.2+

License: BSD 2-Clause "Simplified" License

Makefile 1.39% Shell 0.10% C 14.54% Java 83.97%

spatialite4-jdbc's Introduction

SpatiaLite 4 JDBC Driver

SpatiaLite 4 JDBC requires no configuration, since native DLLs are assembled into a single JAR (Java Archive) file.

This is a fork of Xerial's current SQLite library and Justin Deoliveira's SpatiaLite driver, with added support for the latest SpatiaLite library (4.2+). Spatialite 4.2+ has changed significantly, especially in regards to the extension loading. Therefore this updated and incompatible library for Spatialite 4.2 and upwards was created.

This library bases on the following two upstream libraries: Xerial: https://github.com/xerial/sqlite-jdbc Justin Deoliveira's SpatiaLite JDBC driver: https://github.com/jdeolive/sqlite-jdbc

Changes:

  • SpatiaLite API updates and changes to the SpatiaLite driver to support the latest 4.2+ version
  • Simple cache manager added for SpatiaLite's new per-connection cache objects
  • Removed old boilerplate resources and code
  • Fixes to SQLite extensions code (merged with latest from SQLite)
  • Fixes and auto-sanitization to open() and close() methods of the original xerial driver

Current versions included: SQLite: 3.11.1 SpatiaLite: 4.3.0a

Current status: Initial version. Builds on OS X and Linux with all tests ok. No real-world testing done yet.

Usage

Note: Please see Xerial's documentation for common SQLite usage examples. This is just a very short introduction on how to initialize the SpatiaLite 4 JDBC driver.

For the general usage of JDBC, see JDBC Tutorial or Oracle JDBC Documentation.

  1. Download spatialite-jdbc-(VERSION).jar from the release directory and append this jar file into your classpath.
  2. Load the JDBC driver org.spatialite.JDBC from your code. (see the example below)
  • Usage Example

Spatialite.java

java -classpath "demo:release/spatialite-jdbc-4.3.0a.jar" Spatialite

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class Spatialite
{
    public static Connection getConnection(Properties prop) throws SQLException {
        return DriverManager.getConnection("jdbc:spatialite::memory:", prop);
    }
    
	public static void main(String[] args) 
	{
        Properties prop = new Properties();
        prop.setProperty("enable_shared_cache", "true");
        prop.setProperty("enable_load_extension", "true");
        prop.setProperty("enable_spatialite", "true");
        
        Connection conn = null;
        try {
            conn = getConnection(prop);
            Statement stat = conn.createStatement();
            stat.execute("SELECT InitSpatialMetaData()");
            stat.close();
            stat = conn.createStatement();
            ResultSet rs = stat.executeQuery("SELECT * FROM geometry_columns");
            stat.close();
            if (conn != null)
                conn.close();
        }
        catch (SQLException e) {
            e.printStackTrace();
        }
	}
}

How to Specify Database Files

Here is an example to select a file C:\work\mydatabase.db (in Windows)

Connection connection = DriverManager.getConnection("jdbc.spatialite:C:/work/mydatabase.db");

A UNIX (Linux, Mac OS X, etc) file /home/leo/work/mydatabase.db

Connection connection = DriverManager.getConnection("jdbc.spatialite:/home/leo/work/mydatabase.db");

How to Use Memory Databases

SpatiaLite supports on-memory database management, which does not create any database files. To use a memory database in your Java code, get the database connection as follows:

Connection connection = DriverManager.getConnection("jdbc.spatialite::memory:");

Supported Operating Systems

Currenty spatialite-jdbc-4.3.0a compiles on OS X 64 and Linux 64 (Ubuntu 14.04).

The following operating systems are supported in theory, but no attempt to build has been done yet:

  • Windows XP, Vista (Windows, x86 architecture, x86_64)
  • Mac OS X 10.9 (i386, x86_64)
  • Linux i386 (Intel), amd64 (64-bit X86 Intel processor), Linux arm

License

This program follows the Apache License version 2.0 (http://www.apache.org/licenses/ ) That means:

It allows you to:

  • freely download and use this software, in whole or in part, for personal, company internal, or commercial purposes;
  • use this software in packages or distributions that you create.

It forbids you to:

  • redistribute any piece of our originated software without proper attribution;
  • use any marks owned by us in any way that might state or imply that we xerial.org endorse your distribution;
  • use any marks owned by us in any way that might state or imply that you created this software in question.

It requires you to:

  • include a copy of the license in any redistribution you may make that includes this software;
  • provide clear attribution to us, xerial.org for any distributions that include this software

It does not require you to:

  • include the source of this software itself, or of any modifications you may have made to it, in any redistribution you may assemble that includes it;
  • submit changes that you make to the software back to this software (though such feedback is encouraged).

See License FAQ http://www.apache.org/foundation/licence-FAQ.html for more details.

spatialite4-jdbc's People

Contributors

adnanyaqoobvirk avatar alexdupre avatar blindlf avatar gbatumbya avatar gitblit avatar joelcarranza avatar jturner avatar romank0 avatar sjg5d8 avatar xerial avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.