Results 1 to 4 of 4
  1. #1
    par
    par is offline Member
    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Default using a row of table in JFrame from other class that use jdbc

    heloo
    i have problem.anybody can help me?
    here i bring for you 3 classes.

    class 1 :

    Java Code:
    public class MemberService {
           ...
    
           public member findMember(Member member){
              try{
                Connection conn = getConnection();
                PreparedStatement pst = conn.prepareStatement("select * from member where mem_id=?");
                pst.setInt(1, member.getId());
                System.out.println("record is find in database" );
                ResultSet rs = pst.executeQuery();
                while (rs.next()){
                    System.out.println("name: " + rs.getString(1));
                    System.out.println("age: " + rs.getInt(3));
                }
            }catch(SQLException e){
                System.out.println("SQLException in 'findMember' method");
                e.printStackTrace();
            } 
            return member;
         }
    }
    class 2 :

    Java Code:
    public class EnterMemberId extends javax.swing.JFrame {
           ...
               private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            jButton1.setVisible(false);   
            Member member =new Member();
            member.setId(Integer.parseInt(jTextField1.getText()));
            MemberService memberService = new MemberService();
            memberService.findMember(member);
            String name = member.getName();
            String age = Integer.toString(member.getAge());
            EditMember editMember = new EditMember();
            editMember.setName(name);
            editMember.setAge(age);
            editMember.setVisible(true);
            
        }
    class 3 :

    Java Code:
    public class EditMember extends javax.swing.JFrame {
    
        private String name;
        private String age;
    
        
        public String getName(){
            return name;
        }
        
        
        public void setName(String name){
            this.name=name;
        }
        
        public String getAge() {
            return age;
        }
    
        public void setAge(String age) {
            this.age = age;
        }     
         
         ...
    }

    i want to use "name" and "age" filed of table in my JFrame but i dont know how can i do this.
    i try array but that can't help me,too

    thanks
    Last edited by par; 08-08-2013 at 08:20 AM.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,876
    Rep Power
    5

    Default Re: using a row of table in JFrame from other class that use jdbc

    "use in my JFrame". Yeah, how? In a JTable?

    "I try array" - I don't see that in your code.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    par
    par is offline Member
    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Default Re: using a row of table in JFrame from other class that use jdbc

    my problem in solved

    thanks all

  4. #4
    par
    par is offline Member
    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Default Re: using a row of table in JFrame from other class that use jdbc

    in class 1 i add these :

    member.setName(rs.getString(1));
    member.setAge(rs.getInt(3));


    and now it's work in the best way

    thanks verry much

Similar Threads

  1. to display table data from jdbc
    By Adeelnawaz in forum JDBC
    Replies: 2
    Last Post: 11-26-2012, 10:57 AM
  2. Replies: 1
    Last Post: 05-15-2012, 05:25 AM
  3. Replies: 0
    Last Post: 03-03-2012, 01:01 AM
  4. Replies: 0
    Last Post: 06-07-2010, 11:12 AM
  5. Embedding an oracle table into a JFrame
    By xcallmejudasx in forum New To Java
    Replies: 5
    Last Post: 04-16-2009, 10:23 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •