@Override
    public Matrix select(int matrix_id) throws SQLException {

        statement = connection.prepareStatement(selectColsString);
        statement.setInt(1, matrix_id);
        result = statement.executeQuery();

        int cols = 0;

        while (result.next()) {
            cols = result.getInt(1);
            //System.out.println("cols = " + cols);
        }

        int rows = 0;

        statement = connection.prepareStatement(selectRowsString);
        statement.setInt(1, matrix_id);
        result = statement.executeQuery();

        while (result.next()) {
            rows = result.getInt(1) / cols;
            //System.out.println("rows = " + rows);
        }

        Matrix matrix = new MatrixDouble(rows, cols);
        statement = connection.prepareStatement(selectMatrixString);

        for (int i = 0; i < rows; i++) {
            int j = 0;
            statement.setInt(1, matrix_id);
            statement.setInt(2, (i + 1));

            result = statement.executeQuery();
            while (result.next()) {
                try {
                    matrix.setValue(i, j, result.getDouble("value"));
                } catch (MatrixIndexOutOfBoundsException ex) {
                    System.out.println("Error: " + ex);
                }
                j++;
            }
        }

        statement.close();
        result.close();
        return matrix;
    }