This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes regarding jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Reply locked New topic
Author

regarding jdbc

usv choudhary
Greenhorn

Joined: Oct 23, 2008
Posts: 4
i am working on swing and awt concepts of java
i have created a jtable which retrieved data from mysql database

now i want this jtable class file to load when i click on the previous java file Jbutton
in a supply chain system
say a supplier login to his home page then after to his to view the status he click on the get status button which retrieves data from the database(mysql)but on clicking on this Jbutton my program automatically ends that is the supplier cannot view the status
i am preparing this project code:

here is the coding of supplier
/*import javax.swing.*;
import java.awt.event.*;

public class Supplier extends JFrame implements ActionListener{

private JTextArea jTextArea1;
private JButton ok;
private JTextPane jTextPane1;
private JLabel jLabel1;
private JButton getstatus;




public Supplier()
{
initComponents ();

}


private void initComponents() {

JPanel panel=new JPanel();


jTextArea1 = new JTextArea();
ok = new JButton();
getstatus=new JButton();

jLabel1=new JLabel();

panel.setLayout(null);
setName("SUPPLIER Home Page");
setTitle("SUPPLIER Home Page");
panel.setForeground(java.awt.Color.lightGray);


panel.setBackground(new java.awt.Color (0, 0, 64));


jTextArea1.setLineWrap(true);
jTextArea1.setBorder(new javax.swing.border.SoftBevelBorder(0));
jTextArea1.setEditable(false);
jTextArea1.setColumns(1);
jTextArea1.setRows(2);
jTextArea1.setForeground(java.awt.Color.lightGray);
jTextArea1.setFont(new java.awt.Font ("Times New Roman", 1, 14));
jTextArea1.setText("Supplier supply raw materials to the producer. The main raw material will be EN-8 Rod ");


jTextArea1.setBackground(new java.awt.Color (0, 0, 64));
jTextArea1.setBounds(190, 100, 294, 140);//may be axis
panel.add(jTextArea1);




ok.setText("Ok");

ok.setLocation(400, 280);
ok.setSize(ok.getPreferredSize());
panel.add(ok);
ok.addActionListener(this);

getstatus.setText("getstatus");
getstatus.setLocation(500,280);
getstatus.setSize(getstatus.getPreferredSize());
panel.add(getstatus);

getstatus.addActionListener(this);



jLabel1.setBorder(new javax.swing.border.LineBorder(java.awt.Color.black, 4));
jLabel1.setName("lblTitle");
jLabel1.setText("SUPPLY CHAIN SYSTEM");
jLabel1.setForeground(java.awt.Color.white);
jLabel1.setBackground(new java.awt.Color (0, 0, 64));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setFont(new java.awt.Font ("Helvetica", 1, 18));
jLabel1.setBounds(80, 30, 340, 40);

panel.add(jLabel1);

getContentPane().add(panel);
setVisible(true);
setSize(575,475);


}
public static void main (String args[]) {
new Supplier ();
}

public void actionPerformed(ActionEvent e)
{

JButton button= (JButton)e.getSource();

if(button.equals(ok))
{

new FrontPage();
this.dispose();

}

else
{
new database();
this.dispose();
}



}


}
*/
here on clicking getstatus jbutton must open the database java file
but it does not shows it automatically ends
here is the coding for database file
/*import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;


public class database{
public static void main(String[] args) {
// System.out.println("Getting All Rows from a table!");
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "ravic";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "tushar";
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db, user, pass);
try{
Statement st = con.createStatement();
ResultSet result = st.executeQuery("SELECT * FROM employee1");
// while (result.next()) {
ResultSetMetaData md = result.getMetaData();
int columnCount = md.getColumnCount();

Vector columns = new Vector(columnCount);

//store column names
for(int i=1; i<=columnCount; i++)
columns.add(md.getColumnName(i));

Vector data = new Vector();
Vector row;

//store row data
while(result.next())
{
row = new Vector(columnCount);
for(int i=1; i<=columnCount; i++)
{
row.add(result.getString(i));
}
data.add(row);
}
JTable table = new JTable(data,columns);

//String col[] = {"Name","Course","Grade"};
JFrame frame = new JFrame("Creating JTable Component Example!");
JPanel panel = new JPanel();

panel.add(table,BorderLayout.CENTER);

frame.add(panel);
frame.setSize(300,200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//}
con.close();
}
catch (SQLException s){
System.out.println("SQL code does not execute.");
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
*/
so please help me in this regard
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Is this a continuation of the discussion here? Please don't post the same question twice.

Scott or Jeanne might close this thread.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

I'm going to close this because it looks the same. One tip - try removing code until you have the smallest piece needed to reproduce the problem. People aren't likely to sift through 6 screens of code to figure out what is wrong.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regarding jdbc
 
Similar Threads
regarding jdbc
regarding JTable
JTable
JTable ........
Updating values in a jTable