How to access the development database with the Play! framework? - java

I want to see the tables of my Play! application with the H2 console, but all I see is a list of internal tables of the db engine. How can I view the tables of my application?

Log on to the JDBC URL jdbc:h2:mem:play instead. That is where the development database runs on at least on my Play instance.

Most likely, you are looking a different database. Could you verify the database URL is really jdbc:h2:~/play?
You should also consider upgrading to a more recent version of H2. The version you are using (1.3.149) is a beta version.

Related

Where to deploy Spring boot application with H2 database

I am working on a web application which will serve as an SQL injection learning platform with multiple levels in spring boot and react. I am using PostreSQL as my main database, but I also wanted a lightweight solution for a vulnerable database on which the injections will occure. I was going to choose H2, but it isn't supported on Heroku where I wanted to deploy my application, as I worked with it in the past and it's already familiar.
So the question is: What other platform could I use to work with H2 or should I choose something else instead of H2, and if yes, what?
The way I handle this is to use spring-bean "profiles"
default
or
!default
I use H2 all the time for local-development mode (using 'default' spring bean profile to achieve this).
Now, we do not over-use spring-profiles. We have default and !default. And that is is.
All my JPA stuff works with H2.

Is there a way to include a SQL/JDBC database in a Java WAR web application so users don't have to set up MySQL?

I have a Java Spring MVC web application.
To run it, users have to install and configure a MySQL database for it to connect to (to load configuration and store user info and so on).
Is there a way to include an SQL database in the WAR file that is ready to use, so users don't have to set up the MySQL database?
You can try using SQLite by following this guide available on baeldung.
In-Memory Database like SQLite or HSQLDB or H2 should be used in case you want the data not to be persisted.

java apps with mysql database

I have prepared an application that is a small demo of Student information manipulation. I have stored information related to students in a MySQL DB. Now my application is working 100% on my computer. But I want that work everywhere without depending on Database! I mean I just want "WHEREVER MY .JAR FILE GOES, DATABASE SHOULD ALSO GO ALONG WITH THAT INSIDE .JAR FILE "
So anyone who is using my application or trying it, they can realize exact result of this application.
How can I make this possible? Please someone help me.
For that I have done the following things:
I have installed MySQL database on my computer.
I have created a database on that MySQL server
I have created some tables in the database with a lots of data.. this data is to be used in my whole application, even for login.
Now I want to deliver this application to various clients but my clients are not technical persons and I don't want to give instructions to each of my client to do the above four steps.
How can I integrate some functionality into my app so that they can use my database, Tables and Data automatically .
It would be much better if the code can install the MySQL database automatically from the setup file attached with the application.
How the applications available in the market manage information
Have you thought of using another database engine?
MySQL requires the server to be installed and configured, and it is a huge task to be done by an automatic installer.
What about using for example SQLite http://www.sqlite.org/ or Apache Derby http://db.apache.org/derby/. Both of them work by creating a file in your working dir, you could setup the database and populate data at install time
I have two suggestions for you:
A. Use SQLite instead of MySQL. SQLite is an embeddable database engine and does exactly what you need. You can simply copy the .sqlite file where all the information is stored and distribute it with your JAR file. Given that you've already written you app to use MySQL, this could mean making a few changes to your code.
There is a good SQLite jdbc driver at:
https://bitbucket.org/xerial/sqlite-jdbc
I've used it before, though not extensively.
B. Use a portable installation of MySQL. If you are using Windows these are available on the MYSQL page, look for the downloads marked "ZIP Archive" instead of "MSI Installer". These versions are portable in that they do not require an installation process, just unzip the file, and start the service. Your clients need to know how to start it up, of course. Perhaps you could create a shortcut for that.
Of course, the idea of MySQL being a network server is so that everyone in the enterprise works with the same data, by connecting to the same server. If your clients will use this application in various computers in the same company, you should consider having a single MySQL Server installed, and making the clients connect to that.
Hope this helps!

Using MySQL 3.x and 5.x simultaneously from Java

How can I use MySQL 3.x and MySQL 5.x simultaneously from my Java application if the two versions need different versions of JDBC drivers but the driver class name is the same?
For MySQL 3.x I downloaded MySQL Connector/J 3.0.17 and for MySQL 5.x I have MySQL Connector/J 5.1.12. How can I use them both?
First check whether (as mentioned by #DaveHowes +1) you can use JDBC driver for v5 with DB v3. It probably works. In this case you have no problem.
If it does not work you have to use separate class loaders for 2 connectors to 2 different DBs. So, neither v5 nor v3 JDBC driver will not be in "regular" classpath of your application. Instead you should create some kind of wrapper that will instantiate its own UrlClassLoader: and start driver. The mentioned collector should expose API that allows you to perform JDBC query. I hope this will work. All this if you are using pure JDBC. If you are using some kind of tools (e.g. Hibernate, iBatis etc.) I wish you good luck :) and suggest to ask more specific question that mentions tool you are using.

Is there embedded DB with PL/SQL support and Java API?

I'm looking for embedded db with Java API for testing purposes.
Also i need pl/sql support because we use oracle in production and migrations are written in pl/sql.
I want to test my DAO objects and i need to create db in memory in process of unit test using migration scripts.
Now we use HSQLDB but it does't support pl/sql.
Can you recommend anything?
According to the wikipedia page about PL/SQL, the databases supporting PL/SQL are Oracle and DB2:
Embedded DB2
Embedded Oracle
If these don't suit you, there's nothing else. PL/SQL is a creation of Oracle, so it's not expected to be widely spread.
You could try installing Oracle XE on your local developer workstation and Continuous Integration server. Then connect with the SYS as SYSDBA or SYSTEM user to create your schema(s) before executing your unit tests.
We use Firebird's pl/sql extensively. It has an embedded server you can access through JDBC.

Categories