| Persistance external File JPA [message #1703882]
||Wed, 05 August 2015 15:23
| Frithjof Ebert
Registered: August 2015
I've been looking for a solution to a problem for quite some time. I'm writing a program based on data bases. I'm using JPA and in the IDE netbeans the data base is entered via meta-inf / persistance.xml.
But now I want users to be able to use their own data bases with their installations.
Currently my persistance looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="-.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="-//xmlns.jcp.org/xml/ns/persistence -://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="SERVICE" transaction-type="RESOURCE_LOCAL">
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://192.168.112.103:3306/DATABASENAME?zeroDateTimeBehavior=convertToNull"/>
<property name="javax.persistence.jdbc.user" value="DBUSER"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.password" value="PASSWORD"/>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
But I need some possibility for the user to have a config file, which is at the same folder as the JAR to enter his data base.
Namely, username, password, data base name, data base port and server address.
How can I do that? Unfortunally, I have not found anything that worked out yet.
I'm only starting to learn...
Thanks in advace,
|Re: Persistance external File JPA [message #1704877 is a reply to message #1703882]
||Mon, 10 August 2015 11:21
| Reiner Lott
Registered: August 2013
i would solve this problem for your case as follows:
1. Create a gui where the user can enter:
- his database name
- and also the other parameters which are needed "user name" and "password", ...
2. and bypass this arguments included in a map while creating the entitymanagerfactory.
EntityManagerFactory emf = Persistence.createEntityManagerFactory("SERVICE", getRuntimeConfig());
final Map<String, Object> runtimeConfig = new HashMap<String, Object>();
[Updated on: Mon, 10 August 2015 11:23]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.01976 seconds