Feedback

No olvide que también tenemos una biblioteca con fragmentos de código, http://snippets.dev-co.org _\../

Close

what's your question? be descriptive.

By: Asked from Colombia

problema con java y sql

Java Tengo una excepcion java.sql.SQLException: ResultSet close con el siguiente codigo:

public String getString(String table, String column, int id) {
    String string = "Error";
    try {
        Statement stmt = dbConnection.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT " + column + " FROM " + table + " where id = " + id);
        string = rs.getString(column);
        rs.close();
    } catch (SQLException ex) {
        Logger.getLogger(DbTask.class.getName()).log(Level.SEVERE, null, ex);
    }
    return string;
}
  • 1

xphree

Para poder ayudar por favor incluir mas información al respecto.

Una buena práctica respecto a los close es hacerlas en el bloque finally

    ResultSet rs = null;
    try {
     rs = stmt.executeQuery(....);
    } catch(SQLException ex) {
         // Log Exception
    } finally {
         if(rs != null) {
              rs.close();
          }
    }
or Cancel