Birt report duplicating rows - Table - java

Im having duplicate rows in a table like the printscreen
I read the solution was selecting the columns and check the option: "supress duplicates" (as printscreen) but this is not working as well.
Does anybody has an ideia of how to fix this problem? Thanks in advance

In BIRT, Suppress Duplicates just makes sure the value in the column in not repeated and hence you could see Blank or rows with no values.
And the other reason why we get multiple rows is because there are those many rows with same values.
To avoid blank rows we can make use of hide condition. Steps for the same:
Select the detail row of the table:
Detail Row Selection
In Property Editor -> Properties -> Visibility -> check on Hide Element and add
hidden condition in the pop up window
Row Visibility condition
Visibility condition could be like this :
if(row["Col1"]=="" && row["Col2"]=="" && row["Col3"]==""){true}
If "" doesn't work in the condition, replace it with null
Hope this works.
Thank You.

If you are getting duplicate rows in your table, where it looks like all the values are identical. You probably have one of these issues
A join to a second data set that causes a second row of data to be created, where the filed with two values is not displayed on your report table. = If that field is not required remove it from your dataset.
There are duplicate rows of data in your raw data source = use something like 'select distinct/unique' in your SQL to return only a single row.
If you only have a single data source with only unique rows, what you are displaying may not show a field with two distinct values, but the table is bound to the data that does have two values. Suppress dupes is not going to work because there are not any dupes. = Either display the field with multiple values or clean up your data pull so there is no longer duplicates where they are not intended.

Related

How to restrict a specific row being deleted in MySQL

