Introduction
I'm developing an application and I have to add data to an oracle database that is local. Using JDBC I make the connection
try (Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@" + conexao + ":1521:xe", "system", "root")){
System.out.println("Conectado a "+conexao);
return (Connection) conn;
}
Connection is successful. Now I need to do the insertion. I have the following code:
PersonaDAO.java
public void insert(String conexao) throws SQLException{
// Instancia classe de conexão
Connection conn = ConnDb.getConnection(conexao);
String query = "insert into TESTE2 (TITLE) values('asd')";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
stmt.execute();
conn.commit();
}catch(SQLException e){
System.out.println(e.getMessage());
}
}
And what's triggered when you click a button
String conexao= localConexao.getText();
try {
p = new PessoaDAO();
p.insert(conexao);
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
Error
It falls into a SQLException
not doing the insertion.
Closed Connection