dear programmers.....
once again i fount trouble in my programme
now i have trouble in get record from database and put one field in combo box.... i did it .. but sir when i use next , or last, or first etc button on my frame como value how comobo value change.. i 'm confuse sir
here is its code
[code]
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
public class SupplyMaterial extends JInternalFrame implements ActionListener
{
Connection con; Statement stmt; PreparedStatement prepstmt; ResultSet rs;
JPanel northPanel,southPanel;
JTextField tfartisan, tfmaterial, tfqty, tficode;
JButton MaterialInsert, MaterialSave, MaterialFirst,MaterialLast,MaterialNext,MaterialPrevious,MaterialOk,MaterialCancel;
GridBagLayout gb; GridBagConstraints gbc;
Container cont;
JComboBox box;
Vector v;
public SupplyMaterial(
String title)
{
super(title, true,true,true);
v= new Vector();
box= new JComboBox(v);
JLabel artisan=new JLabel("Artisan ID");
JLabel material=new JLabel("Material ID");
JLabel qty=new JLabel("Quantity");
JLabel icode=new JLabel("Item ID");
tfartisan=new JTextField(20);
tfmaterial=new JTextField(20);
tfqty=new JTextField(20);
tficode=new JTextField(20);
MaterialInsert=new JButton("Insert");
MaterialSave=new JButton("Save");
MaterialFirst= new JButton("First");
MaterialLast=new JButton("Last");
MaterialNext=new JButton(">>");
MaterialPrevious= new JButton("<<");
MaterialOk=new JButton("Ok");
MaterialCancel=new JButton("Cancel");
gb= new GridBagLayout();
gbc= new GridBagConstraints();
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(artisan,0,0,1,2);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(box,0,1,1,3);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(material,1,0,1,2);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(tfmaterial,1,1,1,3);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(qty,2,0,1,2);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(tfqty,2,1,1,3);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(icode,3,0,1,2);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(tficode,3,1,1,3);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(MaterialFirst,4,0,1,1);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(MaterialLast,4,1,1,1);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(MaterialNext,4,2,1,1);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(MaterialPrevious,4,3,1,1);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(MaterialInsert,5,0,1,1);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(MaterialSave,5,1,1,1);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(MaterialOk,5,2,1,1);
gbc.fill= GridBagConstraints.HORIZONTAL;
addComponents(MaterialCancel,5,3,1,1);
MaterialFirst.addActionListener(this);
MaterialLast.addActionListener(this);
MaterialNext.addActionListener(this);
MaterialPrevious.addActionListener(this);
MaterialInsert.addActionListener(this);
MaterialSave.addActionListener(this);
MaterialCancel.addActionListener(this); MaterialOk.addActionListener(this);
connect();
nextRec();
setSize(300,200);
show();
}
public void addComponents(Component c, int row, int col, int nrow, int ncol)
{
gbc.gridx=col;
gbc.gridy= row;
gbc.gridwidth= ncol;
gbc.gridheight=nrow;
gb.setConstraints(c,gbc);
cont= getContentPane();
cont.setLayout(gb);
cont.add(c);
}
void connect()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con= DriverManager.getConnection("jdbc

dbc:artisan", "sa","aptech");
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery("Select * from SUPPLY_MATERIAL");
while(rs.next())
{
//rs.getString("Artisan_ID"));
v.addElement(rs.getString("Artisan_ID"));
}
prepstmt=con.prepareStatement("Insert into SUPPLY_MATERIAL values (?,?,?,?) ");
}
catch(Exception conec)
{
System.out.println("Connection Error"+conec.getMessage());
}
}
public void firstRec()
{
try
{
if(rs.first())
{
v.get(rs.getString("Artisan_ID"));
//tfartisan.setText(rs.getString("Artisan_ID"));
tfmaterial.setText(rs.getString("Item_ID"));
tficode.setText(rs.getString("Product_ID"));
tfqty.setText(Integer.toString(rs.getInt("Quantity")));
}
}
catch(Exception ex)
{
System.out.println("Error"+ex.getMessage());
}
}
public void lastRec()
{
try
{
if(rs.last())
{
tfartisan.setText(rs.getString("Artisan_ID"));
tfmaterial.setText(rs.getString("Item_ID"));
tficode.setText(rs.getString("Product_ID"));
tfqty.setText(Integer.toString(rs.getInt("Quantity")));
}
}
catch(Exception ex1)
{
System.out.println("Error Last Button "+ex1.getMessage());
}
}
public void nextRec()
{
try
{
if(rs.next())
{
tfartisan.setText(rs.getString("Artisan_ID"));
tfmaterial.setText(rs.getString("Item_ID"));
tficode.setText(rs.getString("Product_ID"));
tfqty.setText(Integer.toString(rs.getInt("Quantity")));
}
else
{
rs.first();
}
}
catch(Exception ex3)
{
System.out.println("Error NExt Record "+ex3.getMessage());
}
}
public void prevRec()
{
try
{
if(rs.previous())
{
tfartisan.setText(rs.getString("Artisan_ID"));
tfmaterial.setText(rs.getString("Item_ID"));
tficode.setText(rs.getString("Product_ID"));
tfqty.setText(Integer.toString(rs.getInt("Quantity")));
}
else
{
rs.first();
}
}
catch(Exception ex4)
{
System.out.println("Error Previous Record "+ex4.getMessage());
}
}
public void insertRec()
{
tfartisan.setText("");
tfmaterial.setText("");
tfqty.setText("");
tficode.setText("");
MaterialSave.setEnabled(true);
}
public void saveRec()
{
try{
prepstmt.setString(1,tfartisan.getText());
prepstmt.setString(2,tfmaterial.getText());
prepstmt.setString(3,tficode.getText());
prepstmt.setInt(4,Integer.parseInt(tfqty.getText()));
prepstmt.executeUpdate();
rs=stmt.executeQuery("Select * from SUPPLY_MATERIAL");
}
catch(Exception prep)
{
System.out.println("Error on Prepared Statment"+prep.getMessage());
}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==MaterialFirst)
{
firstRec();
MaterialPrevious.setEnabled(true);
}
if(ae.getSource()==MaterialLast)
{
lastRec();
MaterialPrevious.setEnabled(true);
}
if(ae.getSource()==MaterialNext)
{
nextRec();
MaterialPrevious.setEnabled(true);
}
if(ae.getSource()==MaterialPrevious)
{
prevRec();
}
if(ae.getSource()==MaterialInsert)
{
insertRec();
}
if(ae.getSource()==MaterialSave)
{
saveRec();
MaterialSave.setEnabled(false);
}
if((ae.getSource()==MaterialCancel) || (ae.getSource()==MaterialOk))
{
dispose();
}
}
}