简体   繁体   English

如何绑定jtextfield以从Netbeans中的数据库中获取文本?

[英]How do i bind a jtextfield to get text from the database in Netbeans?

我似乎无法找到任何有关将Jtextfield的文本绑定到Netbeans 6中的数据库的数据的信息。它只是可以绑定的表吗?

I don't think there is a way to actually bind textfields effectively to a JPA entity. 我不认为这是真正有效的JPA实体绑定文本框的方式。

My Discovery: I discovered you can drag an entity manager and a query on to GUI designer and configure them to work with each other. 我的发现:我发现您可以将实体管理器和查询拖到GUI设计器上,并将它们配置为相互协作。 But you can't bind the query to the textfield. 但是您无法将查询绑定到文本字段。 What you want to do, is bind your persistence entity to the Textfield. 您想要做的是将持久性实体绑定到Textfield。 So, add your entity to the palette. 因此,将您的实体添加到调色板中。

You have to right-click the netbeans palette and go to palette manager->add from project. 您必须右键单击netbeans调色板并转到调色板管理器 - >从项目添加。 Select your project and you will be able to add all your persistence entities to the palette (best create a new folder for them). 选择项目,您将能够将所有持久性实体添加到调色板中(最好为它们创建一个新文件夹)。 You should now have your entities in the palette. 您现在应该在调色板中拥有您的实体。 drag onto screen as usual and assign query to entity. 像往常一样拖到屏幕上并将查询分配给实体。

Yo can now open up properties of a textfield-> binding tab and bind the TEXT property of the textfield to your entity and then select which "column" from that entity you truly wish to bind text to. Yo现在可以打开textfield-> binding选项卡的属性,并将textfield的TEXT属性绑定到您的实体,然后选择您真正希望将文本绑定到该实体的哪个“列”。 This should should be bound now and would work for most cases. 这应该受到约束,并且适用于大多数情况。

HOWEVER, In an application were that entity needs to be changed often, it is useless because the binding to the textfield does not update itself. 但是,在一个应用程序中,实体需要经常更改,它是无用的,因为绑定到文本字段不会更新自身。 So it essentially only acts "bound" that first time. 所以它基本上只是第一次“绑定”。 This is mainly because when you change an entity, it's really a different memory object at that point. 这主要是因为当你更改一个实体时,它实际上是一个不同的内存对象。 eg clientEntity = (Query) clientQuery.getSingleResult(); 例如clientEntity = (Query) clientQuery.getSingleResult();

I believe it's safe to say that Swing has been abandoned when it comes to entity binding as JPA and entities in their current state is only really useful with "session" based web services where you typically would be the one to set/get entity column values and merge when done. 我相信可以肯定地说,当涉及到实体绑定时,Swing已被放弃,因为JPA和当前状态下的实体仅对基于“会话”的Web服务非常有用,在这种情况下,您通常会设置/获取实体列值完成后合并。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM