10 Replies - 280 Views - Last Post: 10 June 2012 - 12:42 PM Rate Topic: -----

#1 damiencourt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 11-April 11

How to display a database query result on a client machine?

Posted 08 June 2012 - 01:34 AM

Hello,
I have a java client-server application. The server load a SQl table and displays it in a JTable. Works great. I need some help with displaying the same JTable in the client machine. What is the best way to do that? Initially I wanted to send the ResultSet object over the sockets, but I cant do that, right? I read about converting the JTable data into XML, sending it to the client and then populating the JTable with the XML data. I have never dealt with XML though, so if there's any other way to do that can you let me know?

Thank You

Is This A Good Question/Topic? 0
  • +

Replies To: How to display a database query result on a client machine?

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to display a database query result on a client machine?

Posted 08 June 2012 - 03:49 AM

View Postdamiencourt, on 08 June 2012 - 04:34 AM, said:

Hello,
Initially I wanted to send the ResultSet object over the sockets, but I cant do that, right?

Why not ? As the ResultSet is coming from a socket it must be serializable.
Was This Post Helpful? 0
  • +
  • -

#3 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2675
  • View blog
  • Posts: 11,305
  • Joined: 20-September 08

Re: How to display a database query result on a client machine?

Posted 08 June 2012 - 04:10 AM

Make sure your 'master' table uses a DefaultTableModel:

http://technojeeves....t-to-tablemodel

Then you can serialize that model and send it over the wire
Was This Post Helpful? 2
  • +
  • -

#4 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1152
  • View blog
  • Posts: 2,530
  • Joined: 05-May 05

Re: How to display a database query result on a client machine?

Posted 08 June 2012 - 04:17 AM

You can send over anything over the wire with an ObjectOutputStream, but I recommend using XML. Fight the urgency to fallback on using technologies you already know, to secure system extensibility, especially given the amount of libraries that exist. What if you need to support thin clients or adapt your system for SOA? You'll be re-designing. Don't re-design.
Was This Post Helpful? 1
  • +
  • -

#5 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2675
  • View blog
  • Posts: 11,305
  • Joined: 20-September 08

Re: How to display a database query result on a client machine?

Posted 08 June 2012 - 04:25 AM

The only thing about the above is that

a. The TableModel already exists in memory. The xml will have to be created
b. The serialization option is probably going to be thinner, even with compression on the xml
Was This Post Helpful? 1
  • +
  • -

#6 damiencourt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 11-April 11

Re: How to display a database query result on a client machine?

Posted 08 June 2012 - 04:36 AM

@pbl You are actually the first person to say it's serializable. I read through a few forums before posting and they were all saying that it can't be done.

@g00se Yes it does. I use similar code to the one you posted.I always had the impression though, that I should send the
data contained in the swing component, and not the swing component itself.

I'll give both things a try, hope one of them works.
Was This Post Helpful? 0
  • +
  • -

#7 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2675
  • View blog
  • Posts: 11,305
  • Joined: 20-September 08

Re: How to display a database query result on a client machine?

Posted 08 June 2012 - 04:55 AM

Quote

I always had the impression though, that I should send the
data contained in the swing component, and not the swing component itself.


The TableModel is the data
Was This Post Helpful? 0
  • +
  • -

#8 damiencourt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 11-April 11

Re: How to display a database query result on a client machine?

Posted 08 June 2012 - 05:01 AM

View Postg00se, on 08 June 2012 - 04:55 AM, said:

Quote

I always had the impression though, that I should send the
data contained in the swing component, and not the swing component itself.


The TableModel is the data


Sorry, I misunderstood it. Thought you mean the Jtable, not the tableModel.
Was This Post Helpful? 0
  • +
  • -

#9 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1152
  • View blog
  • Posts: 2,530
  • Joined: 05-May 05

Re: How to display a database query result on a client machine?

Posted 08 June 2012 - 05:01 AM

g00se: Sure but I value extensibility over saving a few bits of memory or milliseconds of time, especially in non-mission-critical business systems.
Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to display a database query result on a client machine?

Posted 08 June 2012 - 07:14 PM

View Postdamiencourt, on 08 June 2012 - 07:36 AM, said:

@pbl You are actually the first person to say it's serializable. I read through a few forums before posting and they were all saying that it can't be done.

If the ResultSet itself it not serializable sure that an ArrayList or Vector of Object made out of each of its row will be
Was This Post Helpful? 0
  • +
  • -

#11 damiencourt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 11-April 11

Re: How to display a database query result on a client machine?

Posted 10 June 2012 - 12:42 PM

View Postpbl, on 08 June 2012 - 07:14 PM, said:

View Postdamiencourt, on 08 June 2012 - 07:36 AM, said:

@pbl You are actually the first person to say it's serializable. I read through a few forums before posting and they were all saying that it can't be done.

If the ResultSet itself it not serializable sure that an ArrayList or Vector of Object made out of each of its row will be


Yes,that's another way of doing it. I used g00se's method, though. Sending the tablemodel works great for me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1