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
Related
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.
I'm currently working on a project that requires me to connect our Java Project to a SQLite database with jdbc.
We've been using a database.db file located in the main/resources folder for a while without any issues. Now we're trying to switch to a hosted database, because this project is intended for multiple users and so far, we've had to include the database.db file with every git commit.
So, the most obvious first choice would be to instead of using the local resource, link to a hosted file. We have hosted our database.db file on a public server (yeah, yeah, but data security is not relevant for this project) and changed the resource to the hosted file, but it doesn't seem to work and returns "Resource not found" errors. We can't seem to get the syntax right. Here's what we have:
[...]
public Connection connectOrCreateDatabase(String databaseName) throws ClassNotFoundException, SQLException{
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:mysql:http://server.com/"+databaseName+".db");
[...]
Is there any way to get this to work?
Or is http just not supported at all?
Thanks in advance!
No, you can't use it over HTTP and pretend it's on the file system.
Why? You can read the db file over HTTP, but you can't write to it, making inserts and updates impossible.
You need to set it up in server mode and connect to it like a "real" database.
I followed the instructions in this blog to create a basic embedded database application.However, although checking the steps over and over and searching for the problem on the web , I'm still getting the exception : Table view blabla does not exists. Table seems to exists when I expand my driver's app schema. Netbeans version is 7.3.
The most common reason for a table-does-not-exist error with Derby is confusion over the location of the database. The database that you are accessing via Netbeans is probably different than the database that your application is accessing.
The location of your database is controlled by the JDBC connection URL, so if you provide some details about your JDBC connection URL, that might help others to help you.
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
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