I have a website written in JSF backed by MySQL database running on Tomcat 7. Now there is only one missing part - project first setup/installation. I want my war when deployed for the first time to offer you installation/first time setup with following steps:
Setup database - enter mysql parameters needed to successfully connect to mySQL server.
Write those parameters into some external file for further use (of course encrypted).
Install database - take a file with SQL inside that creates all the tables in database.
Create first user etc.
Delete installation files.
Similar steps are used in PHP Content Management systems like Drupal. I know perfectly how to work with files in Java. I also know, that I can't change content inside a jar once it's deployed and running, so I have to put my files with SQL and database parameters somewhere else.
My questions are
Where can I put these configuration files to make them readable ? And how ?
Is there another way to achieve this goal ? What is commonly used by Java developers ?
Thank you for your answers.
You can use JPA(Java persistent API) and put all this configuration on persistance.xml and set the schema generation to create Table also the things related to role and user is dependent to application server.
JPA use ORM(object relational mapping) to map between you objects (entity) and database tables
Related
I wanted to create an executable of my java application in eclipse, but instead of having to hosting my database, I wanted to putting inside the application's folders when creating the executable, what do I need to do to accomplish this, and also, what would the path of the class with the code to connect to the database be like?
Thanks in advance.
You cannot do this with MySQL, since MySQL runs in "server mode" only.
To do what you want you would need to change the database to one of the following:
H2. See documentation. URL: jdbc:h2:file:<path>/<database>
HyperSQL. See documentation. URL: jdbc:hsqldb:file:<path>/<database>
Apache Derby. See documentation. URL: jdbc:derby:<path>/<database>
In all three databases the corresponding JDBC driver includes the WHOLE database engine itself. Therefore, just by connecting to the database, you'll get a fully running instance of it.
Now, these databases can work on several modes:
Embedded+File System: the JDBC URL will include a [relative or absolute] path to a directory where the database tables and data are persisted.
Embedded+Memory: the JDBC URL will specify all data will be stored in memory and will be lost once the connection is closed.
Server Mode: the JDBC URL will point to an [external/remote] host:port where the database engine is running. This is similar to MySQL.
According to your question, the first option seems to be the one you need. As a personal note, I find H2 and HyperSQL are easier to set up compared to Derby, since each one comes into a single JAR file.
A database is either located on a user's local machine (for development), or on a server on the internet (for real world use). You could create a Java class that imitates a database, but it's impossible to put a database inside an executable.
I couldn't find an answer to this question. How can I export a Java project that makes use of a PostgreSQL database?
I want to use the same database on another computer. Do I need to export the database itself with the project? How can this be done?
What should the connection URL be, so that the database is accessible on another computer?
I'm using JDBC, and I'm on Windows.
Thanks in advance.
EDIT: Wouldn't I also need to dynamically retrieve the username and password on the other computer, instead of using the specific username and password I have on my computer in PostgreSQL?
It really depends on what you want to achieve.
Shared database between hosts
Do you want the application on both computers to use the same database, so that changes made by one are seen on the other? If so, you need to configure each copy of the application to connect to the same database instance on one of the machines. This is usually done by changing the JDBC URL. You'll need to configure PostgreSQL on the machine that'll be the database server so it allows connections from the other hosts, ensure they can talk to each other over TCP/IP, etc.
Fresh DB on each host
Do you want each install to have a separate instance of the database, so changes made on one have no effect on the other, and where each instance starts out with a blank, empty database (or one with only static contents like lookup tables)? If so, you should generally define the database using SQL scripts, then have the application run the SQL scripts when first installed on a machine. If you've defined the database by hand so far, you can use pg_dump to create a SQL script that you can use as the basis for this, but I really advise you to look into tools like Liquibase for schema management instead.
"Fork" current state
Do you want each instance of the application on a machine to have an independent database, so changes made on one have no effect on other instances on other machines, but where the starting state of an install is what was in the database on the other host? If so, you need to dump and reload the database alongside the application, using pg_dump -Fc and pg_restore. You can automate this within your application / build system using tools like ProcessBuilder, or do it manually.
There's no generic, canned way to do this. It'll require you to define an application deployment procedure, maybe produce an installer, etc.
I have created some mysql databases in mysql.
Now I am trying to get them into my web application by using the play framework.
I added the mysql configs in the application.conf, added the dependency for the mysql driver in the build.sbt, created my first model and added the models packages as the ebean default in the application.conf.
Now when I go into my browser I get this error:
I`m a little confused right now, because I do not want to create a new table, but use the one I created already.
Any idea what I am doing wrong??
Play's default behaviour during development is to manage your database via the evolutions plugin. You define your initial schema in conf/evolutions/default/1.sql and then apply subsequent modifications in 2.sql, 3.sql etc etc. Whenever there are changes to these evolution files the plugin will attempt to run these on the database, which is what you're seeing here (although it looks like an error, it's really just trying to be helpful.)
If you want to manage the schema yourself (and you probably should on a production DB, for example) add evolutionplugin=disabled to the application.conf file.
I read a lot of posts like:
querying embedded database in netbeans using derby
But still I'm having trouble to understand embedded databases.
1) I create a Derby database on Netbeans and I can create tables, link the database to a form and submit the data and update the records with no problem.
2) The problem arises when I want to make the program portable. I apply Clean and Build, then copy the dist folder and also copy the libraries, database, etc ... but when running the program does not recognize the database
3) I read in several places that it is appropriate that the database is created by code using something like
String host = "jdbc: derby: // localhost: 1527 / EmployeesCreateTrue; create = true"
and not creating the database on Netbeans Service...
If I do this procedure with code the database is created but it does not appear or does not allow me to connect from NetBeans and I wish I could fix it to create tables from NetBeans and not from code.
4) I read manuals "how to import a database from Derby to NetBeans" and it doesn't work...
Question: What is the best way to create a database, tables and connect to NetBeans for the final application to be easily portable?
1) Create the database on Netbeans with the wizzard?
or
2) Just plain code on the application?
I don't understand precisely what you mean by "the database is created but it does not appear."
I think if you were to explain that precisely, the community could probably help you.
There are three common reasons for "table does not exist" when you think you've created the tables; I've explained those cases in this answer: Is it necessary to create tables each time you connect the derby database?
Please let us know more information about your situation so that we can help you better understand the behavior of your application.
I'm not 100% sure if this is your problem, but a lot of problems people seem to have with Netbeans and Derby seems to come from the fact that they don't set derby.system.home explicitly. When you don't, Derby stores databases in the current directory, and that is likely different when working in the IDE, either in the Services tab, or your own code, than when you execute your app's jar as a standalone program. So the advice (which you will also find in the manual) is: always set derby.system.home. An alternative would be to use full paths to the databases, but that rarely works well for a real application that is deployed on different machines.
I had the same problem --had the derby db in the services but the netbeans coded programs didn't access it. I solved it by adding the derby database (copy paste) to the package in the Files section. I use Windows 7. Once I did that, I was able use multiple tables (before netbeans just ignored secondary tables and only allowed me to use the primary table).
I am working on collabnet subversion repository. I installed CollabNetSubversionEdge-4.0.6_setup-x86_64 software and I created users in Collabnet GUI to access my repository. And I and my users accessing my repository and everything is working fine.But,
Here my task is Insted of creating users in Collabnet Create users in Data base(MySql or Oracle) and make them to lo-gin from our DataBase to access collabnet
I googled a lot but I didn't get even a single answer for this one.May be this is not possible. If it possible please tell me how to achieve this one.Thank you very much.
Subversion passes off security to its servers. If you use Apache httpd (you don't specify), you can use whatever Apache configurations to do user access. The two most common is LDAP (which can connect to your Windows Active Directory server) and using a text based httpasswd to generate a user password file. I have not seen this with SQL, and I couldn't imagine why you'd want to use something so complex for something so simple -- unless you already store users in a SQL database.
If nothing else, you could have a crontab that would build the svn_access_file via a SQL query that runs it through httpasswd.
There is some information from Oracle on this, but I have never seen it done, and Apache httpd's documentation doesn't have specific directions.