Merge database with java application

Asked

Viewed 772 times

0

Hello, I did a college job using java screens using the ide netbeans, crud the database ,using postgresql as the main database, I was able to finish and everything, however I would like to send only the jar to the teacher, on my computer the jar works, but in another it does not find the database, how do I "load" the database with the application? Obg

my connection

public void Conectabd() throws ClassNotFoundException {
    conectdbd();
    CriarBd();
}

public static Connection conectdbd() throws ClassNotFoundException {

    try {
        Class.forName("org.postgresql.Driver");
        Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:3306/bdoficina", "postgres", "diego");
        return con;
    } catch (SQLException error) {
        JOptionPane.showMessageDialog(null, error);

        return null;
    }

}
  • 3

    I believe that there is no way, only if you were using a "portable" bank, such as sqlite, hsqldb.

  • Unless you pay a hosting postgree, and put the bank on the internet.

  • would like the local bank even , has no other type of bank that already integrates the application no?

  • 1

    Yeah, I mentioned two options, but you’d have to rewrite all the tables for him.

  • I recently made an application in Delphi having Postgresql with BD, and used a file .ini to make this connection with the bank, so in my connection file I put as host the IP of the machine where the bank was saved, another thing I had to change was the file pg_hba.conf in order to be able to access my BD from another machine, but of course this will only work if the computers in question are on the same network in the case

  • @R.Santos I believe that this is not the case. Note that it will send the work to the teacher, it can open anywhere, it will not work, unless he has an online hosting bank, or set up a dynamic dns to redirect to his pc, which should be on all the time, without counting connection problems that may occur too.

  • @diegofm It’s true, I had not connected to that part of the question when I made the comment

Show 2 more comments

1 answer

0

You can use the Sqlite.

After installing the JDBC driver, you can try something like:

import java.sql.*;

public class SQLiteJDBC
{
  public static void main( String args[] )
  {
    Connection c = null;
    try {
      // Cria conexao
      Class.forName("org.sqlite.JDBC");
      c = DriverManager.getConnection("jdbc:sqlite:test.db");
    } catch ( Exception e ) {
      System.err.println( e.getClass().getName() + ": " + e.getMessage() );
      System.exit(0);
    }
    System.out.println("DB aberto com sucesso");
  }
}

See also here some other operations.

Browser other questions tagged

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