Obtener ultimo ID Insertado

"Fernando Aguada" <fernandoaguada-/[email protected]>
Newsgroups gmane.comp.java.javaspain
Message-ID <000e01c9647f$1c6d9e60$ca00a8c0@FERNANDO>
Hola
        estoy dando mis primeros paso con Java, conectando a una BD (Postgresql)
pero no encuentro la manera, si utilizo "getGeneratedKeys", me arroja un error
de "unsupported", y si utilizo esta ultima forma tambien da el error :
"can't use query Methods exception", alguien puede darme una sugerencia?

Saludos !!!

    String cadena = "insert into cliente (numero,nombre) values(?,?)";

        PreparedStatement sentencia = null;
        Statement sentsimp = null;

        try {
            sentencia = conexion.prepareStatement(cadena);

            sentencia.setString(1, unclientevista.txtNumero.getText());
            sentencia.setString(2, unclientevista.txtNombre.getText());

            int filas = sentencia.executeUpdate(cadena);
            
            cadena = "select  lastval() ";
            sentsimp = conexion.createStatement();
            ResultSet rs = sentsimp.executeQuery(cadena); 
     int lastid = rs.getInt(0);
            
            JOptionPane.showMessageDialog(null, lastid, "Error", JOptionPane.WARNING_MESSAGE);


            conexion.close();
            sentencia.close();
        } catch (SQLException e) {

            JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);

        }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.