Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: JTable

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question JTable

    Hi here i get all rows from from DB. I want get sss = rs.getInt(5); from DB ant set to Colheads.
    or no to column but to first Row all data from column;
    Exsample
    now table is  table  a    me need        a  a+1   a3   a4 ....
                         1                   1   2     3     4   .....
                         2
                         3
                         4

    p2 = new JPanel();
            try {
                rs = st.executeQuery("SELECT * from item");
            } catch (SQLException ex) {
                Logger.getLogger(nn.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                while (rs.next()) {
                    s = rs.getInt(1);
                    a = rs.getString(2);
                    ss = rs.getInt(3);
                    aa = rs.getString(4);
                    sss = rs.getInt(5);
                    ssss = rs.getInt(6);
                    rows++;
                }
                data1 = new Object[rows][6];
                Object[] Colheads = {"Isss = rs.getInt(5) here need some help !!!!!!!!!!"};
                rs = st.executeQuery("Select * from item");
                for (int i1 = 0; i1 < rows; i1++) {
                    rs.next();
                    for (int j1 = 0; j1 < 6; j1++) {
                        data1[i1][j1] = rs.getString(j1 + 1);
     
                    }
                }
    Last edited by skuskusas; September 5th, 2012 at 01:42 AM. Reason: add exsample


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: JTable

    Last edited by pbrockway2; September 5th, 2012 at 02:18 AM.

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: JTable

    What is the error? Kindly copy the exception trace and paste here. Well, for your information, rs.getString() never works as you did here;
    for (int j1 = 0; j1 < 6; j1++) {
                        data1[i1][j1] = rs.getString(j1 + 1);
     
                    }
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

  4. #4
    Junior Member
    Join Date
    Aug 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JTable

    that code work fine.

    but hi print like box layout 1 but me need like line 1 2 3
    2
    3
    4

  5. #5
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: JTable

    Well, if you want to set the columnHeaders, use the DefaultTableModel and then using it set the values for table headers. Moreover, What are you talkinga bout printing like box layout and what?
    Kindly be precise so that we could help you in that sense.
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

  6. #6
    Junior Member
    Join Date
    Aug 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JTable

    No not a headers. i want set header like name and if i have data in this row name+1 .
    and print from DB. in db now data is like
     name     but me need  name     name1        name2  ....
        1                  1           2          3
        2
        3

  7. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: JTable

    Okay so you mean that in database data is like
    name
    1
    2
    3
    and you want to display it in your application like
    name1         name2               name3
    1                   2                         3
    Right?
    If that's so, read the data from database in ResultSet and then iterate it and on every iteration, place the data in the table columns.
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

  8. #8
    Junior Member
    Join Date
    Aug 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JTable

    Right but i dont known how maybe you can whrite exsample ?

  9. #9
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: JTable

    Okay so take it step by step.
    1. You get resultset.
    2. Iterate through the result Set
    3. Against each iteration, set the value of table column headers.

    Isn't it simple?
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

  10. The Following User Says Thank You to Mr.777 For This Useful Post:

    skuskusas (September 7th, 2012)

  11. #10
    Junior Member
    Join Date
    Aug 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JTable

    well maibe its simple for java programmer bu me programing only 2weeks and when you said
    "Iterate through the result Set" i think wtf its mean so if you can whrite code if not i said thanks for you for help

  12. #11
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: JTable

    So i would recommend to see this: Database Programming with JDBC and Java: Chapter 4. Database Access Through JDBC
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

Similar Threads

  1. JTable Row Color
    By ellias2007 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 23rd, 2012, 01:29 PM
  2. JTable
    By gogiseq@gmail.com in forum Java Theory & Questions
    Replies: 1
    Last Post: October 24th, 2011, 05:24 AM
  3. JTable
    By adra in forum Java Theory & Questions
    Replies: 5
    Last Post: August 30th, 2011, 07:05 AM
  4. JTable
    By timmin in forum AWT / Java Swing
    Replies: 3
    Last Post: April 3rd, 2011, 12:10 PM
  5. Hello everyone! I need help with JTable
    By hektor in forum AWT / Java Swing
    Replies: 6
    Last Post: October 11th, 2010, 10:11 AM