How to run a . jar using java jdbc on another machine

Asked

Viewed 522 times

0

I’m a beginner in java, I made an application using the netbeans native database. Gero the file jar, and in the machine I made the application the jar runs normally, but when I put this jar on another machine it just opens, plus when it arrives at the part that makes the connection in the bank (example when I click the sign up button, the register, and not even list) it just doesn’t open.

I wonder how I do to run on another machine, like it was done on windows 10, and want to run on windows 7.

  • 3

    Welcome to Stack Overflow! For the community to help you, it’s important to explain your problem in detail. It would be interesting to attach an Error Log to make it easier! I suggest you read the articles: Tour and how to ask a question.

  • How are you making the connection and how does the bank generate in the app? Add the code there, netbeans creates a local only connection to your computer, the Uri will be invalid in another.

  • public class Dao {&#xA; // private static List<Usuario> banco = new LinkedList<Usuario>();&#xA; EntityManagerFactory emf= Persistence.createEntityManagerFactory("Aplica__oPU");&#xA; EntityManager em =emf.createEntityManager();&#xA; EntityTransaction etx = em.getTransaction();

  • public void salve(Object o){ etx.Begin(); em.merge(o); etx.commit(); } public remover(Object o){ etx.Begin(); em.remove(o); etx.commit(); } public List list list(The){ Query q = in.createQuery("SELECT the FROM "+o.getSimpleName()+" the"); Return q.getResultList(); }

  • I don’t know if I can understand it, but this is the code I use to connect to the database, and I use a class percistencia.xml

  • @Endersoncesar, could you update your question with the connection parameters you use? Most likely you are connecting on localhost (because you are developing on your machine). When you distribute your application, you need to switch localhost to the IP (or DNS) of the machine where the database is located.

  • hello I’m using the path, jdbc://debylocalhost:1127/sample[app in APP], this is the path of the bank in my machine, but I’m trying to run the jar in just a machine, I have to change this path?

Show 2 more comments

1 answer

-1

In the scenario you are reporting, the machine you want to run your jar must be on the same network as the machine containing the database.

So, at the site you used the localhost in its connection configuration, the IP of the machine containing the database will be passed.

An example:

  • Machine 1 (database): IP: 10.3.1.100
  • Machine 2 (jar): IP: 10.3.1.102

So that Machine 2 can communicate with Machine 1 on its persistence.xml, it will be necessary to configure the property responsible for the url as follows:

<property name="javax.persistence.jdbc.url" value="jdbc:meu_sgbd://ip_maquina_1/minha_base_de_dados" />

Note: Do not forget to inform the port used by the DBMS.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.