I'm using jComboBox to select a Supplier from table so I have created -1 id row in a table for "none" selected Supplier.
-1 row is also appearing to user where I've fetched all records in
jTable.
I don't want user delete this row may either accidentally or consciously.
So may I have something like this?
I'm using MySQL and Java.
String comName = (String) jSupplrsComboBox.getSelectedItem();
Suppliers suppliers = manager.searchSuppCompny(comName);
if (comName.equals("none")) {
receivings.getSuppliers().setId(-1);
receivings.setSuppliers(suppliers);
}
receivings.setSuppliers(suppliers);
Fetched Suppliers to jComboBox and just manually addd "none" text so it doesn't match in Suppliers table.
I'm not sure what exactly you're trying to achieve, but if you're utilizing a JComboBox, I imagine you're filtering your database by the supplier indicated by the comboBox selection. This also means your comboBox model needs to be populated with entries that exist in your database.
This is a quick way to set Strings to the ComboBox from an Enum, passing entries from the database should work in a similar way, but ensuring duplication does not exist may need to be addressed
jSupplrsComboBox.setModel(new DefaultComboBoxModel<>(SupplierId.values()));
From link Java - Check Boxes in a JComboBox, response by Jonathan Feinberg might be better suited for more than one filter.
As for MYSQL, I'm assuming you have access to make modifications, it may be better if you add an extra field, say isValid, to indicate if said entry is valid or not. In which case you can filter on jSupplrsComboBox.getSelectedItem() with an additional WHERE isValid = 1.
But your question was geared more towards Java than MYSQL, so I won't mention more on that. Check out MySQL Boolean Question and associated links for more on that.
Well I tried myself and where I'm retrieving records I changed code:
DefaultTableModel suppliersModel = (DefaultTableModel) jSuppliersTable.getModel();
for(Suppliers suppliers : manager.allSuppliers()) {
suppliersModel.addRow(new Object[]{suppliers.getId()});
int id = (Integer) suppliersModel.getValueAt(0, 0);
if(id == -1) {
suppliersModel.removeRow(0);
}
That retrieve records after first row which is -1 id in the database table.
Tahnks.

BIRT Report Generation - How do I keep all row data?

My question has to do with the output that is generated when I run a BIRT report.
Normally, a BIRT report would not show the duplicate portion of each row of data that is written to a report. For instance, if I were generating a report that were to contain multiple lines (rows) of data and the data was organized by a 'Group ID'. The data, for each specific Group ID would be shown indented and organized by each Group ID. The Group ID would be shown in the first row of output, but for subsequent rows of data (for that same Group ID), the Group ID would not be shown. In otherwords, no need to display the same Group ID over and over in the report. This method helps to keep the clutter down and makes the report easier to read.
I have a customer who doesn't want the report generated this way. The specifications are to show each row of report data as if it were directly from a SQL query.
Is there a way to have the BIRT report show all data during the report generation? I've looked all over and still haven't come up with any ideas.
Thanks!
Your assumption 'Normally, ...' is wrong. Instead, normally BIRT does output each row of report data as if it were directly from a SQL query.
If you create a group and you don't want to repeat the same values, you have to move those columns to the group header (and use "drop cell: detail", if you like).
However, for the columns, there's also a property called "suppress duplicates" or so. Maybe this is set in your template or style sheet or you checked it accidentally?
Make sure this is not checked!
Use ROW_NUMBER() in your SQL to create a unique value, each row will now be different and will display. Include the field in your report, but don't display it (hide).
This should give you the desired results.

How to avoid page Break between two detail rows of table in BIRT

I have eclipse version 3.4.1 for BIRT Reporting,
I need to avoid page break between two detail rows of a table.I didn't found "avoid" option in page break properties.
My table showing data in two detail rows so may Table can be break at the end not in between two detail rows.
Example:
Employee No/Employee Name
--------------------------
Detail row 1 [employee_No]
Detail row 2 [employee_Name]
In above, I need to avoid page break between employee_No and employee_Name
Thanks in Advance.
The easiest solution if your design criteria will allow it; is to use a table with 2 detail columns. Place your employee number in the left column and the employee name in the right column, this way there is no row to break, everything is on the same row.
The harder way but it will allow you keep the existing format and control page breaks between employee name and number is to use a list element with a table inside it.
In this example I have a list with a table (actually two tables) in the detail line of the list. The table(s) each return only one occurrence per primary key (in my case a ticket ID, in yours an employee ID). You can get as fancy as you want with table (I have extra columns for spacing, and two columns of data & Two columns of labels.)
You can then avoid page breaks in your table.
I built this report a couple years ago, and have not done anything similar for a while, so all the details of making it work are not fresh in my mind, but I don't recall it being overly difficult to figure out.
I know this is quite old, but with versions 2.5 and following, you can define where in your layout do you want to avoid page breaks.
To do so, select an element in your layout, go to property editor -> page break and select "avoid" in the desired position.
Keep in mind that, depending on your layout, you probably need to set "avoid" in different point, for example after "first rows" and before "second rows" of each record in the question example.

DuplicateKeyException even after removing unique constraints

I'm working on db2. I got one table, which contains some data:
Data | Value | Lang
To Data column of this table, was added unique constraint. However, now application CAN contain many rows for the same date. So, I removed constraint, but, after reorganization of table, restart of server it still throws exceptions when I want to add more than one row with the same Data.
Unfortunately I didn't create this table at first place, and I can't remove data from it :/
Anyone has any idea what's going on?
Thanks for you time!
Okay, it looks like there was index on this column also.
To check indexes:
select * from SYSIBM.SYSINDEXES where TBNAME= 'TABLE_NAME';
To drop index:
drop index INDEX_NAME;
Now it works! :) Quite easy.

Generate encoding String according to creation order

I need to generate encoding String for each item I inserted into the database. for example:
x00001 for the first item
x00002 for the sencond item
x00003 for the third item
The way I chose to do this is counting the rows. Before I insert the third item, I count against the database, I know there're already 2 rows, so the next encoding is ended with 3.
But there is a problem. If I delete the second item, the forth item will not be the x00004,but x00003.
I can add additional columns to table, to store the next encoding, I don't know if there's other better solutions ?
Most databases support some sort of auto incrementing identity field. This field is normally also setup to be unique, so duplicate ids do not occur.
Consult your database documentation to see how it is done in your database and use that - don't reinvent the wheel when you have a good mechanism in place already.
What you want is SELECT MAX(id) or SELECT MAX(some_function(id)) inside the transaction.
As suggested in Oded's answer a lot of databases have their own methods of providing sequences which are more efficient and depending on the DBMS might support non numeric ids.
Also you could have id broken down into Y and 00001 as separate columns and having both columns make up primary key; then most databases would be able to provide the sequence.
However this leads to the question if your primary key should have a meaning or not; Y suggest that there is some meaning in the part of the key (otherwise you would be content with a plain integer id).

Categories

Resources