• Post Reply Bookmark Topic Watch Topic
  • New Topic

hello javacs...please help me...

 
Sathish Babu Adluru Subas
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi javacs,
iam doing a distributed app.the foll. is my client app code...
public class ClientApplication
{
Socket client = null ;
Socket clientnew = null;
String UserName = null;
String Pwd = null;
Vector vc = null;
public cmsborrower[] cbm = new cmsborrower[5];
ClientThread CThread = null;

public ClientApplication(String mstrUser,String mstrPass)
{
UserName = mstrUser;
Pwd = mstrPass;
vc = new Vector();
vc.addElement(UserName);
vc.addElement(Pwd);
}

public void Connect()
{
try
{
client = new Socket("cil",2001);
CThread = new ClientThread(client,vc);
CThread.start();

}
catch ( SocketException se)
{
System.out.println("Exception in Socket Occured....");
}
catch ( UnknownHostException uhe )
{
System.out.println("Unknown Host....");
}
catch (IOException ex)
{
System.out.println("IO Exception..." + ex.getMessage());
};
}
public void mCommProcess(String sql,int SendReceiveQuit) {
System.out.println("sql = " + sql + " " + SendReceiveQuit);
try
{
CThread.mCommunicate(sql,SendReceiveQuit);
}
catch(Exception e)
{
System.out.println("Thread Exception " + e.getMessage());
}
}
}
class ClientThread extends Thread
{
Socket clientSocket = null;
OutputStream req = null;
ObjectOutput reqobject = null;
InputStream res = null;
ObjectInput resobject = null;
Vector vc = null;
public cmsborrower[] cbm = new cmsborrower[4];
ThreadGroup tGroup = null;
public ClientThread(Socket client,Vector v)
{
this.clientSocket = client;
this.vc = v;
tGroup = new ThreadGroup("ClientGroup");
}
public void run()
{
try
{
System.out.println("UserName:- " + vc.elementAt(0));
System.out.println("Pwd :- " + vc.elementAt(1));
Thread ConThread = new Thread(tGroup,"RunThread");
ConThread.start();
req = clientSocket.getOutputStream();
reqobject = new ObjectOutputStream(req);
res = clientSocket.getInputStream();
resobject = new ObjectInputStream(res);
int errcode = 0;
String servmess = "3400";
reqobject.writeObject(vc);
reqobject.flush();
cbm = (cmsborrower[])resobject.readObject();
ReceiveBorrower borr = new ReceiveBorrower();
borr.cbmrec = cbm;
for(int i=1;i<5;i++)
{
System.out.println("Values :- " + cbm[i].cbm_borrowcode + " | " + cbm[i].cbm_constcode + " | " + cbm[i].cbm_sectorcode);
}
}
catch(ClassNotFoundException ce)
{
System.out.println("Class not found...");
}
catch(IOException ioe)
{
System.out.println("IO Exception..." + ioe.getMessage());
}
}
public void mCommunicate(String sqlQuery,int iSendReceiveQuit)
{
System.out.println("In mCommunicate...");
Thread CommThread = new Thread(tGroup,"CommThread");
CommThread.start();

switch(iSendReceiveQuit)
{
case 1 :
try
{
System.out.println(sqlQuery);
reqobject.writeObject(sqlQuery);
// if ( reqobject == null)
System.out.println("RequestObject is Null");
reqobject.flush();
}
catch (Exception ex)
{
ex.printStackTrace();
System.out.println("IOException :- " + ex.getMessage());
}
break;
case 2 :
/* try
{
cbm = (cmsborrower[])resobject.readObject();
ReceiveBorrower borr = new ReceiveBorrower();
borr.cbmrec = cbm;
for(int i=1;i<cbm.length;++i)>
{
System.out.println("Values :- " + cbm[i].cbm_borrowcode + " | " + cbm[i].cbm_constcode + " | " + cbm[i].cbm_sectorcode);
}
}
catch(ClassNotFoundException ce)
{
System.out.println("Class not found...");
}
catch(IOException e)
{
System.out.println("IO Exception..." + e.getMessage());
} */
break;
case 3 :
mDisConnectFromServer();
break;
default :
break;
}
}
public void mDisConnectFromServer()
{
try
{
reqobject.close();
resobject.close();
clientSocket.close();
}
catch ( IOException ex )
{
System.out.println("I/O Exception Occured..." + ex.getMessage());
}
}
}
its working fine that iam able to logon to the server and iam able to retrieve the info from the Server.In my GUI app,if i wanted to insert the values to my database,i've used the foll. code
...
ClientApplication cilapp = new ClientApplication("shan","shan");
strInsertStmt = "insert into cms_borrower_m (cbm_borrocode,cbm_constcode,cbm_sectorcode,cbm_borrowname) values('TEMP00000023',3,'ERC','Sachin Tendulkar')";

cilapp.mCommProcess(strInsertStmt,1);
...
The prob is that the mCommunicate method of the ClientThread is not being accessed.It shows the NullPointerException in the mCommProcess().
please help me get out of this...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!