Urgent :problem with JTable on server program

hi all i am writing an internet cafe timer.there is a table with the following colums:PC Name,IP Address,Status,Time Left, Time Login. ,on the server GUI. Whenever a client connects,a new row having the clients details is added to the table model, which reflects on the table.but if a client disconnects and reconnects, i want it to search thru the rows in the model, if there is a row with its information already,it shouls simply update the status column to "Reconnected", and not add an entirly new row, but if there is no row with its information, it can then add a new row with its information.

Simply put, when a client connects,it should check

1)if the table is empty, add a new row;

2)else, check if tabe already has a row for the client, then update the row,else add a new row.

its not working this way.it only works for the first client to connect,if other clients connect and disconnect,it still adds a new row, instaed of updating.

the method doTable() in class ClientThread is what i use .please check it out and help me.

i have a thread for each client.when a client connects, the server starts the thread and passes an instance of the server ui to the thread, so the threads acess the tablemodel thru this instance.

Here is a simple run down of my classes

CafeServer.java

/**

* @(#)CafeServer.java

*

*

* @author obinna

* @version 1.00 2007/3/10

*/

import java.net.*;

import java.io.*;

import java.util.*;

import javax.swing.*;

import java.sql.*;

public class CafeServer {

int serverPort;

int serverLimit;

//ServerSocket serversocket;

private static int rownum = -1;

private static Connection conn;

private static CafeServerUI serverUI;

/**

* Creates a new instance of <code>CafeServer</code>.

*/

public CafeServer() {

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

conn = DriverManager.getConnection("jdbc:odbc:cafetimer","","");

System.out.println("connection established with cafetimer database");

}catch(Exception ex){

JOptionPane.showMessageDialog(null,"Cannot find database");

}

serverUI = new CafeServerUI( this,conn );

}

public void closeServer(){

System.exit(0);

}

public static void main(String[] args) throws IOException{

// TODO code application logic here

try{

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

new CafeServer();

}

catch(Exception ex){

JOptionPane.showMessageDialog(null,"Could Not Find System Look and Feel.\nDefault L&F Loaded.");

JFrame.setDefaultLookAndFeelDecorated(true);

}

ServerSocket serverSocket = null;

boolean listening = true;

try {

serverSocket = new ServerSocket(4444);

} catch (IOException e) {

System.err.println("Could not listen on port: 4444.");

System.exit(-1);

}

while (listening)

new ClientThread(serverSocket.accept(),serverUI,conn).start();

serverSocket.close();

}

}

CafeServerUI.java

//import statements.......................................

public class CafeServerUI extends JFrame{

public Vector pins = new Vector<String>();

public DefaultTableModel model;

public JTable table;

protected JTextArea msgarea;

protected JScrollPane scrpane;

protected JPanel mainp,northp,leftp,rightupp,rightp;

protected String[] colnames = {"Computer Name","IP Ad

.............................................................constrctor follows

ClientThread.java

import java.io.*;

import java.net.*;

import java.sql.*;

public class ClientThread extends Thread{

private Socket socket = null;

private String pin, timeleft, pin3,timeleft3,tleft;

private CafeServerUI csui = null;

private Ticket ticket;

private RemainingTime remtime;

private String hostname,ipadd;

private int rownum;

private Connection conn;

private Statement stmt;

private ResultSet rs;

private boolean found;

public ObjectOutputStream outputStream;

public ObjectInputStream inputStream;

private Admin admin;

boolean found2 = false;

//private String[] newrow = new String[5];

public ClientThread(Socket socket,CafeServerUI csui,Connection conn) {

super("Client Thread");

this.socket = socket;

this.csui = csui;

this.conn = conn;

try{

stmt = this.conn.createStatement();

}catch(Exception ex){

System.out.println(ex.getMessage() + " : " + ex);

}

//this.rownum = rownum;

hostname = this.socket.getInetAddress().getHostName();

ipadd = this.socket.getInetAddress().getHostAddress();

//sString[] newrow = {hostname,ipadd,"Connected","",""};

doTable();

//System.out.print("table row " + this.rownum);

this.csui.oos.addElement(ClientThread.this);

}

public void doTable(){

String[] newrow = {hostname,ipadd,"Connected","",""};

if(this.csui.model.getRowCount() == 0){

this.csui.model.addRow(newrow);

}else{

for(int i=0; i < this.csui.model.getRowCount(); i++ ){

String hname = (String)this.csui.model.getValueAt(i,0);

if(hname.equalsIgnoreCase(hostname)){

this.csui.model.setValueAt("Re Connected",i,2);

break;

}else{

this.csui.model.addRow(newrow);

break;

}

}

}

}

.....public void run()....

[5677 byte] By [java_everywherea] at [2007-11-15]