How to link jtextfield to get text from a database in Netbeans?

I cannot find any information about binding Jtextfield text to data from a database in Netbeans 6. Are these just tables that can be linked?

+4
source share
1 answer

I do not think that there is a way to actually bind text fields effectively to JPA entities.

My Discovery: I found that you can drag and drop the entity manager and query into the GUI designer and configure them to work with each other. But you cannot bind a query to a text field. What you want to do is bind your persistence object to a text field. So add your entity to the palette.

You need to right-click the netbeans palette and go to the palette manager โ†’ add from project. Select your project, and you can add all your persistence objects to the palette (it is best to create a new folder for them). You should now have your objects in the palette. drag to the screen as usual and assign the request to the object.

Now, Yo can open the bookmark properties of textfield-> binding and bind the TEXT property of the text field to your object, and then choose which โ€œcolumnโ€ of this object you really want to bind. This should be connected now and will work in most cases.

HOWEVER, in the application it was necessary that this object change frequently, it is useless, since the binding to the text field does not update itself. Thus, he essentially only acts โ€œconnectedโ€ for the first time. This happens mainly because when you change the entity, it is really a different memory object at that moment. for example, clientEntity = (Query) clientQuery.getSingleResult();

I believe it is safe to say that Swing was abandoned when it comes to entity binding, since JPAs and entities in their current state are really only useful for session-based web services, where you will usually install / get object column values โ€‹โ€‹and merge at the end.

+1
source

Source: https://habr.com/ru/post/1338948/


All Articles