3
Introducing
I am developing an application and have to add data to an oracle database that is local. Using JDBC I connect
try (Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@" + conexao + ":1521:xe", "system", "root")){
System.out.println("Conectado a "+conexao);
return (Connection) conn;
}
Connection is made successfully. Now I need to insert. I have the following code:
Personal.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 is triggered when clicked on a button
String conexao= localConexao.getText();
try {
p = new PessoaDAO();
p.insert(conexao);
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
Error
He falls into a SQLException
not making the insertion.
Closed Connection
@That’s what Caffe was! Thank you =)
– ralfting