H2 tables not showing up in IntelliJ for Jhipster generated project - java

So I generated a new Spring boot application using jhipster. Upon navigating to the H2 console, the following information is shown.
I am able to login, and I can verify tables exist.
Next, I copy the link, jdbc:h2:file:./target/h2db/db/ikdoemee and try to connect to the H2 database using IntelliJ which shows successful.
However, the IntelliJ database view isn't showing any tables.
I tried adding the following parameters to my JDBC url, but no tables show up.
jdbc:h2:file:./target/h2db/db/ikdoemee;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1 ;DATABASE_TO_UPPER=false
Why am I unable to get my tables visible in IntelliJ?
My .h2.server.properties is
#H2 Server Properties
0=JHipster H2 (Disk)|org.h2.Driver|jdbc\:h2\:file\:./target/h2db/db/ikdoemee|ikdoemee
webAllowOthers=true
webPort=8082
webSSL=false
EDIT: My target folder:

You need to activate h2 "Automatic Mixed Mode" by changing the spring.datasource.url of the application-dev.yml file.
example URL: jdbc:h2:./target/h2db/db/'PROJECTNAME';AUTO_SERVER=TRUE
The URL for the connection to the h2 database should look like that:
jdbc:h2:/home/'USERNAME'/IdeaProjects/'PROJECT'/target/h2db/db/'PROJECTNAME';AUTO_SERVER=TRUE
if that doesn't work try also to delete the target folder and refresh the h2 connection

To resolve this issue I installed Buddy JPA plugin.
It created profile automatically and I compared it with mine.
the difference was in parameter DB_CLOSE_ON_EXIT=FALSE
I tried it with manually created profile and it works as well.
The result link is:
jdbc:h2:file:./work/h2db;DB_CLOSE_ON_EXIT=FALSE

The only solution that worked for me at the moment is to put the direct path to the file in Path field without extension.
After that I could see my tables in IDEA.
click to preview settings
Note:
Don't forget to also add parameter AUTO_SERVER=TRUE to datasource.url, as pointed out by #Unknown_Energy.
My apps versions:
Idea 2018.3.5 UE
h2 1.4.197
h2 base name: demo.mv.db
this bug is related to these issues:
Data Source detection
Intellij IDEA and H2 DB file recognition problem

When running the application, the log will show something like
n.w.config.DatabaseConfiguration 1: H2 database is available on port 18080.
Then change Connection Type to Remote and port to the port just showed,
append the db file location to the url (with out extension) just like ./build/h2db/db/projectname, User will be the ProjectName.
The final url will like jdbc:h2:tcp://localhost:18080/./build/h2db/db/projectname
This worked for me, I'm not a English native speaker, sorry for my poor English.

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.

Connecting to a web-hosted database with java

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.

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

Accessing Java DB outside NetBeans

I developed an application with a java db database .I cannot access the database records when I close the netbeans IDE with the message "Error connecting to server Localhost on port..." My connection code to the Database is :
String host="jdbc:derby://localhost:1527/Employee;create=true";
String user="admin";
String pass="admin";
con=DriverManager.getConnection(host,user,pass);
How do I fix the problem?
Netbeans automatically starts the Derby server; you can see that in the "Services" tab (Ctrl-5).
You'll have to start the database server by hand if you don't use Netbeans; see the doc.
Presumably your Derby database is hosted in NetBeans? You'll need to create a standalone database.
You would have to probably start your database before connecting (you are using server mode). Have a look into Vogella tutorial on Derby db connection from java application: http://www.vogella.de/articles/ApacheDerby/article.html
I guess NetBeans has an embedded DB instance.
Try to use
jdbc:derby:/MyFolder/MyDatabase/Employee;create=true
or
jdbc:derby:C:\MyFolder\MyDatabase\Employee;create=true
if you do not need to access the DB from multiple applications.
You can use JavaDB (aka Derby) either by connecting to a JavaDB Network Server or by using it as an embedded DB when your application opens the DB files itself.
Currently, your application is connecting to a Network Server started by NetBeans, as your URL is telling to connect to port 1527 on localhost, i.e. your system.
What you need to do is tell your application to use JavaDB as an embedded database, i.e. it should manage the database itself instead of getting Netbeans to do it instead. You can do this just be changing the URL to something like:
jdbc:derby:Employee;create=true
You may need to tweak that URL depending on where the database files are stored relative to your application's working directory.
Only one application can have the DB open at one time. So when you're doing this NetBeans won't be able to open the database, and if NetBeans has the database open your application won't be able to open it. So you may find you want to reconfigure NetBeans as a DB client.
the simplest way of dealing with these problems is creating batch files..
first of all build your java database program.. the tricky part is to start the server. the jderby is a server so it needs to be started.. that's why you start the server in netbeans. so download db derby files from "http://db.apache.org/derby/releases/release-10.8.2.2.html". after you download these files, copy your netbeans project in those db jderby files.. go and copy your database folders from where they will be saved.. and paste them in the db jderby files.. now open notepad and type
#echo
start (PATH)
start (PATH)
the first path take the path of the file named start network server.bat
the second path take the path of the jar file of your main project.
Now save your the notepad as setup.bat and run the batch file afterward.. and ur program will start the server and running your application at once...
NB: you can use a different name from setup, any of your choice but the extension bat must be available

Categories