java programming and database connection [closed]

1

I have a problem that is making me miserable. It is as follows:

I have a database and I have my program in java everything connected, I already created the jar strong> and everything.

But the problem is that the program only runs on the machine perfectly on the machine where the database is installed, I would like to know how to ensure that the application will continue to save data without however having the database installed.

Basically I need to know somehow how to load the database along with my application. package bie.trabalho.utilitarios;

import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;

public class ConnexaoOracle {

private String NomeDoUsuario;
private String Senha;
private String Caminho;

private final String host = "localhost";
private final String servico = "xe";
private final String PortaDeEntrada = "1521";


public Connection Connexao;

public ConnexaoOracle(String nome, String Senha) {

    setNomeDoUsuario(nome);;
    setSenha(Senha);
    setCaminho();

}

public void setNomeDoUsuario(String Nome){
    this.NomeDoUsuario =Nome;
}
public void setSenha(String senha){
    this.Senha = senha; 
}
private void setCaminho() {
    Caminho = "jdbc:oracle:thin:@"+host + ":" + PortaDeEntrada + ":" + servico; 

}

public String getSenha()
{
    return this.Senha;
}

public String getNomeDoUsuario() {
    return NomeDoUsuario;
}
public String getCaminho() {
    return Caminho;
}



public boolean Connectar()
{
    boolean vereficadorDeConexao = false;
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
        Connexao = DriverManager.getConnection(getCaminho(), getNomeDoUsuario(), getSenha());
        vereficadorDeConexao = true;

    } catch (InstantiationException | IllegalAccessException
            | ClassNotFoundException | SQLException e) {

        vereficadorDeConexao = false;
    } 
    return vereficadorDeConexao;
}

public ResultSet ExecutarComandoSql(String Comando)
{
    ResultSet Resultados = null ;
    try {
        Statement Comandosql = Connexao.createStatement();
        Resultados = Comandosql.executeQuery(Comando.toUpperCase());


    } catch (SQLException e) {
        System.out.println(e.getMessage());
    }
    return Resultados;  
}

public void commit()
{

    String Comando = "commit";
    ExecutarComandoSql(Comando );

} 

public void rollback()
{
    String Comando = "rollback";
    ExecutarComandoSql(Comando );

}
public boolean Disconnectar()
{
    boolean vereficadorDeDesconexao = false;
    try {
        Connexao.commit();
        Connexao.close();
    } catch (SQLException e) {

    }

    vereficadorDeDesconexao = true;
    return vereficadorDeDesconexao;
}

}

    
asked by anonymous 21.12.2015 / 10:04

1 answer

1

Your need is for an Embedded Database , it's an integrated application bank that also runs alongside the application.

  

As you can see in wikipedia, there are several options, the difference is how   the storage, disk, memory, or   a combination of both, make sure this does not end up losing   data.

Usually in memory it is used in the development environment because it is faster and simpler to test because the data is erased every time the application is closed.

But typically the disk storage mode is what happens in separately installed databases.

Here are some options

21.12.2015 / 13:14