How to load SpatiaLite extension in JAVA

瀏覽次數:2,387 次
跳到第一則未讀訊息

Thomas

未讀,
2010年3月9日 上午9:14:222010/3/9
收件者:SpatiaLite Users
Dear all,

I want to load libspatialite-1.dll into my JAVA program, but I don't
get it to work properly
So far I've got this:
stmt.executeQuery("SELECT load_extension('libspatialite.dll')");

The error message I get is:

java.sql.SQLException: no such function: load_extension

I've got all the necessary libraries in the C:/windows/system32 folder
and it does work in sqlite3.

Thanks in advance,

Thomas

Thomas

未讀,
2010年3月9日 上午9:18:362010/3/9
收件者:SpatiaLite Users
Just a small addition, there is a small typo in the statement.
libspatialite should be libspatialite-1

Justin Deoliveira

未讀,
2010年3月9日 上午9:22:332010/3/9
收件者:spatiali...@googlegroups.com
Hi Thomas,

You need to ensure that sqlite has been compiled to allow for the
loading of shared libraries (--enable-dynamic-extensions).

I have had good luck using sqlite/spatialite through java with the
xerial jdbc driver:

http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC

-Justin


--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Thomas

未讀,
2010年3月9日 上午10:10:162010/3/9
收件者:SpatiaLite Users
Hi Justin,

I've tried using the drivers from the site you provided (I used a
different driver before). Now I'm getting a different error.

This is my code:

public Database(String host, String database){
makeConnection();
try {
stmt = con.createStatement();
stmt.executeQuery("SELECT load_extension('libspatialite-1.dll')");
} catch (SQLException e) {
e.printStackTrace();
}
}
//create connection
public void makeConnection(){
try{
Class.forName("org.sqlite.JDBC").newInstance();
String url = "jdbc:sqlite:mars3.sqlite";
con = DriverManager.getConnection(url);

}
catch(Exception ex){
ex.printStackTrace();
}
System.out.println("Connection succeeded");
}

And this is the error I'm getting.

[SQLITE_ERROR] SQL error or missing database (not authorized)

I hope you can help.

Thomas

> OpenGeo -http://opengeo.org

Francisco Bosch

未讀,
2010年5月4日 清晨7:48:362010/5/4
收件者:SpatiaLite Users
Hi Thomas,

I'm trying to use spatialite in a java program with the SQLiteJDBC
from the xerial website,
Did you achive use spatialite with java? because I have the same error
than you.

So far I can use sqlite in java but no spatialite.

thanks.
--
Francisco Bosch
--
You received this message because you are subscribed to the Google Groups "SpatiaLite Users" group.
To post to this group, send email to spatiali...@googlegroups.com.
To unsubscribe from this group, send email to spatialite-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spatialite-users?hl=en.

Frans Knibbe

未讀,
2011年9月6日 清晨7:39:202011/9/6
收件者:spatiali...@googlegroups.com
I have the same problem. I have a database that I want to access with C# and java. In C#, I can access the database and use the spatial things provided by SpatiaLite. This is done with the load_extension command. In java, I can access the same database but I have not been able to succesfully load the SpatiaLite extension. Different JDBC drivers give different errors, as described in the earlier messages.

Can someone explain how to connect to SpatiaLite from java?

Andrea P.

未讀,
2011年9月6日 上午8:11:412011/9/6
收件者:SpatiaLite Users


>And this is the error I'm getting.
>
>[SQLITE_ERROR] SQL error or missing database (not authorized)
>
>I hope you can help.
>
>Thomas

Hi,
I have successfully to load_extension using the xerial jdbc driver.

The more troubles I found was to ensure the
libspatialite-1.dll
could find all the dependendies (other dll) it need.
Also pay attention to put the database (the db sqlite) in the right
position.

I guess using
Class.forName("org.sqlite.JDBC").newInstance();
String url = "jdbc:sqlite:mars3.sqlite";

you are refering to where is the JVM.

So perhaps is better use a absolute path for database.

Regards,
Andrea.

Andrea P.

未讀,
2011年9月6日 上午8:13:352011/9/6
收件者:SpatiaLite Users
Hi,
I use this xerial driver:
http://www.xerial.org/maven/repository/snapshot/org/xerial/sqlite-jdbc/3.7.7.1-SNAPSHOT/

is a snapsot, but it is aligned to the sqlite used in the last
spatialite (3.0.0 beta).

Regards.

Frans Knibbe

未讀,
2011年9月7日 上午10:50:422011/9/7
收件者:spatiali...@googlegroups.com
Thanks. By now I have figured out that the problem has to do with me running the 64 version of Windows 7. I was able to get SpatiaLite to work with java on the 32 bit version. I will continue on the thread(s) about Windows 7 64 bit problems. 

Masud Rashid

未讀,
2012年10月15日 凌晨4:36:582012/10/15
收件者:spatiali...@googlegroups.com
Frans knibbe,
Did you solve the problem with Windows 64 bit. I am having trouble with this.

kavimani durai

未讀,
2018年2月14日 凌晨4:01:092018/2/14
收件者:SpatiaLite Users
Please check Java 32 or 64 BIT 
回覆所有人
回覆作者
轉寄
0 則新訊息