Reputation: 11
I'm trying to insert data in my postgresql database, but, when I execute the executeUpdate() method, it doesn't insert any data on my DB, and I cannot see where I'm doing wrong...
Ps: My database is autocommit: on;
I'm using Jboss 7.1.1 here my dataSource configuration:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jta="true" jndi-name="java:jboss/datasources/PostgresqlDS" pool-name="PostgreDS" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:postgresql://dataBaseAddress/dataBaseName</connection-url>
<driver>org.postgresql</driver>
<pool>
<min-pool-size>2</min-pool-size>
<max-pool-size>20</max-pool-size>
</pool>
<security>
<user-name>user</user-name>
<password>password</password>
</security>
</datasource>
<drivers>
<driver name="org.postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
Here is my connection class:
public Connection getConnection() throws TopLevelException, SQLException {
Connection conn = null;
try {
Context ctx = new InitialContext();
TransactionBean tal = (TransactionBean) ctx.lookup("java:global/snrng-ear/snrng-ejb-lgc/TransactionBean!br.com.compplied.snrng.ejb.TransactionBean");
conn = tal.getConnection();
} catch (NamingException e) {
throw new TopLevelException(e);
}
return conn;
}
Here is the method that execute my insert
public int inserirHistorico(RetornoHistoricoObject retorno) throws TopLevelException {
int update = 0;
PreparedStatement ps = null;
ResultSet rs = null;
Connection con = null;
String sql = "INSERT INTO table ( column1, column2, column3, column4, column5, column6) values (?, ?, ?, ?, ?, localtimestamp)";
try {
con = getConnection();
ps = con.prepareStatement(sql);
rs = ps.getResultSet();
ps.setString(1, retorno.getNome_arquivo());
ps.setString(2, retorno.getNumero_autenticacao().trim());
ps.setString(3, retorno.getNosso_numero());
ps.setDate(4, retorno.getData_pagamento());
ps.setDouble(5, retorno.getValor());
update = ps.executeUpdate();
} catch (SQLException e) {
throw new TopLevelException(e);
} catch (Exception e) {
throw new TopLevelException(e);
} finally {
try {
close(rs, ps, con);
} catch (SQLException e) {
throw new TopLevelException(e);
}
}
return update;
}
When I execute the ps.executeUpdate() method, is returned to me a success message with the new id inserted, but, when I look for this id on my table, there's nothing inserted there. I've already checked my DB parameter, connection and so, but it's still not working... Can anyone help me?
Upvotes: 1
Views: 10692
Reputation: 1
In order to isolate the problem, try:
Perform a manual insert in the DB to check the autocommit setting? If work - problem in Java. If do not work - problem in DB
Create a simple class to perform the insert and check if it works. It work, problem with app settings. If do not work - FU## something with Java/Driver!
If 1 and 2 work, try to use a Transaction:
Transaction t = beginTransaction(); // session???
//your code here
tx.commit;
Upvotes: 0