SQLite issue in OS X - java

I am using SQLite in my project. Everything works fine in windows, but in OS X I get error as:
Caused by: java.lang.UnsupportedOperationException: Pure Java mode disabled!
at org.sqlite.JDBC.(JDBC.java:34).
What can be the reason for it?

Java has the ability to run as a wrapper around existing C libraries. They refer to these as "native libraries". This is handy for a project like SQLite that already has libraries written in C, you don't have to rewrite everything just for Java.
"Pure Java mode" means it is running only Java code and no native libraries. Usually you do this only if the native library is missing. I don't know why it would be disabled.
Either SQLite JDBC driver is mistakenly not seeing the SQLite library (for which there is an open bug), or you're missing the native/C SQLite library. According to these instructions, you might be able to configure the library manually to use the native library with sqlite.purejava=false.

Related

Can I use MySQL from AWS Lambda in Python?

Is the MySQL connector for Python or some equivalent module available in a form I can zip up and included in an AWS Lambda function, or is that just asking for trouble? Apparently Lambda functions written in Node.js can use a builtin library to talk to MySQL on RDS, but I don't see an obvious way to do that in Python.
I wouldn't want to try to install something that takes a long time or requires any assumptions about the underlying operating system. On Windows at least, it's a whole separate installer.
Same question for Java: does this work out of the box, or are there machinations necessary to package a MySQL jar file?
If in some cases you need to uses native library (which mysql should have), you can uses pure python implementation using PyMySQL, and include it in the deployment package of lambda.
More detail on how to create deployment package for python is here https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html
See the advanced version.
For java, I guess it will work out of the box as long as you include all dependency in jar.
I think I got it. Being on Windows added some steps.
I got Python 2.7.10, which comes with Pip. I then installed mysql-connector-python using the trick here.

Is SQLite the most appropriate thing to use for an embedded database? [duplicate]

This question already has answers here:
Java and SQLite [closed]
(9 answers)
Closed 7 years ago.
I need to build a Java application that I will install on a Linux server.
When people will install they just would need to install this application, launch it, and nothing more. But we have some data to save.
I said no to MySQL, because it needs a server.
I said no to XML because there will be really a lot of data to save and manipulate.
So I'm looking at SQLite which is the best I think. Indeed (stop me if i'm wrong), SQLite doesn't need any server? (just install the final application and SQLite works fine in my application?)
Then I checked at http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers and I'm really a little bit confused.
What is the difference between a Wrapper and a Driver?
Plus I see there exists a "pure java implementation": SQLJet is it more or less optimized?
Finally what would you use in my situation?
Another database to consider is H2. It is an embedded database engine completely written in Java so you have the benefit of full unicode (16 bit) character support that Sqlite does not have. Other embedded databases are HSQLDB and Derby.
sqlite doesnt need any requirement on the server ?
Correct. It does not. Neither does H2.
just install the final application and sqlite works fine in my application ?
Correct. As long as you include Sqlite or H2 in your WAR (or unpack it into your jar), it will work fine.
What is the difference between a Wrapper and a Driver ?
Depends on the usage. I think Sqlite is talking about the fact that when you use the JDBC driver for Sqlite, it is actually a wrapping of the Sqlite C native libraries inside the driver. Typically the JDBC driver talks to a remote database.
H2 also is that way with the "driver" actually doing the database operations just that it was written in Java so you don't need the C wrapper.
Plus I see there exists a "pure java implementation" : SQLJet is it more or less optimized?
This is the first I've heard of Sqljet so I'm not sure. The Xerial Sqlite driver is what I've used and it's performance seems to be good.
Finally what would you use in my situation?
I'd use H2 myself for the native Java features.
Yes SQLite doesn't require a server.
One very simple solution for development is using SQLLite by embedding it in your source code, with a little stub data. You can then commit your database to your version control system (i.e. I use github, its super easy to do this) as a single file. This is, obviously, not a good production method, but it is a good way to create a single development version.
A Wrapper is a program which facades another program by allowing you to access its functionality through a different interface. For example, eclipse "wraps" many java programs that we use in everyday development for us in a convenient GUI. Whereas a Driver is a program that is needed to launch an existing application. For example, in a java application, we might have a main class that can be thought of as a Driver for entry point to the application.

