Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4557802
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:33:35+00:00 2026-05-21T17:33:35+00:00

i need to create a client-server connection (in JAVA), where the server is connected

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:33:36+00:00Added an answer on May 21, 2026 at 5:33 pm

    You don’t have a vector of String objects. You have a vector of string arrays (String[])

    Edit in response to comments:

    System.out.println("result size is "+result.size());
    for (int i = 0;i < result.size();i++){
        System.out.println("here");
        String[] array = (String[])result.get(i));
        for (int j = 0; j < array.length; j++)
            System.out.println(array[j]); 
        System.out.println("here2");
    }
    

    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:

    while (rs.next()){
        for (int i=1;i<=numOfCols;i++)
            tuple[i-1]=rs.getString(i);
        result.addElement(tuple);
        isResultEmpty=0;
    }
    

    On each loop iteration, you’re simply changing what your string array contains, and adding the same reference over and over. You need:

    String[] tuple;
    while (rs.next()){
        tuple = new String[numOfCols];
        for (int i=1;i<=numOfCols;i++)
            tuple[i-1]=rs.getString(i);
    
        result.addElement(tuple);
        isResultEmpty=0;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a persistent connection between Java spring server and Android client.
I want to create http socket connection for server in php for multiple client
I'm programming a simple Java NIO server and have a little headache: I get
I need to create a bash script which will connect to an FTP server,
I am building an HTTP client based on the example on HTTP server given
I would like to create a dummy application for connecting my Android phone to
Hi i wanna work with some bluetooth communication using my Android device. How can
I would like to know if someone could provide example or a link on
I posted about this before to a degree, but after a few days of
I'm not quite sure where to start with all of this, but im assuming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.