简体   繁体   English

Netbeans MVC Swing JTable ResultSet 数据插入

[英]Netbeans MVC Swing JTable ResultSet data insert

I'm new to Java, Swing and programming, but I need to make an application.我是 Java、Swing 和编程的新手,但我需要制作一个应用程序。 I'm using NetBeans for development and here's my question:我正在使用 NetBeans 进行开发,这是我的问题:

If I drag and drop the JTable to my frame and select custom code for the table, I get this code:如果我将 JTable 拖放到我的框架中并为表格选择自定义代码,我会得到以下代码:

appView.java应用程序视图

tblViewData = new javax.swing.JTable();

tblViewData.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {

    },
    new String [] {
        "ID", "Reference No", "Name", "Description"
    }
));



jScrollPane1.setViewportView(tblViewData);

What I want to do is populate new Objects[][] with data that I fetch from the appController using ResultSet and the values I set in the appModel for variables ID, Ref, Name and Desc.我想要做的是用我使用 ResultSet 从appController获取的数据以及我在appModel 中为变量 ID、Ref、Name 和 Desc 设置的值填充新的 Objects[][]

Here's a sample code of an insert I attempted to see if I could display a row of data:这是我试图查看是否可以显示一行数据的插入示例代码:

    new Object [][] {
        { new Integer(model.getID()), model.getRef(), model.getName(), model.getDesc() }
    },

This code returns a 0 in the first column of the row.此代码在行的第一列中返回 0。

Am I approaching this problem wrong?我处理这个问题错了吗?

Thanks for the help.谢谢您的帮助。

Well I have no idea what the "appController" or "appModel" are.好吧,我不知道“appController”或“appModel”是什么。 Maybe these are IDE dependent classes?也许这些是 IDE 依赖类? Instead of using the IDE to generate your SQL code I suggest you write your own code and populate the table yourself.我建议您不要使用 IDE 生成 SQL 代码,而是自己编写代码并自己填充表。

There are plenty of examples on the forum showing how to load a JTable with data from a ResultSet .论坛上有很多示例展示了如何使用ResultSet数据加载JTable Just search for examples using those two class names as your keywords.只需使用这两个类名作为关键字搜索示例即可。

Or you can check outTable From Database which shows how you can use the DefaultTableModel to load rows of data from the ResultSet .或者,您可以查看Table From Database ,其中显示了如何使用DefaultTableModelResultSet加载数据行。

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

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