[JBoss] My executeUpdate() working, but not commit

Discussão em 'StackOverflow' iniciado por Stack, Julho 23, 2021.

  1. Stack

    Stack Membro Participativo

    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?

    Continue reading...

Compartilhe esta Página