Derby database encoding - java

I found that Derby database is installed with the jdk automatically. I wanted to use bu I encountered a problem for which I could not find the solution in google.
I have a russian version of windows. Derby seems to be installed correctly, but when i start the database itself or sysinfo - it gives me out some info but in some unknown symbols - actually its a mess in cyrillic symbols instead of plain english. When i try to create a database - it throws an exception so I cant connect, but I cant read the message because of the mess in the symbols.
Has anyone had the same problem?
If I dont find the solution, how can I uninstall Derby from the jdk-release and install it locally into another directory?

You can install derby separately by going to http://db.apache.org/derby and downloading the JAR files and adding it to your project class path. I always do this instead of using the default derby that comes with the JDK.
by the way, if you do this and still get those weird symbols, your problem might be elsewhere. Hope you solve this, derby is a cool embedded db :)

You can also use derby as a filesystem DB. Download from here Then in your code, you need to change driver name and connection string accordingly.
For in memory
driver=org.apache.derby.jdbc.EmbeddedDriver
url=jdbc:derby:memory:myDB;create=true
For fileSystem ,
driver=org.apache.derby.jdbc.ClientDriver
url=jdbc:derby://localhost:1527/schema_name;create=true

Related

How to export a jar with its database?

I need to export my project
Im using Eclipse and MYSQL. My project is working fine in IDE and my database is already connected.
The problem is that I don't know how/where should i start?
I read things about like making a file contains manifest.mf, exporting project through runnable jar, maven etc. As a result of reading and searching too much of "how to export it", those things made me more confuse and i don't know what should i do anymore.
What i want to do is for someone on other computer can access my application without opening an ide or sql (is it possible?)
So can someone clarify and give me guide how to export your whole project + database in the most simplest way if possible, because im new to this thing.
Use an embedded database and setup the database in the start of your application.
The main contenders in the java space are HSQLDB, H2 and Apache Derby.
If this is not required by your application it will be an extra hurdle, then evaluate the trade off between changing the application to use an embedded database versus setting up a server to be accessed from the other computer.

How to load multiple sqlite driver versions on a single java server?

The Problem
Hi, I'm trying to implement sqlite in a server plugin, but I'd like to use a different version than is provided with the server - is this possible?
I've set up sqlite in my project, and it works perfectly for most data types, however because of the server's sqlite version, I'm unable to write binary arrays to my database. The server ships with 3.7.2, however this version doesn't support Statement#setBinaryStream, so I'd like to use 3.8.11.2 in my project.
I'm unable to change the server's sqlite version, and it is unlikely that this version will be changed any time soon, so my solution was to try and include a different sqlite version in my project jar, and use that. I'm a big fan of sqlite, so if possible, I'd like to be able to use it.
What I've Tried
I have tried the following:
Use the maven shade plugin to include the sqlite-jdbc library with my project, relocating org.sqlite to me.Fupery.shaded.sqlite
Register my relocated driver with the java.sql.DriverManager singleton:
Driver driver = ((Driver) Class.forName("me.Fupery.shaded.sqlite.JDBC").newInstance());
DriverManager.registerDriver(driver);
Get the connection as usual
Connection connection = DriverManager.getConnection("jdbc:sqlite:" + dbFileURL);
But no luck! The lib is correctly included in my jar, and the code to register the driver (above) runs without exceptions, however when I try to write a byte stream, it throws an AbstractMethodError as usual (indicating it's using the old version, not the one I loaded).
Is there a way to specify which driver to use when getting a connection? I looked through the DriverManager and Driver methods but couldn't find anything I could use.
Alternative Methods
Alternatively, is there another method I can use to write a blob to a database in the server's provided sqlite version (3.7.2)? I tried Statement#setBytes before Statement#setBinaryStream, but I didn't have any luck - no exceptions are thrown, but the column I set the byte to is empty.
A test I wrote here returns without errors, but when I check the database afterwards, the "test" column is empty every time (other data types work fine):
$ SELECT * FROM test_table;
test1|
test2|
test3|
I've decided to use the Statement#setBytes method to write to a blob instead in 3.7.2, now that I've been able to get this to work correctly. It's is a simpler and tidier solution, and works just as well.

Java mysql - It throws me a xml. A jdk/jre issue?

Almost the same question as here.
Class.forName("com.mysql.jdbc.Driver");
conection = DriverManager.getConnection("jdbc:mysql://"+server+"/"+bd, user, password);
So I get the wonderful and fantastic XML when I run it. I used it before (with another server) and it Works ok.
My server it's ok because I tested it with another PC.
I'd say I have update java so I guess there could be the problem, but I have no idea. Could be related with enviroment variables? That specific java version? Btw I have 1.8u45.
I need mysql.
Well, finally I solve it. It wasn't java, nor mysql. It was so easy to see... It was Eclipse:
I have EE Luna version and I don't really know why whenever I clicked run (doesn't matter the Project), it always ran a DocsBlahBlah... file related with mysql ConnectionProperties.
So I deleted that from "Run Config..." and apparently all works fine.
However I'm afraid that will be happening more simply the 1st run config it's the one I need now.

Access Visual FoxPro database from Java

I've been trying to access a Visual Fox Pro database from Java for a week now. I'm getting desperate because my project is in a very tied budget and timeframe. (As any other project, I guess, hahaha)
I have a .dbf, a .cdx and a .fpt files. I need to be able to look for a record, extract data, and update data. I don't have a VFP licence.
I hope someone has some pointers or a working example that I can use. If the only way is buying a driver I'll be willing to consider it based on suggestions received.
This is a short description of what I have tried.
I found this xBaseJ: java objects to read and write to dBase files. But it doesn't suport CDX index files.
Also found this Example to access a dbf. But my tests show this exception: java.sql.SQLException: [Microsoft][Controlador ODBC dBase] La tabla externa no tiene el formato esperado.
I guess a translation to english of this error could be something like: java.sql.SQLException: [Microsoft][ODBC dBase Driver] External table is not in the expected format
Because of that error I think I need a newer driver. In this microsoft page say they no longer have an ODBC driver, and everybody should use OLE DB Provider. The problem is I haven't found a way to use it from java.
As far as I can tell, there is no way to do it directly. Found here someone talking about a JACOB "thingy", and someone comments about the need to create a C++ or C# "something" to be able to do what I need. I think he is talking about The JACOB Project: A JAva-COM Bridge. But I also don't know what COM calls would actually have to make.
Haven't been able to find a suitable JDBC driver.
Thank you all.
Ely.
I found the way to do it.
I ended up using JACOB (from here <= upd 2021-10-25: now here).
Downloaded and installed Visual FoxPro OLE DB driver from http://msdn.microsoft.com/en-US/vfoxpro/bb190232 (upd 2021-10-25: links there do not work anymore). the direct link is: Microsoft OLE DB Provider for Visual FoxPro 9.0 SP2 (upd 2021-10-25: does not work anymore)
Downloaded JACOB version 1.17 binary and source code.
Added jacob.jar as a Java Build Path library
Copied jacob-1.17-x86.dll to the project directory (same place as eclipse's .project file)
Copied jacob-1.17_src\jacob-1.17\samples\com\jacob\samples\ado contents to my src directory and:
Removed the ms directory
renamed test.java to Main.java
Changed the connection string to:
String connectStr = "Provider=vfpoledb;Data Source=C:\\path\\to\\Data\\;Collating Sequence=general;";
Changed the queryStr to match one of the dbf's name
Hope this helps someone else.
Since the jacob approach did not work anymore as described and others seemed to work without the OLE DB bridge, I cancelled trying there and successfully did it via hxtt.com drivers:
register with some email and the mailed link contains some password to get to the drivers page
there one can download the proper driver, e.g. v42 till Java 8 or v43 since Java 9
use the following JDBC settings in your env (e.g. Eclipse Database Explorer) to access your DBF files (e.g. you have some C:\foo\bar.dbf):
driver jar: e.g. DBF_JDBC42_tillJava8.jar
driver class: com.hxtt.sql.dbf.DBFDriver
URL: jdbc:dbf:/c:/foo/
(if required by your tool with dummy values:)
database: db
user/pass: usr / <empty pass>
You may find interesting to use a jdbc driver for foxpro files.
I made some quick tests with this one, and it almost looks like you are using a real database in Java.
Regards,

How to create installer once finished with Java Desktop Application with MySQL DB?

I have finished writing a Java Desktop application with a mySQL database. I want to make the application run outside netbeans and let it be installed on other computers. I know about building the project and creating the runnable jar file, however this requires me to export the database itself to the other computer I want the application to run on.
My question is two parts:
1)Is there a way I can create a setup file that also installs the database and the application together?
2)Also my database path is hard coded, does that mean I have to change the code every time I install my application for someone, what is the better way to do that?
Thanks
Yes. You can use some setup builder, like InnoSetup, for example. Personally, however, I like giving my customers a zip file, which they extract wherever they like. The executable jar should be able to handle everything by itself (I like it where there is no need to install the software, just unpack and run).
If it is hardcoded, then yes (but, what do you mean by hardcoded? path to file? ip address?). You should use properties or configuration files for paths and other external things your software depends on. The software should read from those files. Upon startup check for presence of such file(s) - if missing, the user should be shown a window in which the config can be entered.
As for deploying MySQL with your code - consider using a server for that, so that your users are not forced to install MySQL, instead they connect to it over the net. If you need the database only for storing data locally, why not using SQLite or a similar, file-based db engine?
The above answers are just suggestions and more-less reflect the way I am thinking. I would be happy to hear from someone with more experience. Nonetheless, I hope the answers help a little :)
I agree with Sorrow.
If I have to use MySQL, it is normally over the net since I don't want to allow my clients pass through the hazzles of installing MySQL themselves. If however you am stuck with using MySQL locally, investigate MySQL unattended installations + NSIS Installer.
If you can use any db you want, I just use javadb/derby. It comes bundled with most Java installations these days and if not all you need is to add a jar file to you application.
As per 'hardcoding' paths, I really don't understand what you mean. You really don't have 'paths' as it were, I am assuming what you mean is connection string. You don't have to hardcode your connection string, just put some parameters in a properties file and construct your connection string from them.
1) Is there a way I can create a setup file that also installs the database and the application together?
See my answer to Java based Standalone application.
2) Also my database path is hard coded, does that mean I have to change the code every time I install my application for someone, what is the better way to do that?
Have the DB installer pop a JFileChooser to ask the user where they want to install the DB. Store that path using the JNLP API PersistenceService. Here is my demo. of the PersistenceService.

Categories