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 7 of 7

Thread: Database connection using NetBeans

  1. #1
    Junior Member
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Database connection using NetBeans

    Working in NetBeans 6.1 IDE. I have created a database with 4 tables. I have then, following the NetBeans tutorials, created 4 projects which each provide basic CRUD access to the tables. These projects are simple to create as, using the Java Desktop/Database Application templates all the work is done for you, however... What I cannot track down how to do is create a simple 'Switchboard' type front end which, in an application would run first and present the user with a set of 4 JButtons which, when clicked, will bring up the appropriate table access form. I have created a fifth project which contains the 'switchboard' form but how do I link this to the other four 'projects'. Is it an import or do I code the action on each button to open the relevant project ? Any help gratefully received, thanks.
    John


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Linking Database Projects in NetBeans

    Hello jcc285 and welcome to the Java Programming Forums

    Hopefully this tutorial will be able to help you somewhere along the line.

    Lesson: Using the NetBeans GUI Builder (The Java™ Tutorials > JavaBeans(TM))
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Linking Database Projects in NetBeans

    No that doesn't help at all I'm afraid but thanks for the effort. If I add the .jar file for one of my database table access 'projects' to the classpath for my 'Swithcboard' form do you have any idea how I run the library .jar file from a JButton click on a form ?

    thanks

    John

  4. #4
    Junior Member r12ki's Avatar
    Join Date
    May 2009
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Re: Linking Database Projects in NetBeans


    I have the same problem in it. Can somebody give me an advice or show me where the tutorial is ?
    Thanx

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Linking Database Projects in NetBeans

    Quote Originally Posted by jcc285
    Working in NetBeans 6.1 IDE. I have created a database with 4 tables. I have then, following the NetBeans tutorials, created 4 projects which each provide basic CRUD access to the tables. These projects are simple to create as, using the Java Desktop/Database Application templates all the work is done for you, however... What I cannot track down how to do is create a simple 'Switchboard' type front end which, in an application would run first and present the user with a set of 4 JButtons which, when clicked, will bring up the appropriate table access form. I have created a fifth project which contains the 'switchboard' form but how do I link this to the other four 'projects'. Is it an import or do I code the action on each button to open the relevant project ? Any help gratefully received, thanks.
    John
    I think I understand what you mean. Try this code.

    There are 2 classes. MyClass1 & MyClass2. When the button on MyClass1 is clicked, MyClass2 is opened and vise versa. You can replicate this on your Switchboard program.

    To hide the previous window use frame1.setVisible(false);

    MyClass1
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
     
    /**
     * JavaProgrammingForums.com
     */
     
    public class MyClass1 {
     
        public static JFrame frame1 = new JFrame("JAVA WINDOW 1");
     
        public static void createAndShowGUI()  {
     
            frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            JButton button = new JButton(" >> Open myClass2 Application <<");
            //Add action listener to button
            button.addActionListener(new ActionListener() {
     
                public void actionPerformed(ActionEvent e)
                {
                    //Execute when button is pressed
                    javax.swing.SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            frame1.setVisible(false);
                            MyClass2.createAndShowGUI();
     
                        }
                    });
                }
            });      
     
            frame1.getContentPane().add(button);
            frame1.pack();
            frame1.setVisible(true);
        }
     
     
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }
    MyClass2
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
     
    /**
     * JavaProgrammingForums.com
     */
     
    public class MyClass2{
     
        public static JFrame frame1 = new JFrame("JAVA WINDOW 2");
     
        public static void createAndShowGUI()  {
     
            frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            JButton button = new JButton(" >> Open myClass1 Application <<");
            //Add action listener to button
            button.addActionListener(new ActionListener() {
     
                public void actionPerformed(ActionEvent e)
                {
                    //Execute when button is pressed
                    javax.swing.SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            frame1.setVisible(false);
                            MyClass1.createAndShowGUI();
                        }
                    });
                }
            });      
     
            frame1.getContentPane().add(button);
            frame1.pack();
            frame1.setVisible(true);
        }
     
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  6. #6
    Junior Member r12ki's Avatar
    Join Date
    May 2009
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Linking Database Projects in NetBeans

    Thank you....

    You helped me...

    But, Now, I have another problem. I have made a database in SQL. I don't know how to call it when I press jButton (I named GO).
    I made a simple application using NetBeans, I use a form, some jButton, and Text field.
    Some command such as [ SELECT group FROM dbOwner ] didn't work when I press GO>> button.

    Can you solve this ??

    Thank's for your kindness

  7. #7
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Linking Database Projects in NetBeans

    Hello r12ki,

    To connect to a database and run SQL queries you need to read up on JDBC.

    Java: Java JDBC: JDBC 101: How to connect to an SQL database with Java JDBC.

    If you require more help with this, please start a new thread in our Database forum:

    Database - Java Programming Forums
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Database synchronization from RMS with MySQL in Online mode
    By jeremyraj in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: January 24th, 2011, 08:08 AM
  2. Desktop Database Application
    By TCoomer in forum JDBC & Databases
    Replies: 2
    Last Post: June 4th, 2009, 03:51 PM
  3. [SOLVED] How to link two different class?
    By John in forum Object Oriented Programming
    Replies: 11
    Last Post: April 27th, 2009, 02:57 PM
  4. Are We seriously Ignoring NetBeans?
    By javacrazed in forum Java IDEs
    Replies: 4
    Last Post: November 12th, 2008, 05:08 PM
  5. Website to study Struts framework
    By kirman in forum Java IDEs
    Replies: 2
    Last Post: October 17th, 2008, 07:26 AM