As we know Data Blocks style layout in oracle can view in 2 way:
1. FORM
2. TABULAR
I want to know in Java is there any component have same behavior? I mean I want to have table(in form style) same as a data blocks that customer enter his data than after he press save all data go to database, is it possible or not?
Unlike .NET, Java doesn't have a UI component which can be connected directly to a database table for editing.
I'm also not aware of a framework which adds this. There are DB tools like SQuirreL SQL which have inline table editing.
There are lots of frameworks to map DB tables to Java POJOs (Hibernate, for example) but that means you need to define Java mappings for your database tables. With that, you can use UI frameworks like Metawidget to create an editor.
Related
So I'm creating a program that auto generates forms for data entry. The form is created by a user (its a simple table setup with the ability to merge cells). Some of the cells contain text views, others contain text inputs (all based on how the user draws it).
This form is then sent to another application that draws it back out. I was wondering what the best method is to represent the form. I though either use XML to represent the form or use a database that would basically function as a grid and row 1 column 1 in the database would match the form cell row 1 column 1 and so on (kind of an odd way to use a database).
The form creation program is made in C++ and the form regeneration program is created in Java.
Is there an even better way to do this?
Thanks,
I am also thinking the same thing because I am in to creating dynamic forms for my framework to. So I will share some thoughts with you. Using database to add new forms like adding a record in one table that specifies the form and its fields in another having the ability to select it's field types to, or creating one table for each form and each time create a new table or altering its fields (sound messy).. or create a folder with a bunch of xmls that are used for the structure of your forms?
When it comes to database:
Your application is stricted with a specific database application
like sql server 2008 or mysql or mysqli or oracle etc.
Your application is causing network traffic, not that bad but it is
doing it eveytime you need to create or use a form.
You need a panel that creates those forms using the database, and
can be accessed if its web even from your mobile.
When it comes to XML:
Your application is free from database version restrictions.
you need the impersonator to have the right to create files in a
spesific directory in your frameowork.
You don't need a panel even though you can create one, because XML are human readable files. So you can make one while eating your dinner and serve it to your system,
and wala, you have your form generated.
These are my thoughts for now.
How about the methods that will be used in the form? will those also be dynamic? How can you specify what calls what? this is also what you need to take in account.
I think that XML is a much better choice here. Using database as a grid could be more of a headache than needed. You will have to deal with all the problems related to having the database and not really get any benefits of the database. The industry decides to go with xml more often than not as well (xbrl being one example).
I would like to present a database table in my Swing app.
Very simple table, it should display data that consists of one or a few tables in the database.
The user should be able to add, delete and update the table and then press save.
(not mandatory, it could just save each time he changes values )
What is the recommended way to do that in the most efficient way?
What are the recommended frameworks to start with?
Usually a JTable is used to render database data in a table format, you can see how here.
It is also recommended that you split your GUI and Database access logic into separate classes. Also, it might be a good idea to execute Database operations on a thread which is not the Event Dispatcher Thread (EDT) since this might make your application's UI hang.
With regards to database access, you can use and ORM framework such as Hibernate. It will allow you to connect to your database and retrieve information regardless of what database you are using. You can also change your underlying database at any point in time without you having to rewrite your SQL queries to fit the Database engine you are using.
You can use JFrames to create forms with which you can add and/or remove data.
I've a page with a datatable which can be considered a view on a table of a database. Some fields are static, but some others are inputText, which are meant to modify that field (in particular, all the fields of a specific column).
I would like to press a button and save the whole table.
In general, I'd like to understand how to read an entire table in a managed bean.
Thanks!
EDIT:
I'll try to be more clear:
imagine you've a NxM table of only inputText. Outside the table, a button with an action like #{SomeBean.process}. I'd like to have, in that process method, a List with length N and Row is an object with M fields.
If I understand correctly
I think, you need to save not a datatable, you need to save a rows from this table. With JSF you can use binding and when you need to save data, you just get rows from this binding and make data operations.
If you used some kind of object-relatational mapping like JPA it would be quite easy. Then you could create an entity class of your database table and fill your datatable with a list of your entity objects.
Then you could submit the whole datatable and merge all the changes with your database.
Some IDEs like Netbeans even create entity classes automatically with the help of a wizard. If you are on Netbeans, I recommend to read the JSF Crud tutorial. For Eclipse there should be similiar tutorials, but I am not so familiar with this IDE.
I have heard of JfreeChart but is there any general steps for using data returned from an SQL query to create graphs and chart.
I have an application that shows as a menu option "Analytic's", this Jframe window uses complicated query to retrieve data using business logic but i want to then display this data in a more viable way (rather than a long Jtable result). How can i filter my data and create a graph for the user to analyze?
Check java2s.com/Code/Java/Chart/CatalogChart.htm for a lot examples.
Generally you can fill your own dataset based on your ResultSet. But if you are query is returning results close enough to what you are loading into your dataset you can just use the JDBCCategoryDataset from JFreeChart.
Since you are in search... I think that there is no better tool for designing and generating reports and graphs from your database than iReport. It offers a very consistent GUI, and gives you all support necessary to start creating business graphs from your database data.
The produced report is dynamic. Can be embedded into any application. The reports can be exported as PDF, XML, XHTML, .doc, .odt and more ways. One can pass variables to the report at run-time like from-to Dates, code-id's etc.
iReport is built on top of JasperReports. It is free and open source.
Let me make also clear that i am not in any way affiliated with iReport! :-)
I'm getting introduced to serialization and ran into some problems when pairing it with LinkedList
Consider i have the following table:
CREATE TABLE JAVA_OBJECTS (
ID BIGINT NOT NULL UNIQUE AUTO_INCREMENT,
OBJ_NAME VARCHAR(50),
OBJ_VALUE BLOB
);
And i'm planning to store 3 object types - so the table may look like so -
ID OBJ_NAME OBJ_VALUE
============================
1 Class1 BLOB
2 Class2 BLOB
3 Class1 BLOB
4 Class3 BLOB
5 Class3 BLOB
And i'll use 3 different LinkedList's to manage these objects..
I've been able to implement LoadFromTable() and StoreIntoTable(Class1 obj1).
My question is - if i change an attribute for a Class2 object in LinkedList<Class2>, how do i effect the change in the DB for this individual item? Also take into account that the order of the elements in LinkedList may change..
Thanks : )
* EDIT
Yes, i understand that i'll have to delete/update a row in my DB table. But how do i keep track of WHICH row to update? I'm only storing the objects in the List, not their respective IDs in the table.
You'll have to store their IDs in the objects you are storing. However, I would suggest not trying to roll your own ORM system, and instead use something like Hibernate.
If you change an attribute in a an object or the order of items. You will have to delete that row and insert the updated list again.
How do i effect the change in the DB for this individual item?
I hope I get you right. The SQL update and delete statements allow you to add a WHERE clause in which you chose the ID of the row to update.
e.g.
UPDATE JAVA_OBJECTS SET OBJ_NAME ="new name" WHERE ID = 2
EDIT:
To prevent problems with your Ids you could wrap you object
class Wrapper {
int dbId;
Object obj;
}
And add them instead of the 'naked' object into your LinkedList
You can use AUTO_INCREMENT attribute for your table and then use the mysql_insert_id() function to retrieve the id assigned to the row added/updated by the last INSERT/UPDATE statement. Along with this maintain a map (eg a HashMap) from the java object to the Id. Using this map you can keep track of which row to delete/update.
Edit: See the answer to this question as well.
I think the real problem here is, that you mix and match different levels of abstraction. By storing serialized Java objects into a relational database as BLOBs you have to consider several drawbacks:
You loose interoperability. Applications written in other languages than Java are not able to read the data back. Even other Java applications have to have the class files of the serialized classes in their classpath.
Changing the class definitions of the stored classes will end up in maintenance nightmares.
You give up the advantages of a relational database. Serialization hides the actual data from the database. So the database is presented only with a black box. You are unable to execute any meaningfull query against the real data. All what you have is the ID and block of bytes.
You have to implement low level data handling by yourself. Actually the database is made to handle your data effectively, but because of serialization you hinder it doing its job. So you are on your own and you are running into that problem right now.
So in most cases you benifit from separation of concerns and using the right tool for a job.
Here are some suggestions:
Separate the internal data handling inside your application from persistent storage. Design your database schema in a way to enable the built-in database features to handle the data efficently. In case of a relational database like MySQL you can choose from different technologies like plain JDBC, object relational mappers like JPA or simple mappers like MyBatis. Separation here means to avoid to contaminate the database with implementation specific concerns.
If you have for example in your Java application a List of Person instances and each Person consists of a name and an age. Then you would represent that list in a relational database as a table consisting of a VARCHAR field for the name and a numeric field for the age and maybe a third field for a unique key. Then the database is able to do what it can do best: managing large amounts of data.
Inside your application you typically separate the persistent layer from the rest of your program containing the code to communicate with the database.
In some use cases a relational database may not be the appropiate tool. Maybe in a single user desktop application with a small set of data it may be the best to simply serialize your Person list into a plain file and read it back at the next start up.
But there exists other alternatives to persist your data. Maybe some kind of object oriented database is the right tool. In particular I have experiences with Fast Objects. As a simplification it is serialization on steroids. There is no need for a layer like JPA or JDBC between your application and your database. You are able to store the class instances directly into the database. But unlike the relational database with its BLOB field, the OODB knows your classes and the actual data and can benefit from that.
Another alternative may be JDBM or Berkeley DB.
So separation of concerns and choosing the right persistence strategy (and using it the right way) is a key concern for the success of your project. But doing it right is hard even for experienced developers.