Search code examples
javaswingnetbeansderby

Is there a way to open a table made in derby(derby in netbeans) in jtable?


I am trying to create a frame for customers where they can view the product Table which I already created in derby (that is the DB in netbeans).Is there a way of opening the table product in the customer Frame so that the customer can view the details and also make sections too? If there is no way can u please suggest any ideas to tackle this ? enter image description here

By the click of the search product I want to display


Solution

  • If you just want to bind a table in the database to a JTable in a JFrame designed with the gui builder, netbeans does provide a shortcut for this:

    1. Go to the Services Tab (in the Upper Left). Use Windows -> Services if it not visible
    2. Create a database connection to your database.
      • Select the Databases icon. Right-click for "New Connection"
      • Choose the appropriate driver. For derby it would be either Java DB(Embedded) or Java DB(Network) depending on how you setup Derby.
      • Provide the other connection properties.
    3. Click the triangle on you Database connection to expand the nodes for it and the database within and then tables
    4. Select your JFrame class in the Editor window, and use the Design button to view the design
    5. Drag the appropriate database table from the services window to the JTable in the GUI designer
    6. To get the data the user selected your code would call something like this:

      jTable1.getModel().getValueAt(jTable1.getSelectedRow(), columnYouWant);
      

      where columnYouWant is an integer index to the column of interest.