473,378 Members | 1,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Bind data to JTable

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 7234
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 8TB
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 8TB
I've also merged your threads since they are dealing with basically the same problem.
Jun 25 '07 #4
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.printIn("") "

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 8TB
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
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...
1
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 =...
1
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...
0
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...
1
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...
2
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...
16
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...
5
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....
5
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. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.