Where do you get the sqlj libaries for java?

I've been charged with writing a DB manipulator with java for a project.
My professor gives us material that says to use the sqlj library (Oracle I'm assuming?), but nobody explains where it comes from or how do download it.
I've been looking for hours now.
The SQLJ site?
http://www.sqlj.org/
Unless you mean the executable, but I'm not sure what that is:
http://www.oracleutilities.com/OSUtil/sqlj.html
The jars you're looking for are in Oracle Database Client. You can download it here: http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
SQLJ is not a library, it is a language extension - this means you'll have to use a preprocessor to compile your java code to .sqlj files, which can then be executed. It's not as simple as including a library.
this might get you started - you will need an Oracle environment on your machine though, I'm not sure if it's freely available
You can download DB2 Express-C and compile your SQLj classes, generate the java files, and access plans for the database.
Usually when you look for libraries, try typing: library-name maven repository, that will usually give you the right library, if not - that means "The library is kinda unusable and there are lots of better tools".
P.S.: Don't listen to your professor, just do it using standard JDBC or JPA.

Can I read BerkeleyDB (non-Java-edition) files from Java?

I need to read BerkeleyDB files from Java.
Oracle has an official Java Edition of BerkeleyDB, but it seems that this uses its own, incompatible binary file format.
What do I do?
According to the Wikipedia page, there are Java bindings for classic Berkeley DB, but they require use of JNI and a native library. Here's a link to the Sleepycat Berkeley DB - Java API documentation.
Berkeley DB can actually store data in 2 different formats, depending on whether you elect to use the SQL API or not. The SQL API is a recent addition, Berkeley DB has historically been a key/value database.
It is true that you need to build the native library and use JNI, but this is to be expected if you want to access files created by a native library. Fortunately, the build process is very simple.
If you are building under Windows, please refer to the installation guide.
For Linux or other *NIX, after you have untarred the file go to the build_unix directory and do one of the following:
If you are using the (standard) key/value interface:
../dist/configure --enable-java --prefix=/usr/local/db
make install
If you are using the SQL API:
../dist/configure --enable-sql --enable-jdbc --prefix=/usr/local/db
make install
(Obviously you can replace --prefix with the install location of your choice)
For more information see the docs page.
Hope that helps, good luck with your project.

Is there a driver for SQLite in Java?

I did some research on their site, and after some Google-ing, it looks like there are only drivers for C & C++. Is there an open driver that I can use with SQLLite, or is there a way I can use it with JDBC?
UPDATE
I'm doing development on Linux, but I would like to keep my options open. Native libraries would work, but wouldn't give the cross-platform freedom that I'm used to with Java.
I have used org:xerial:sqlite-jdbc
Example Groovy script:
#Grab(group='org.xerial', module='sqlite-jdbc', version='[3.6.4,)')
sql = groovy.sql.Sql.newInstance("jdbc:sqlite:test.db","org.sqlite.JDBC")
sql.execute("create table students(name, age)")
(note: 3.6.4 is not the latest version)
SQLite JDBC is completely written in Java, so there are no external dependencies.
SQLite is a native library - therefore a platform independent solution is not that simple. The SQLiteJDBC project uses a internally complex but working system for accessing SQLite database platform independent (on most platform with a good speed). As the name implies it can be used via JDBC (see code sample on the main page).
If you only need one specific platform you can also use the SQLite Java wrapper. For windows there are pre-compiled binaries; sources are also available.
There is also SQLJet, which is a pure java impl which is compatible with sqlite.

Categories

Resources