public void logBatchUpdateExceptions(Throwable t) { while (!(t instanceof SQLException)) { t = t.getCause(); if (t == null) { return; } } SQLException sqle = (SQLException) t; // If the SQLException is the root chain the results of getNextException as initCauses if (sqle.getCause() == null) { SQLException nextException; while ((nextException = sqle.getNextException()) != null) { sqle.initCause(nextException); sqle = nextException; } } // The SQLException already has a cause so log the results of all getNextException calls else { while ((sqle = sqle.getNextException()) != null) { this.logger.error("Logging getNextException for root SQLException: " + t, sqle); } } }
/** Creates a Pooled connection and adds it to the connection pool. */ private void installConnection() throws EmanagerDatabaseException { logger.debug("enter"); PooledConnection connection; try { connection = poolDataSource.getPooledConnection(); connection.addConnectionEventListener(this); connection.getConnection().setAutoCommit(false); synchronized (connectionPool) { connectionPool.add(connection); logger.debug("Database connection added."); } } catch (SQLException ex) { logger.fatal("exception caught while obtaining database " + "connection: ex = " + ex); SQLException ex1 = ex.getNextException(); while (ex1 != null) { logger.fatal("chained sql exception ex1 = " + ex1); SQLException nextEx = ex1.getNextException(); ex1 = nextEx; } String logString; EmanagerDatabaseException ede; logString = EmanagerDatabaseStatusCode.DatabaseConnectionFailure.getStatusCodeDescription() + ex.getMessage(); logger.fatal(logString); ede = new EmanagerDatabaseException( EmanagerDatabaseStatusCode.DatabaseConnectionFailure, logString); throw ede; } }
public int guardarProducto(Producto producto) { Statement stmt = null; Connection conn = null; int registrosInsertados = 0; try { conn = super.getConection(); stmt = conn.createStatement(); registrosInsertados = stmt.executeUpdate( "INSERT INTO productos_aplicables (productos_id, denominacion, precio) " + "VALUES (" + producto.getIdproducto() + " , '" + producto.getDenominacion() + "' , " + producto.getPrecio() + ")"); } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } try { stmt.close(); conn.close(); } catch (SQLException e) { while (e != null) { e.printStackTrace(); e = e.getNextException(); } } } return registrosInsertados; }
public int modificarCuota(Cuota cuota) { Statement stmt = null; Connection conn = null; int registrosInsertados = 0; try { conn = super.getConection(); stmt = conn.createStatement(); System.out.println( "UPDATE cuotas " + "SET monto = '" + cuota.getMonto() + "' , pagado = '" + cuota.isPagado() + "', facturas_serie = '" + cuota.getSerieFactura() + "', facturas_numero = '" + cuota.getNumeroFactura() + "' " + ", productos_id = '" + cuota.getProducto().getIdproducto() + "' " + "WHERE cuotas_id = " + cuota.getId()); registrosInsertados = stmt.executeUpdate( "UPDATE cuotas " + "SET monto = '" + cuota.getMonto() + "' , pagado = '" + cuota.isPagado() + "', facturas_serie = '" + cuota.getSerieFactura() + "', facturas_numero = '" + cuota.getNumeroFactura() + "' " + ", productos_id = '" + cuota.getProducto().getIdproducto() + "' " + "WHERE cuotas_id = " + cuota.getId()); } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } try { stmt.close(); conn.close(); } catch (SQLException e) { while (e != null) { e.printStackTrace(); e = e.getNextException(); } } } return registrosInsertados; }
public Collection<Cuota> getCuotasAlumnoInscripcion(long idAlumno, long idInscripcion) { ResultSet resu = null; Statement stmte = null; Connection conne = null; try { conne = super.getConection(); stmte = conne.createStatement(); resu = stmte.executeQuery( "SELECT cuotas_id, periodo, alumnos_id, inscripciones_id, monto, pagado, facturas_serie, facturas_numero, cuota, productos_id FROM cuotas " + "where pagado = false " + "AND alumnos_id = '" + idAlumno + "' " + "AND inscripciones_id = '" + idInscripcion + "'"); } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } Collection<Cuota> co = new ArrayList<Cuota>(); try { while (resu.next()) { Cuota c = new Cuota(); c.setId(resu.getLong(1)); c.setPeriodo(resu.getTimestamp(2)); c.setIdAlumno(resu.getLong(3)); c.setInscripcion(resu.getLong(4)); c.setMonto(resu.getDouble(5)); c.setPagado(resu.getBoolean(6)); c.setSerieFactura(resu.getInt(7)); c.setNumeroFactura(resu.getLong(8)); c.setCuota(resu.getBoolean(9)); c.setPago(this.getPago(c.getId())); c.setProducto(this.getProducto(resu.getInt(10))); co.add(c); } } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } try { resu.close(); stmte.close(); conne.close(); } catch (SQLException e) { while (e != null) { e.printStackTrace(); e = e.getNextException(); } } return co; }
/** Flushes the batch */ public void flush() throws SQLException { try { preparedStatement.executeBatch(); preparedStatement.clearBatch(); } catch (SQLException e) { String details = e.getNextException() == null ? "" : e.getNextException().getMessage(); throw new SQLException(e.getMessage() + "\n\n" + details); } }
private String getErrorMessage() { if (rootCause instanceof SQLException) { SQLException sqle = (SQLException) rootCause; if (sqle.getNextException() != null) { return sqle.getNextException().getMessage() + Config.NEWLINE + rootCause.getMessage(); } } return rootCause.getMessage(); }
/* * Method test for getNextException */ public void testGetNextException() { SQLException aSQLException; String[] init1 = {"a", "1", "valid1", "----", null, "&valid*", "1"}; String[] init2 = {"a", "1", "valid1", "----", "&valid*", null, "a"}; int[] init3 = {-2147483648, 2147483647, 0, 48429456, 1770127344, 1047282235, -545472907}; SQLException[] init4 = { new SQLException(), null, new SQLException(), new SQLException(), new SQLException(), null, new SQLException() }; SQLException theReturn; SQLException[] theReturns = init4; String[] theFinalStates1 = init1; String[] theFinalStates2 = init2; int[] theFinalStates3 = init3; SQLException[] theFinalStates4 = init4; Exception[] theExceptions = {null, null, null, null, null, null, null}; int loopCount = init1.length; for (int i = 0; i < loopCount; i++) { try { aSQLException = new SQLException(init1[i], init2[i], init3[i]); aSQLException.setNextException(init4[i]); theReturn = aSQLException.getNextException(); if (theExceptions[i] != null) { fail(i + "Exception missed"); } assertEquals(i + "Return value mismatch", theReturn, theReturns[i]); assertEquals(i + " Final state mismatch", aSQLException.getMessage(), theFinalStates1[i]); assertEquals(i + " Final state mismatch", aSQLException.getSQLState(), theFinalStates2[i]); assertEquals( i + " Final state mismatch", aSQLException.getErrorCode(), theFinalStates3[i]); assertEquals( i + " Final state mismatch", aSQLException.getNextException(), theFinalStates4[i]); } catch (Exception e) { if (theExceptions[i] == null) { fail(i + "Unexpected exception"); } assertEquals(i + "Exception mismatch", e.getClass(), theExceptions[i].getClass()); assertEquals(i + "Exception mismatch", e.getMessage(), theExceptions[i].getMessage()); } // end try } // end for } // end method testGetNextException
/** * 例外チェーンをたどって原因となった{@link SQLException SQL例外}を返します。 * * <p>例外チェーンにSQL例外が存在しない場合は<code>null</code>を返します。 * * @param t 例外 * @return 原因となった{@link SQLException SQL例外} */ protected SQLException getCauseSQLException(Throwable t) { SQLException cause = null; while (t != null) { if (t instanceof SQLException) { cause = SQLException.class.cast(t); if (cause.getNextException() != null) { cause = cause.getNextException(); t = cause; continue; } } t = t.getCause(); } return cause; }
private static void dumpSQLExceptions(SQLException se) { System.out.println("FAIL -- unexpected exception: " + se.toString()); while (se != null) { System.out.print("SQLSTATE(" + se.getSQLState() + "):"); se = se.getNextException(); } }
@Override public void prepare() throws IOException { LOG.debug( "Preparing JDBC resource source (resource={}, table={})", profile.getResourceName(), script.getTableName()); try { this.resultSet = prepareResultSet(); } catch (SQLException e) { for (SQLException ex = e; ex != null; ex = ex.getNextException()) { WGLOG.error( ex, "E03001", profile.getResourceName(), script.getName(), script.getTableName(), script.getColumnNames()); } throw new IOException( MessageFormat.format( "Failed to prepare JDBC source (resource={0}, table={1}, columns={2})", profile.getResourceName(), script.getTableName(), script.getColumnNames()), e); } LOG.debug( "Creating ResultSet support {} for {}", script.getSupport().getClass().getName(), script.getColumnNames()); support = script.getSupport().createResultSetSupport(resultSet, script.getColumnNames()); }
@Override public void Insert(UsersFriends usersFriends) { // SQL // INSERT INTO UsersFriends (VkID_User, VkID_Friend) VALUES (usersFriends.getVkIDUser(), // usersFriends.getVkIDFriend()); String SQL = ""; try { this.dbHandler.openConnection(); Statement statement = this.dbHandler.getConnection().createStatement(); SQL = "INSERT INTO UsersFriends (VkID_User, VkID_Friend) VALUES (\"" + usersFriends.getVkIDUser() + "\",\"" + usersFriends.getVkIDFriend() + "\")"; statement.executeUpdate(SQL); } catch (SQLException ex) { System.out.println("SQLException caught"); System.out.println("---"); while (ex != null) { System.out.println("Message : " + ex.getMessage()); System.out.println("SQLState : " + ex.getSQLState()); System.out.println("ErrorCode : " + ex.getErrorCode()); System.out.println("---"); ex = ex.getNextException(); } } catch (Exception ex) { System.out.println("Other Error in Main."); } }
public DataBaseManagement(String driver, String dbURL) { try { this.dbURL = dbURL; Class.forName(driver).newInstance(); conn = DriverManager.getConnection(dbURL); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException e) { // TODO Auto-generated catch block if (e instanceof SQLException) { SQLException sqle = (SQLException) e; if (sqle.getSQLState().equals("XJ040")) { sqle = sqle.getNextException(); if (sqle.getSQLState().equals("XSDB6")) { logger.error(sqle.getMessage() + " Please shutdown that other instance of Derby."); } } } else { CustomException.errorPrint(e); } } }
public static void main(String args[]) { try { String urlBD = "jdbc:odbc:FOSA"; String usuarioBD = "SYSDBA"; String passwordBD = "masterkey"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conexion = DriverManager.getConnection(urlBD, usuarioBD, passwordBD); Statement select = conexion.createStatement(); ResultSet resultadoSelect = select.executeQuery("SELECT MAX(NUM_REG) AS numreg FROM FACT01"); System.out.println("COMANDO EXITOSO"); System.out.println("numreg"); System.out.println("------"); int col = resultadoSelect.findColumn("numreg"); for (boolean seguir = resultadoSelect.next(); seguir; seguir = resultadoSelect.next()) System.out.println(resultadoSelect.getInt(col)); resultadoSelect.close(); select.close(); conexion.close(); } catch (SQLException ex) { System.out.println("Error: SQLException"); while (ex != null) { System.out.println( (new StringBuilder()).append("SQLState: ").append(ex.getSQLState()).toString()); System.out.println( (new StringBuilder()).append("Mensaje: ").append(ex.getMessage()).toString()); System.out.println( (new StringBuilder()).append("Vendedor: ").append(ex.getErrorCode()).toString()); ex = ex.getNextException(); System.out.println(""); } } catch (Exception ex) { System.out.println("Se produjo un error inesperado"); } }
public void listProducts() { products = new ArrayList<Product>(); try { ResultSet results; if (listAllProducts) { results = listAllProductsStatement.executeQuery(); } else { listByCustomerStatement.setString(1, customerLogin); results = listByCustomerStatement.executeQuery(); } while (results.next()) { int auctionId = results.getInt("auction_id"); Product product = new Product(session.getDb(), auctionId); products.add(product); } } catch (SQLException e) { while (e != null) { debug.println(e.toString()); debug.flush(); e = e.getNextException(); } } if (products.size() <= 0) { productsBox.setLine(0, ""); productsBox.setLine(1, " No products to show."); for (int i = 2; i < 13; i++) { productsBox.setLine(i, ""); } } else { productsBox.setLine(0, " Name | Status | Highest Bid Amount | Buyer or Highest Bidder"); productsBox.setLine(1, ""); ArrayList<Product> productsOnPage = paginator.paginate(products, curPage, 5); int lineOffset = 0; for (int i = 0; i < productsOnPage.size(); i++) { Product product = productsOnPage.get(i); // lineOffset works now lineOffset = i * 2; productsBox.setLine( lineOffset + 3, " " + product.name + " | " + product.status + " | $" + product.amount + " | " + product.getHighestBidder()); } // clear the lines of productBox if there are not as many products as before int lastLine = productsOnPage.size() * 2 + 2; for (int i = lastLine; i < 12; i++) { productsBox.setLine(i, ""); } productsBox.setLine(12, paginator.getPageMenu(products, curPage, 5)); } }
/* * ConstructorTest */ public void testSQLException() { String[] theFinalStates1 = {null}; String[] theFinalStates2 = {null}; int[] theFinalStates3 = {0}; SQLException[] theFinalStates4 = {null}; Exception[] theExceptions = {null}; SQLException aSQLException; int loopCount = 1; for (int i = 0; i < loopCount; i++) { try { aSQLException = new SQLException(); if (theExceptions[i] != null) { fail(); } assertEquals(i + " Final state mismatch", aSQLException.getMessage(), theFinalStates1[i]); assertEquals(i + " Final state mismatch", aSQLException.getSQLState(), theFinalStates2[i]); assertEquals( i + " Final state mismatch", aSQLException.getErrorCode(), theFinalStates3[i]); assertEquals( i + " Final state mismatch", aSQLException.getNextException(), theFinalStates4[i]); } catch (Exception e) { if (theExceptions[i] == null) { fail(i + "Unexpected exception"); } assertEquals(i + "Exception mismatch", e.getClass(), theExceptions[i].getClass()); assertEquals(i + "Exception mismatch", e.getMessage(), theExceptions[i].getMessage()); } // end try } // end for } // end method testSQLException
private boolean AidedIn(SaoWorker w) { BatSQL bSQL = new BatSQL(); boolean success = false; String id = w.getUserID(); String q = "select * from aidedin where USERID='" + id + "'"; ResultSet rs = bSQL.query(q); try { boolean more = rs.next(); if (more) { success = true; } } //end of try catch (SQLException ex) { System.out.println("!*******SQLException caught*******!"); while (ex != null) { System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("Message: " + ex.getMessage ()); System.out.println ("Vendor: " + ex.getErrorCode ()); ex = ex.getNextException (); System.out.println (""); } System.exit(0); } //end catching SQLExceptions catch (java.lang.Exception ex) { System.out.println("!*******Exception caught*******!"); System.exit(0); } //end catching other Exceptions bSQL.disconnect(); return success; } //end of AidedIn?
private List<UsersFriends> FindBy(String SQL) { List<UsersFriends> usersFriendsList = new ArrayList<UsersFriends>(); try { this.dbHandler.openConnection(); Statement statement = this.dbHandler.getConnection().createStatement(); ResultSet result = statement.executeQuery(SQL); while (result.next()) { usersFriendsList.add( new UsersFriends( result.getInt("id"), result.getInt("id_user"), result.getInt("id_friend"))); } // else System.out.println("Записи с данными параметрами не существует"); } catch (SQLException ex) { System.out.println("SQLException caught"); System.out.println("---"); while (ex != null) { System.out.println("Message : " + ex.getMessage()); System.out.println("SQLState : " + ex.getSQLState()); System.out.println("ErrorCode : " + ex.getErrorCode()); System.out.println("---"); ex = ex.getNextException(); } } catch (Exception ex) { System.out.println("Other Error in Main."); } return usersFriendsList; }
public ArrayList queryCustByLogName(String loginName) { Connection cnnct = null; PreparedStatement pStmnt = null; CustomerBean cb = null; ArrayList<CustomerBean> customers = new ArrayList(); try { cnnct = getConnection(); Statement stmt = cnnct.createStatement(); String preQueryStatement = "SELECT * FROM Customer WHERE loginName = " + loginName; ResultSet rs = stmt.executeQuery(preQueryStatement); while (rs.next()) { cb = new CustomerBean(); cb.setCustId(rs.getString("custId")); cb.setLoginName(rs.getString("loginName")); cb.setLoginPswd(rs.getString("loginPswd")); cb.setCustFullName(rs.getString("custFullName")); cb.setCustTel(rs.getString("custTel")); cb.setCustAddress(rs.getString("custAddress")); cb.setCustDOB(rs.getString("custDOB")); customers.add(cb); } rs.close(); cnnct.close(); } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } catch (IOException ex) { ex.printStackTrace(); } return customers; }
public boolean addCategoryRecord(String productId, String category) { Connection cnnct = null; PreparedStatement pStmnt = null; boolean isSuccess = false; try { cnnct = getConnection(); String PreparedStatement = "INSERT INTO Category VALUES (?,?)"; pStmnt = cnnct.prepareStatement(PreparedStatement); pStmnt.setString(1, productId); pStmnt.setString(2, category); int rowCount = pStmnt.executeUpdate(); if (rowCount >= 1) { isSuccess = true; } pStmnt.close(); cnnct.close(); } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } catch (IOException ex) { ex.printStackTrace(); } return isSuccess; }
public boolean addStaffRecord(String staId, String staPswd, String staFullName, String staTel) { Connection cnnct = null; PreparedStatement pStmnt = null; boolean isSuccess = false; try { cnnct = getConnection(); String PreparedStatement = "INSERT INTO Staff VALUES (?,?,?,?)"; pStmnt = cnnct.prepareStatement(PreparedStatement); pStmnt.setString(1, staId); pStmnt.setString(2, staPswd); pStmnt.setString(3, staFullName); pStmnt.setString(4, staTel); int rowCount = pStmnt.executeUpdate(); if (rowCount >= 1) { isSuccess = true; } pStmnt.close(); cnnct.close(); } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } catch (IOException ex) { ex.printStackTrace(); } return isSuccess; }
@Override public void close() throws IOException { LOG.debug( "Closing JDBC resource source (resource={}, table={})", profile.getResourceName(), script.getTableName()); sawNext = false; if (resultSet != null) { try { resultSet.close(); resultSet = null; support = null; } catch (SQLException e) { for (SQLException ex = e; ex != null; ex = ex.getNextException()) { WGLOG.warn( ex, "W03001", profile.getResourceName(), script.getName(), script.getTableName(), script.getColumnNames()); } } try { if (statement != null) { statement.close(); } } catch (SQLException e) { for (SQLException ex = e; ex != null; ex = ex.getNextException()) { WGLOG.warn( ex, "W03001", profile.getResourceName(), script.getName(), script.getTableName(), script.getColumnNames()); } } } try { connection.close(); } catch (SQLException e) { for (SQLException ex = e; ex != null; ex = ex.getNextException()) { WGLOG.warn(ex, "W02001", profile.getResourceName(), script.getName()); } } }
private boolean validUser(HttpServletRequest request, String email, String password) { // Validate user try { Context initCtx = new InitialContext(); if (initCtx == null) System.out.println("initCtx is NULL"); Context envCtx = (Context) initCtx.lookup("java:comp/env"); if (envCtx == null) System.out.println("envCtx is NULL"); // Look up our data source DataSource ds = (DataSource) envCtx.lookup("jdbc/TestDB"); if (ds == null) System.out.println("ds is null."); Connection dbcon = ds.getConnection(); if (dbcon == null) System.out.println("dbcon is null."); HttpSession session = request.getSession(); // Get client session Statement statement = dbcon.createStatement(); String query = "SELECT * FROM customers c WHERE email = '" + email + "' AND password = '******'"; ResultSet rs = statement.executeQuery(query); if (rs.next()) { // IF person exists with that password session.setAttribute( "user.name", rs.getString("first_name") + " " + rs.getString("last_name")); session.setAttribute("user.id", rs.getString("id")); return true; // then log in } } catch (SQLException ex) { System.out.println("<HTML><HEAD><TITLE>MovieDB: Error</TITLE></HEAD><BODY>"); while (ex != null) { System.out.println("SQL Exception: " + ex.getMessage()); ex = ex.getNextException(); } // end while System.out.println("</BODY></HTML>"); } // end catch SQLException catch (java.lang.Exception ex) { System.out.println( "<HTML>" + "<HEAD><TITLE>" + "MovieDB: Error" + "</TITLE></HEAD>\n<BODY>" + "<P>SQL error in doGet: " + ex.getMessage() + "<br>" + ex.toString() + "</P></BODY></HTML>"); } return false; }
private static void showSQLException(SQLException ex) { System.out.println("SQLException:"); while (ex != null) { System.out.println(" Message: " + ex.getMessage()); System.out.println(" SQLState: " + ex.getSQLState()); System.out.println("ErrorCode: " + ex.getErrorCode()); ex = ex.getNextException(); } }
public Producto getProducto(int id) { ResultSet resu = null; Statement stmte = null; Connection conne = null; try { conne = super.getConection(); stmte = conne.createStatement(); resu = stmte.executeQuery( "SELECT productos_id, denominacion, precio FROM productos_aplicables " + "WHERE productos_id = '" + id + "'"); } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } Producto producto = new Producto(); try { while (resu.next()) { producto.setIdproducto(resu.getInt(1)); producto.setDenominacion(resu.getString(2)); producto.setPrecio(resu.getDouble(3)); } } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } try { resu.close(); stmte.close(); conne.close(); } catch (SQLException e) { while (e != null) { e.printStackTrace(); e = e.getNextException(); } } return producto; }
/** * Gets the SQL state code from the supplied {@link SQLException exception}. * * <p>Some JDBC drivers nest the actual exception from a batched update, so we might need to dig * down into the nested exception. * * @param ex the exception from which the {@link SQLException#getSQLState() SQL state} is to be * extracted * @return the SQL state code */ private String getSqlState(SQLException ex) { String sqlState = ex.getSQLState(); if (sqlState == null) { SQLException nestedEx = ex.getNextException(); if (nestedEx != null) { sqlState = nestedEx.getSQLState(); } } return sqlState; }
public Collection<Producto> getAll() { ResultSet resu = null; Statement stmte = null; Connection conne = null; try { conne = super.getConection(); stmte = conne.createStatement(); resu = stmte.executeQuery( "SELECT productos_id, denominacion, precio FROM productos_aplicables "); } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } Collection<Producto> productos = new ArrayList<Producto>(); try { while (resu.next()) { Producto p = new Producto(); p.setIdproducto(resu.getInt(1)); p.setDenominacion(resu.getString(2)); p.setPrecio(resu.getDouble(3)); productos.add(p); } } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } try { resu.close(); stmte.close(); conne.close(); } catch (SQLException e) { while (e != null) { e.printStackTrace(); e = e.getNextException(); } } return productos; }
private static void printSQLException(SQLException se) { while (se != null) { System.out.print("SQLException: State: " + se.getSQLState()); System.out.println("Severity: " + se.getErrorCode()); System.out.println(se.getMessage()); se = se.getNextException(); } }
private void logSQLException(String message, SQLException e) { SQLException mainException = e; StringBuilder causes = new StringBuilder(); int i = 1; while ((e = e.getNextException()) != null) { causes.append(i++).append("\n\t").append(e); } log.error(message + " - causes: " + causes, mainException); }
public String getDni(long idCuota) { ResultSet resu = null; Statement stmte = null; Connection conne = null; try { conne = super.getConection(); stmte = conne.createStatement(); resu = stmte.executeQuery( "SELECT a.dni FROM alumnos AS a " + "WHERE a.alumnos_id = " + "(SELECT c.alumnos_id FROM cuotas AS c WHERE cuotas_id = '" + idCuota + "')"); } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } String dni = ""; try { while (resu.next()) { dni = resu.getString(1); } } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } try { resu.close(); stmte.close(); conne.close(); } catch (SQLException e) { while (e != null) { e.printStackTrace(); e = e.getNextException(); } } return dni; }