Win a copy of Design for the Mind this week in the Design forum!
    Bookmark Topic Watch Topic
  • New Topic

regarding jdbc

 
usv choudhary
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 48649
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic