Can I read BerkeleyDB (non-Java-edition) files from Java? - 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.

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.

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.

Ideal data source for Standalone Applications?

Suppose I created a standalone application in java and distributed it through my website.
What I need to know is what is the ideal Database solution I can use so that all the users can use the application without installing anything extra.
For example, if I use SQL server or MySql database, the downloader will need those installed so that I can dump my database on it. Another solution I see is to use Database file like Microsoft Access .mdb file. But that too will need Microsoft Office installed on the client. XML files are platform independent but anyone can open and change them.
What is the solution used by most of the applications?
H2 is a very potent candidate for your need. We use it as a default RDBMS in all our demo applications and also for db-driven unit testing.
You could use an embedded database. There are hundreds for Java some which use SQL and many which don't. Any database you use, you may want the users to be able to maintain, so users editing the data may be a good thing.
You could consider Derby as it ships with Java.
I would use plain flat files which are CSV formatted unless you have a more specific requirement. e.g. you can load and edit them in excel/spreadsheet editor/text editor.
H2 is the successor of HSQLDB (same developer). It is not only one of the finest embedded DBs for JAVA, it is also free, even for commercial use. It's great with hibernate and comes with with a powerful web-interface (you can start it by running the h2 jar file). Additionally there is the possibility to encrypt you database (AES). We use that feature for getting some security aspects right with some of our projects.
check javadb. it is easy and can be redistributed
Firebird can do this : there is an embedded version.
There is some good java drivers
Using MDB files on Windows doesn't require any additional installation requirements such as Microsoft Office. DAO and ADO have come with the Windows OS since Windows 2000.

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.

How can I open a file using java stored procedure

I am using oracle database 10g. I have to write a java stroed procedure through which i can call a file at the server and store it locally at the users machine. Im using oracle Apex 3.1.1.
If you're talking about a true Oracle Java stored procedure, I don't think you can do this. Remember that the Java procedure is running under the Oracle JVM in the database, which means that it can only "see" the database host filesystem.
Any reason it has to be java? DBMS_FILE in PL/SQL should generally work fine.
Otherwise, I think ( I haven't done java stored procedures for a long time ) you should just be able to open an IO stream as you always would in java.
Since you are using APEX 3.1, is there a reason why you can simply create a link to the file on the server through APEX (hence the Web Server) to download the file?
You can also do this through UTL_FILE package, just don't forget to run the CREATE DIRECTORY and grant READ on the directory first.
I think you can do the file open through java as well, but only if you do the grant first to allow the Oracle process access to the directories on your system. This does seem like the most complex method.
Why a Java Stored Procedure? Just because you think it cannot be done in PL/SQL?
There are a couple of FTP implementations in PL/SQL. Sourceforge has one. Tim Hall has published one on his Oracle-Base site.
1: http://sourceforge.net/projects/plsqlftp/ "UTL_FTP project

Categories

Resources