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
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))
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
Re: Linking Database Projects in NetBeans
:confused:
I have the same problem in it. Can somebody give me an advice or show me where the tutorial is ?
Thanx
:-h
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
Code :
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
Code :
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);
}
}
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
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