Is there a simple way to create reports in Java without using a database (like SQL)?
What I want to do is to get a number of strings in an ArrayList of objects and then put them on a printable report. Also, i want to put values from a comma-separated file to the printable report. I've found this JavaDoc but, based from what I've understood, it's not possible to design the report using this. (Correct me if I'm wrong)
Try JasperReports, it's the most common open source tool for reporting in the Java world, and you can create reports from multiple data sources, not only data bases.
Reports are view, separate from the source of data. I don't see how a report would know the difference between a database and a list of strings.
Data is data, regardless of where it comes from. I didn't bother to read the link you included, because tying a report to a particular type of data doesn't make sense to me.
Related
Unfortunately I couldn't find anything specific to this topic / to my problem. Here we go:
I'm building a JavaFX Business Application for a friend of mine. Unfortunately I do not have any possibility to connect to a Database. I want the Application to load a savestate from a file. The application contains a list with clients and the clients got some specific properties. I do not want to hardcode this to a .prop or .txt file, because I'm sure that there's a different way of doing this, isn't there?
Thanks in advance, appreciate it!
Lots of choices for persisting data to local storage. The exact choice depends on your needs. You do not describe enough details to make a specific recommendation.
Here is a list of possibilities, roughly in increasing order of complexity of your data.
Text file
If you have small amounts of simple data, save to a text file. You can store each piece in a separate file, or combine into a single file. Recent versions of Java have new classes to make this easier than ever. See Oracle Tutorial.
Comma-separate & Tab-delimited
For sets of structured data, write to text files in comma-separated values (CSV) or tab-delimited values. For example a list of people with rows for each person, and columns for name, phone number, and email address.
While reading/writing such files is easy enough to program yourself, I suggest using an established library to eliminate the drudgery, avoid bugs, and save yourself some time. There are a few such libraries written in Java.
My favorite is the Apache Commons CSV project. This library makes easy work of the chore of reading/writing such files. Despite the name, this library supports tab-delimited as well as comma-separated formats. I've written a few Answers here on Stack Overflow showing how to use this library, as you can see here, here, and here.
By the way, plain old ASCII defines a few character positions explicitly for delimiting in data files, with four levels of grouping (document, group, record/row, and field). Unicode, of course, inherits these from ASCII as code points. I am puzzled why these have remained so obscure and so infrequently used. Seems much more logical to me than using commas and tabs which may well exist inside the data payload.
Serialization
You can write out the data values stored within an object. This is called serialization. Java has a serialization facility built-in, but be sure to study up on the details.
To more simply write out an object’s values and later read them back in to reconstitute an object, I have enjoyed using the Simple XML Serialization project. This works well for relatively simple needs, and is aimed at the situation where you want the structure of a class to drive the process of determining what to write.
Java has other XML binding facilities both built-in and third-party. These are much more powerful in their flexibility. They are especially good for when you want to define and verify the XML structure in a rigid fashion such as defining a XML DTD or XML Schema against which to validate the data and perhaps even generate the Java class in which to represent the data.
Embedded database
For more complicated data, use an embedded relational database.
The SQLite database is bundled with many platforms. This is a C-based library, not pure Java. As the name indicates, SQLite is indeed quite “lite“, lacking rigid data types and many other common database features. SQLite is meant to be an alternative to writing text files than as a competitor to more serious databases. It is a great product if your needs fit the sweet-spot of its capabilities.
My first choice for an embedded database would be H2 Database Engine. Built in pure Java. Can be run inside your app, or separately as a server (you choice). Has sophisticated relational database features. Has been around for years, often updated, and is well-worn. The principal author has much experience in the field.
I have a big XML file that lacks information, most of these data are codes and I need to generate a PDF file with the descriptions.
On the other hand, I have all descriptions needed accesible from my java application, the question is: What of the following options is most fast?
Using XSTL-extension for access to the information storaged in a Map
Using XSTL-extension for access to the information storaged in a local database
Using XSTL-include for read a file generated by my java process that contains variables with name=ids and Select=descriptions.
I'm worried about the performance because I'm talking about a lot of ids (data).
I had the same problem few time ago and I decided to use your third option:
Using XSTL-include for read a file generated by my java process that contains variables with name=ids and Select=descriptions.
because in this way yo can be indepedent of you core, not like with extensions.
I'm a newbie to Java.
Could you help me understand how to construct printing of a rather complicated report. The report is a table with a lot of fields about a services rendered to a client (date, client, service, signatures etc.). The layout of this table may change in time if the boss orders.
Printing of the report may be done from many computers to many printers.
What I can't think of is how to cope with this: to pseudographics is outdated and complicated if the layout changes.
The other approach is to use Excel workbooks (or something similar). In this case all I need is putting information in the right cell. This is good because Excell will be responsible for correct printing. But this is a bit more burdensome for the computer and slow for the user: to launch Excell, maybe the user will have to check the borders or something.
Well, could you recommend me anything?
We use JasperReports to generate PDF files. It's an open source Java library and comes with a report designer that easily plugs into Eclipse. A stand-alone version of the report designer is available, if you use a different IDE.
I want to create reports in PDF using the data available in database. I want to do some data manipulation and use the charts and details to be shown in pdf to the user.Suppose say there are 2 columns in DB a and b . I want to show in the PDF, the value of a and b and the addition of a and b. What i can use to generate this pdf report?
I thought of using jasper, but i donot want to use it. Instead is there any other logic in java that can help to solve this problem. Please suggest with examples.
Thanks
Birt is a tool that can be used to generate all sorts of reports. There are plugins for Eclipse that you can use to help you get going and you can definitely add logic in Java. It can output your report in multiple formats including PDF, HTML, and I believe even Word docs.
If you've used Eclipse before you should be able to figure out the basics, but it can get as complicated as you want. In its simplest form you attach data sources (such as a database with a JDBC connection) and you structure your joins and layout fields onto a form. You can even tie it into a Java EE container if needed.
There are examples on their website and it has a rather large community to help with questions.
I am making a math game in Java and I want to create the ability for the user to create a local account (or log in to an existing one), which would have a unique properties file. How would I do this?
You have a couple of options to look into. Java comes with the necessary libraries with which you can create, open, read and write to files. Using the File class, you could create an account file, for instance "User1.properties", and save the information in an easy to parse format. If you're looking to go one further, you can look into using XML or JSON, which are commonly used formats for saving information in this way. Here's some helpful links to get you started.
Using files in Java
Using XML in Java
Using JSON in Java
Another option you have available is to use a database in a similar fashion to websites. The type of database you use is up to you, although MySQL is an example of one commonly used database. Once again, here is a link to help you get started with MySQL in Java.
Regardless of what you use, you will need to take the username and password provided (or whatever combination of login credentials you would like your system to use), and compare them with those stored in your file or database.