i need to create a client-server connection (in JAVA), where the server is connected to a database and the client can send queries and get answers.
I use the OCSF (by Dr. Timothy C. Lethbridge) , and JDBC driver for JAVA.
at the server’s side, i have the following code
ResultSetMetaData rsmd=rs.getMetaData();
int numOfCols=rsmd.getColumnCount();
String[] tuple=new String[numOfCols];
Vector result=new Vector();
while (rs.next()){
for (int i=1;i<=numOfCols;i++)
tuple[i-1]=rs.getString(i);
result.addElement(tuple);
isResultEmpty=0;
}
if (isResultEmpty==0)
this.sendToAllClients(result);
else
this.sendToAllClients("No appropriate results!");
so far, it seems to work fine, i made some test-prints if the for loop and it works fine.
for the client side, i have the following code:
public void handleMessageFromServer(Object msg)
{
//clientUI.display(msg.toString());
if (msg instanceof Vector){
Vector result=(Vector)msg;
System.out.println("The result of the query is:\n\n");
//System.out.println((String)result.firstElement());
System.out.println("result size is "+result.size());
for (int i=1;i<=result.size();i++){
System.out.println("here");
System.out.println((String)result.get(i));
System.out.println("here2");
}
}
else
clientUI.display(msg.toString());
}
the problem starts when i try to print the results:
the first “here” is printed, and nothing else happens,
it never gets to the “here2”, and seems to just terminate the printing and waits for new input.
is there any problem with the casting I make?
i just can’t figure out where is the exact problem….
thank you very much in advance for helping
You don’t have a vector of
Stringobjects. You have a vector of string arrays (String[])Edit in response to comments:
This is of course assuming the server side works. I didn’t look at it closely.
Edit for server side:
This is all kinds of broke:
On each loop iteration, you’re simply changing what your string array contains, and adding the same reference over and over. You need: