Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 906997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:28:43+00:00 2026-05-15T16:28:43+00:00

With SQLite, user defined SQL functions can easily be added using the C api

  • 0

With SQLite, user defined SQL functions can easily be added using the C api or PHP. But is it also possible using Java or Groovy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:28:44+00:00Added an answer on May 15, 2026 at 4:28 pm

    It turns out writing a user defined function is actually quite easy using SQLiteJDBC. Here’s a Groovy example:

    @GrabConfig(systemClassLoader=true)
    @Grab('org.xerial:sqlite-jdbc:3.6.16')
    import org.sqlite.*
    import java.sql.*
    
    db = groovy.sql.Sql.newInstance("jdbc:sqlite::memory:","org.sqlite.JDBC")
    
    // a distance function using the spherical law of cosines
    Function.create(db.getConnection(), "distance", new Function() {
        protected void xFunc() throws SQLException {
            def lat1 = value_double(0)
            def lon1 = value_double(1)
            def lat2 = value_double(2)
            def lon2 = value_double(3)
    
            double theta = lon1 - lon2;
            double dist = (Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))) + 
                (Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta)))
            dist = Math.acos(dist)
            dist = rad2deg(dist)
            dist = dist * 60 * 1.1515
            dist = dist * 1.609344
            result(dist);
        }
    
        def deg2rad(deg) {
          deg * Math.PI / 180.0
        }
    
        def rad2deg(rad) {
          rad * 180.0 / Math.PI
        }
    })
    
    db.execute("CREATE TABLE city(name, lat, lon)")
    db.execute("INSERT INTO city(name, lat, lon) VALUES('New York City', 40.7143, -74.0060)")
    db.execute("INSERT INTO city(name, lat, lon) VALUES('San Francisco', 37.7749, -122.4194)")
    db.execute("INSERT INTO city(name, lat, lon) VALUES('Paris', 48.8567, 2.3510)")
    db.execute("INSERT INTO city(name, lat, lon) VALUES('Cologne', 50.9407, 6.9599)")
    
    db.eachRow("SELECT a.name as a, b.name as b, distance(a.lat, a.lon, b.lat, b.lon) as d FROM city a, city b WHERE a.name != b.name ORDER BY d;") {
        println "Distance from ${it.a} to ${it.b}: ${it.d}km"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In SQLITE there is a possibility to relatively easily create User-Defined Functions and Aggregates
I am making a SQLite database with Java interface where the user can input
I have a user defined function in SQLite (an aggregator that calculates the product)
I'm using an AutoCompleteTextView to suggest user some words from my sqlite db as
User-Defined Functions & Collating Sequences Full support for user-defined functions and collating sequences means
I'm using the sqlite C API. Everything is run in the main function (variables,
i created a user login page with database using SQLite, my requirement is to
I want to retrieve data from sqlite. user can have more than 1 score
I have one sqlite database in which I store both user-defined information and information
The application interact with PHP Classes to get data from MySQL and using SQLite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.