1

I´ve got a question, I´m working on a app that shows some data in a jtable, but I have a little problem, here is the thing, I have 2 data databases to show in the same jtable, and I don´t know how to show both in the same table, one of the tables give me info about a product, like stock and price, but the other one give me the components that make the full product. some idea?

this are my two databases: BMAEFOL1 and BMAEMAL1

I use another one to show other info but it´s in Jlabels. BMAEPRL1

so..this is my code for the part of the jtable:

if(BSC.getText() != " "){

       String ST = BSC.getText();
       aux=1;

       String SSQL="SELECT * FROM BMAEPRL1 WHERE NMPROD ="+ST+" ORDER BY NMPROD";  /*BMAEMAL1*/

    try{ 
       Class.forName(driver);
        cn = DriverManager.getConnection(url2, user, pass);
        st = cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
        ResultSet.CONCUR_READ_ONLY);  


        rs = st.executeQuery("Select CODMAT, DESCRI, CANTID, PTOPED, PREULT  from BMAEMAL1 WHERE CODMAT ="+ST+" ORDER BY CODMAT");
        rs.next();

the CODMAT and DESCRI need to be from BMAEFOL1 and the others from BMAEMAL1.

thanks!

1 Answers1

1

If I understand what you want to do (since it's not really explicit) :

  1. Get the ResultSet from a first query in your first table with a SELECT *
  2. Get the ResultSet from the second query using SELECT * too.
  3. Create a Map or whatever to link the data together from the two tables
  4. Add the column names to your header and set the data in the JTable (you can use ResultSetMetaData to get all columns names)

Is this what you want to achieve ?

Robert
  • 66
  • 4
  • yes!! That´s what I want! sorry for my bad explenation, English is it not my first languague and in my languague I could find the answer! – Maximiliano Correa May 12 '17 at 17:14
  • This related [example](http://stackoverflow.com/a/9134371/230513) illustrates displaying a `Map` in a `JTable`. – trashgod May 12 '17 at 23:08