Join the database with the java application [duplicate]

0

Hello, I did a college job using java screens using ide netbeans, I made crud in the database, using postgresql as the main bank, I got it done and everything, but I would like to just send the jar to the teacher, in my computer the jar works, but in another it does not find the database, how do I "load" the database with the application?

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;
    }

}
    
asked by anonymous 24.11.2016 / 17:19

1 answer

0

You can use 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 for some other operations.

    
24.11.2016 / 17:30