I am creating a project that has a database (in Access 2016), the problem is that I do not know how to export the database with the executable jar, if it could be done, should I change the path of the base in the code? This is my class'
package Swing.pruebas.SqlFiles;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
public class ConnectDB {
private Connection con;
private Statement smt;
@SuppressWarnings("unused")
private final String controlador;
private final String nombre_db;
private final String usuario;
private final String contraseña;
public ConnectDB(){
this.controlador = "sun.jdbc.odbc.JdbcOdbcDriver";
this.nombre_db = "C:\Users\USUARIO\Desktop\eclipse_java\TutorialesBlog\src\Swing\pruebas\Usuarios.accdb";
this.usuario = "";
this.contraseña = "";
}
public boolean establecerConexion() throws SQLException{
try{
con = DriverManager.getConnection("jdbc:ucanaccess://"+this.nombre_db, this.usuario, this.contraseña);
}catch(SQLException e){
JOptionPane.showMessageDialog(null, "Error al realizar la conexión: "+e);
System.out.println(e);
return false;
}
try{
this.smt = this.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
}catch(SQLException e){
JOptionPane.showMessageDialog(null, "Error al realizar la conexión: "+e);
return false;
}
return true;
}
public ResultSet ejecutarSentencia(String sql) throws SQLException{
ResultSet rs;
rs = this.smt.executeQuery(sql);
return rs;
}
public int ejecutarSentenciaUpdate(String sql) throws SQLException{
int rs;
rs = this.smt.executeUpdate(sql);
return rs;
}
}
Which path should I assign to the variable db_name so that the program can use the DB, on any computer. Will I have to put the DB in the executable JAR exported? The current code does work.