How do I load an extension · Issue #908 · xerial/sqlite-jdbc · GitHub
Skip to content

How do I load an extension #908

Open

Description

@whatify-io

Describe the bug
I added memstat extension by copying code from https://sqlite.org/src/file/ext/misc/memstat.c and pasting it in src/main/ext.
Then i did:

  • update makefile with -DSQLITE_DEFAULT_MEMSTATUS=1 -DSQLITE_ENABLE_MEMSTATVTAB=1
  • make native (mine is linux x86_64)
  • mvn package

This produced the jar.

Now I copied the Sample.java, showing relevant section below:

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
 import org.sqlite.core.DB;
import org.sqlite.SQLiteConnection;
    import java.util.Properties;

    public class Sample
    {
      public static void main(String[] args)
      {
        Connection connection = null;
        Properties properties = new Properties();
        properties.setProperty("enable_load_extension", "true");

        try
        {
          // create a database connection
          connection = DriverManager.getConnection("jdbc:sqlite:memory:", properties);
            // sql queries to load extensions
        //  connection.prepareStatement("SELECT load_extension('memstat')").execute(); -> perhaps this is not needed?
          Statement sm = connection.createStatement();
          ResultSet rr = sm.executeQuery("select * from memstat"); -> throws no table , tried sqlite_memstat too
          while(rr.next()) {
                System.out.println(rr.getString("name"));
          }
        

I was able to use a .so file and load that but I want to compile it together as done for extension-functions

Expected behavior
I expected to see memstat table.

Logs
If applicable, provide logs.

Environment (please complete the following information):

  • OS: Linux
  • CPU architecture: x86_64
  • sqlite-jdbc version 3.39.2.0

Additional context
Add any other context about the problem here.

Activity

  1. added
    questionFurther information is requested
    and removed on May 23, 2023
  2. whatify-io commented on May 24, 2023

    @whatify-io
    Author

    Hi can I get some help here would be really great, as this is blocking us from getting sqlite heap stats.
    It would be good to add some example on how to add an extension to src/main/ext and use it.
    I don't know if there is a JDBC way of doing this http://www.sqlite.org/c3ref/db_status.html

  3. whatify-io commented on Jun 23, 2023

    @whatify-io
    Author

    Hello anything someone can come with?

  4. ieugen commented on Jan 22, 2024

    @ieugen

    Hi @whatify-io , did you manage to find a solution to this?

  5. ieugen commented on Jan 22, 2024

    @ieugen

    it seems there is load_extension in JNI to allow loading of extensions.

    Have your tried it @whatify-io ?
    After calling it I imagine sqlite should allow for extension loading - even via SQL function.

  6. sylv256 commented on Oct 2, 2025

    @sylv256

    This is silly. Does anyone have an alternative driver that's maintained by more than one person? Or maybe a contributing guide so I can help make this usable?

    Not being able to load extensions is kind of a huge issue.

  7. gotson commented on Oct 2, 2025

    @gotson
    Collaborator

    This is silly. Does anyone have an alternative driver that's maintained by more than one person? Or maybe a contributing guide so I can help make this usable?

    Not being able to load extensions is kind of a huge issue.

    You just need to use load_extension in a statement.

    UPDATE: To clarify, OP is asking how to include a source file extension in the build. We do not support this as of now. What we do support is runtime loadable extension.

  8. gotson commented on Oct 3, 2025

    @gotson
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions