restore derby database online - java

From a java application (junit test) I am trying to restore a derby file database. The derby server has been started as a standalone server (so not embedded). I am using the following code.
String url = "jdbc:derby://localhost/V4_0_0/ambikas";
String urlToRestoreFrom = "C:/javadev/workspace/trunk/ambi-kas-lib/derby/V4_0_0_backup/ambikas";
DriverManager.getConnection(url + ";createFrom=" + urlToRestoreFrom);
log.debug("db restored ...");
When I run the code no exceptions are thrown from Derby's side. Everything seems to go fine but no restore has taken place. The directory "url" where I want to restore the db contains the current database. According to the derby documentation this should work however. The restore functionality should replace the current db.
I know there have been some threads before on this topic but none of them seem to solve my problem. I am stuck with it for weeks now.

It's not "createFrom=", it's "restoreFrom=".
See these docs for more information: http://db.apache.org/derby/docs/10.9/adminguide/cadminhubbkup98797.html

Related

connecting with JBOSS EAP to H2 Console (Red Hat - Ticketmonster tutorial )

I'm doing the Red Hat TicketMonster tutorial but got stuck pretty fast.
You can find the tutorial (pdf) here
The problem:
At first everything worked just fine. I managed to deploy the app on localhost, could see the tables using h2console etc.
But when I decided to continue later, I couldn't enter the console like I did before. So I installed the H2 database engine and am able to at least log in but now my tables are gone.
I didn't change anything in the -ds.xml file (just added some Entities in the model package) and use the same url in the database engine.
Maybe the database is locked?
<connection-url>jdbc:h2:mem:test;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url>
I don't know what went wrong and what to do next.
Never mind, found the reason why the connection to h2 console didn't work.
Apparently I didn't deploy the h2console.war in the right folder after changing the runtime server (to Wildfly).

Java DB (Embedded) connection cannot find database

I am trying to create a connection using Java DB (Embedded), but I keep getting the error shown in the image below:
If it helps my Java DB Installation path is: C:\Program Files (x86)\glassfish-3.1.2.2\javadb and my database location is: C:\Users\MyPC\.netbeans-derby
I have tried specifying the file paths, I have watched YouTube tutorials and tried a few examples from Oracle and other sites, none of which help.
The properties (if it helps) for this database are:
I noticed that the driver class is ClientDriver, is it posible this could be playing a role in the problem?
How can I get the Java DB (Embedded) connection to work (or simply correct the problem)?
The root directory doesn't load, find the location on the Database,
eg C:\Users\xxx.netbeans-derby\dataBaseName
copy it and paste it as the database Java DB(Embedded) name. Your new JDBC URL: is now jdbc:derby:C:\Users\xxx.netbeans-derby\dataBaseName
Test the connection and the path should connect.
I think this is a bug in 8.1 and needs to be addressed, but this will work around it.

Embedded Java DB in Netbeans

I have nearly finished a project developing a simple image catalogue application using Java and Netbeans.
I have only now realised that my database is not embedded so when I create the JAR file and try to run it (external to Netbenas) i get an error (error connecting to localhost).
This is the code at present that connects to the database. All works fine when run in Netbeans.
//conect to database
String host = "jdbc:derby://localhost:1527/Catalogue";
con = DriverManager.getConnection(host);
My question is (and I can't seem to find a simple solution) is there a way to just create a new embedded DB with the same name and table and rows etc and then just adjust the code so when i run the JAR file externally to Netbeans all will work OK?
I am imagining the code will be something like:
String host = "jdbc:derby:'path to db'/Catalogue;
Am I on the right track? I have tried this (I think) but it does not seem to work…
Thanks for any assistance
<<<<<< UPDATE >>>>>>>
I have now created an embedded database and created a table (named photos) with exactly the same details as my original (non-embedded) database.
I have changed the connection in the code to be:
String host = "jdbc:derby:catalogueEmbed;create=true";
Now when I run the program in Netbeans it says: "Table/view PHOTOS does not exist"
Do I need to run and sql statement in my code to create the table and row data?
Thanks for any assistance

Apache Derby - Database created but not found

This is in continuation to my previous question
I'm trying to embed a derby database in my web application. I'm able to embed it, though I am facing glitches. Here's the snapshot of my project structure.
I wonder why class.forName("org.apache.derby.jdbc.EmbededDriver") is throwing exception?
java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbededDriver
To overcome this, I have used
DriverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver());
Which works well. Why is it so? Also, Where would it create database if coded like this. I cannot spot the database.
connection = DriverManager.getConnection("jdbc:derby:MyDbTest;create=true");
I checked in tomcat webapps and eclipse workspace, I didn't find database.
If given this way, I can spot it.
connection = DriverManager.getConnection("jdbc:derby:E:/MyDbTest;create=true");
class.forName("org.apache.derby.jdbc.EmbededDriver")
Threw an exception because there is a 'd' missing from embedded.
See here for information about specifying the location of databases on the file system.
connecting to a file-based derby database

Cannot connect to the database with Play framework

I'm building a website with play! framework, I've finished coding and testing with in memory database, and everything was fine, so I decided to push the code to my server. But I encountered with a strange error, it says, "A database error occured : Cannot connected to the database, Unknown database 'fpn_server'".
I did change the application.conf file in conf folder, I set the application.mode to prod(quite sure this has no connection with database), set the db property to "mysql:root:mypass#fpn_server", and jpa.ddl to "create" to make sure the database got created.
Well, to be honest, I developed a demo website with the same database name, and it was successfully deployed on my server. But this time, the schema changed, I did NOT use the evolution scripts as the documentation said, I simply dropped the database from mysql server. Not quite sure if this is the mistake.
I've been googling around for a while, an no good.
BTW, I'm usin play 1.2.4 not play 2.
Can anyone help me? Any suggestion is welcome!
Thanks in advance.
You are using the shortcut MYSQL5 configuration, which appears fine. However, maybe you should try using the verbose settings.
%production.db.url=jdbc:mysql://localhost/fpn_server
%production.db.driver=com.mysql.jdbc.Driver
%production.db.user=root
%production.db.pass=mypass
If there is anything that looks wrong in the verbose settings, this could be responsible for why your shortcut settings are not making sense.
If the configuration looks fine, I would check that your database is accessible.
For reference, here is the application.conf database options - http://www.playframework.org/documentation/1.2.4/configuration#dbconf

Categories