2
I have a Java application that uses Hibernate, for development I made the database configuration using localhost but for use on other computers I will need to define the IP that will have the database (Server) in my project I use the file Persistence.xml
I thought through a home screen, the user register the IP of the machine in a configuration file created in the installation.
But now I come across the situation of having to inform to Persistence which IP informed in the file created by the installation process.
Follow the example of my Persistence below.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="ConexaoPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>br.com.exemplo.modelo.Exemplovenda</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/conexao?zeroDateTimeBehavior=convertToNull"/>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
did not understand the question, you made the database on localhost and want to add to an external server?
– haykou
for development I created a local database, even in the configuration I used the localhost, but for production I need to inform externally what is the IP of my server.
– DevAgil
Have you tried replacing localhost with your IP with the database? For example //meuip.com:port/nameBD ?
– haykou
yes, and it works without problems, only I do not know if in the client it will keep the same ip that I fixed in the programming, in this case I get very tied.
– DevAgil