473,779 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bind data to JTable

3 New Member
I'm using NetBeans 5.5

First :I want to bind data from table from MS Access DB into JTable .

Second: Is there any other component in java to do the previous action(e.g. DataGrid )
Jun 24 '07 #1
5 7267
Ahmed Osama
3 New Member
I'm using NetBeans 5.5 :

How could I bind data from table from MS Access DB into JTable,is there in java smth like DataGrid ?!!

N.P. : I've made an application which reads data from the DB & use
Expand|Select|Wrap|Line Numbers
  1. System.out.append(rs.getString("Blob") 
to show the data .
Now I want to display the data using some GUI .
Jun 25 '07 #2
r035198x
13,262 MVP
I'm using NetBeans 5.5 :

How could I bind data from table from MS Access DB into JTable,is there in java smth like DataGrid ?!!

N.P. : I've made an application which reads data from the DB & use
Expand|Select|Wrap|Line Numbers
  1. System.out.append(rs.getString("Blob") 
to show the data .
Now I want to display the data using some GUI .
I suppose you've read about how to create a basic swing application?
Jun 25 '07 #3
r035198x
13,262 MVP
I've also merged your threads since they are dealing with basically the same problem.
Jun 25 '07 #4
Ahmed Osama
3 New Member
Thanks for reply :) .

After searching , frankly I couldn't make my DB to show it's info. in JTable.
However , I've made my application to use some GUI but shows the data using
"System.out.pri ntIn("") "

that's my code :


Expand|Select|Wrap|Line Numbers
  1.  import javax.swing.*;
  2.    import java.sql.*;
  3.    import javax.swing.event.TableModelListener;
  4.    import javax.swing.table.TableModel;
  5.  
  6.  
  7. public class MyConnection {
  8.  
  9.     public MyConnection() {
  10.  
  11.     }
  12.  
  13.       public static Connection getConnection() throws Exception {
  14.       Driver d = (Driver)Class.forName
  15.      ("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
  16.     Connection c = DriverManager.getConnection(
  17.      "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/Inventory.mdb"
  18.       );
  19.     return c;
  20.  
  21.     }
  22.  
  23.       //******************************************
  24.  
  25.  
  26.  
  27.       static Connection theConn;
  28.      // public static String sql;
  29.       public void retrieveData(String sql )
  30.       {
  31.  
  32.                    try {
  33.  
  34.       // connection to an ACCESS MDB
  35.       theConn = MyConnection.getConnection();
  36.  
  37.       ResultSet rs;
  38.       Statement stmt;      
  39.  
  40.       stmt = theConn.createStatement();
  41.       rs = stmt.executeQuery(sql);
  42.       boolean FirstLoop=true;
  43.       boolean DataExisted=false;
  44.  
  45.       while (rs.next())
  46.       {
  47.           if(FirstLoop==true)
  48.           {
  49.                  System.out.append("ID");
  50.                  System.out.append("\t");                 
  51.                           System.out.append("Product_Name");
  52.                           System.out.append("\t");
  53.                                     System.out.append("Product_Price");
  54.                                     System.out.append("\t");
  55.                                                 System.out.append("Amount_In_Stock");
  56.                                                 System.out.append("\t");
  57.  
  58.                                                 System.out.println("");
  59.                                                 FirstLoop=false;
  60.                                                 DataExisted=true;
  61.           }
  62.  
  63.            System.out.append(rs.getString("ID"));
  64.            System.out.append("\t\t");
  65.            System.out.append(rs.getString("Product_Name"));
  66.            System.out.append("\t\t");
  67.            System.out.append(rs.getString("Product_Price"));
  68.            System.out.append("\t\t");
  69.            System.out.println(rs.getString("Amount_In_Stock"));
  70.  
  71.  
  72.  
  73.       }   
  74.  
  75.       if(DataExisted==false)
  76.           System.out.println("No Result is found ");
  77.       System.out.println("__________________________________________________________________");
  78.       System.out.println("__________________________________________________________________");
  79.       rs.close();
  80.       stmt.close();
  81.     }
  82.     catch (Exception e) {
  83.         e.printStackTrace();
  84.     }
  85.     finally {
  86.       try {
  87.         if (theConn != null) theConn.close();
  88.       }
  89.       catch (Exception e) {
  90.       }
  91.     }
  92.       }
  93. }
Jun 26 '07 #5
r035198x
13,262 MVP
Now that's a huge step forward. Realize now that a GUI is just a bunch of components which takes data in various forms (images, Strings, e.t.c) and just displays them. If you have data printed to console, all you need now is to redirect that to a GUI. I suppose you've read the swing tutorial?
Jun 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1925
by: Alan Hoffman | last post by:
Hi, Is it possible to create a JTable where the column is not all one type of Component. For example using a JTable to enter in values for an address where the first column is just JLabels and the second columns first cell is a JTextField for the street and the next cell is a JComboBox that contains all the states. Thanks, Alan
1
8974
by: asd | last post by:
I need to make the cells in the 1st column look like the column header. I tried the following code but it didn't change anything: private void rendererTest() { TableColumn column = tblDecisions.getColumnModel().getColumn(0); TableCellRenderer renderer = column.getHeaderRenderer(); column.setCellRenderer(renderer); }
1
7975
by: raysaun | last post by:
I am trying to set a TableCellEditor for a JTable, however, the editor never seems to get called. I can not even get a simplified version (below) to work. When I put a breakpoint on the return statement in getTableCellEditorComponent, it never stops there even though I edit cells in the table. Can anyone tell me what I am missing. By the way, I have gotten TableCellRenderers to work with no problems. public class Frame1 extends...
0
3398
by: nuria | last post by:
hi, I have an editable JTable, when you are editing it and press F8 shows a dialog and then go again to the JTable window but the focus goes to a JtextField component, go with the tab for the rest of the textfields and when have to get the focus again the JTable can´t get it !!! only if I go with the mouse!!!! I am trying all things, give the focus to other component before call the Jdialog, put visible(false) the JTable before call...
1
7389
by: onsir | last post by:
I have code like this, but still wrong. how to show data from database in JTable. package my.JavaNetBean; import java.sql.*; import java.io.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException;
2
2128
by: renehv | last post by:
Hi, does somebody konws how in runtime execution to change the data values in a JTable, setValueAt works only if the change is in the same table , if i want to change the table values from another component ??
16
2578
by: Epix | last post by:
Hi, I have a program that is written in Java using swing. There is a JTable that is filled with data that needs to be put into a table on a web site which is written in Javascript. Each cell in the table on the web site is editable. The table in the application it set up to exactly like the one on the web site so it has all the same rows and columns. I have never used Javascript and don't know how to do this. Any help would be greatly...
5
9850
by: moizpalitanawala | last post by:
Hello friends, How to add data to JTable from a .txt file. I had seen this code from one of the tutorial from java.com. This code doesnt take any input. But shows what is written in the array. But i want the table to display the data from a .txt file in which i had stored information in this format. Can anyone please modify the codes and explain me. Name:Mr.xyz Phone:111111222222
5
5219
by: rburke1125 | last post by:
Hello All! I'm a bit new to Java, and certainly to the community. I'd appreciate any and all pointers to the right direction! I have a JTable that I have populated with a 2 dimensional array. During the period of the data sitting there, it will be modified. When finished, I would of course like to export it back to a 2 dimensional array. I really have no clue on the best way of doing this. I assume JTables do not have a 2-dim...
0
9633
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10305
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9928
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8959
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.