Use SpatiaLite with Java / JDBC

Hello. As an example of using SpatiaLite, "[Language bindings: Java / JDBC] (http://www.gaia-gis.it/gaia-sins/spatialite-cookbook/html/java.html) "I found (SpatiaLite Cookbook), so I tried running the source (SpatialiteSample.java) SpatialiteThreads.java).

I installed the following as a preparation (using homebrew).

$ brew install sqlite libspatialite
$ brew cask install java
$ wget https://bitbucket.org/xerial/sqlite-jdbc/downloads/sqlite-jdbc-3.16.1.jar

Execution

$ javac -classpath ".:sqlite-jdbc-3.16.1.jar" SpatialiteSample.java
$ java -classpath ".:sqlite-jdbc-3.16.1.jar" SpatialiteSample
SQLite version: 3.16.1
SpatiaLite version: 4.3.0a
target CPU: x86_64-apple-darwin15.6.0
> Inserted 100000 entities of type POINT SRID=4326
> Inserted 100000 entities of type LINESTRING SRID=4326
> Inserted 100000 entities of type POLYGON SRID=4326
$ 
$ ls -ld spatialite-test.sqlite
$ javac -classpath ".:sqlite-jdbc-3.16.1.jar" SpatialiteThreads.java 
$ java -classpath ".:sqlite-jdbc-3.16.1.jar" SpatialiteThreads
start: Slot #0    Thread #0
start: Slot #2    Thread #2
start: Slot #1    Thread #1
...
    stop: Slot #25    Thread #991
    stop: Slot #19    Thread #997
    stop: Slot #57    Thread #1000
$ 

If there is a problem with the operation of sqlite + spatialite, it seems that you should check as follows first.

$ SQLITE3_VERSION=`brew info sqlite | grep /usr/local/Cellar/sqlite | awk '{print $1}'`
$ SQLITE3=${SQLITE3_VERSION}/bin/sqlite3
$ echo $SQLITE3
$ $SQLITE3 -version
$ ( \
echo "SELECT load_extension('mod_spatialite');"  \
echo "SELECT sqlite_version();"  \
echo "SELECT spatialite_version();"  \
echo "SELECT spatialite_target_cpu();" \
) | $SQLITE3
$ 

Recommended Posts

Use SpatiaLite with Java / JDBC
Use JDBC with Java and Scala.
Use Lambda Layers with Java
Use Spring JDBC with Spring Boot
Use java with MSYS and Cygwin
Use Microsoft Graph with standard Java
Use Azure Bing SpellCheck with Java
Use Java 11 with Google Cloud Functions
[JaCoCo (Java Code Coverage)] Use with NetBeans
[Java] Use Collectors.collectingAndThen
Use JDBC Manager with the settings in jdbc.dicon.
How to use Java framework with AWS Lambda! ??
How to use Java API with lambda expression
[JAVA] [Spring] [MyBatis] Use IN () with SQL Builder
Install java with Homebrew
Use ProGuard with Gradle
Change seats with java
Install Java with Ansible
Use Puphpeteer with Docker
Comfortable download with JAVA
Use XVim2 with Xcode 12.0.1
Use CentOS with LXD
Switch java with direnv
Use OpenCV in Java
Use ngrok with Docker
Use webmock with Rspec
Download Java with Ansible
Let's scrape with Java! !!
Use WebJars with Gradle
Build Java with Wercker
Use PreparedStatement in Java
Use jlink with gradle
Endian conversion with JAVA
Use aggregate queries (Count) with Azure CosmosDB Java SDK
Play with Java function nodes that can use Java with Node-RED
Use java1.7 (zulu7) under a specific directory with jenv
Easy BDD with (Java) Spectrum?
Java multi-project creation with Gradle
Getting Started with Java Collection
Use GDAL with Python with Docker
[Java] How to use Map
Use Thymeleaf with Azure Functions
Java Config with Spring MVC
Basic Authentication with Java 11 HttpClient
Run batch with docker-compose with Java batch
[Template] MySQL connection with Java
Install Java 7 with Homebrew (cask)
[Java] JSON communication with jackson
How to use trained model of tensorflow2.0 with Kotlin / Java
Try DB connection with Java
How to use java Optional
Enable Java EE with NetBeans 9
[Java] JavaConfig with Static InnerClass
Try gRPC with Java, Maven
Let's operate Excel with Java! !!
Use Java included with Android Studio to build React Native
Version control Java with SDKMAN
Use Bulk API with RestHighLevelClient
How to use java class
Paging PDF with Java + PDFBox.jar
Sort strings functionally with java