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