Transfer complete ResultSet using Sockets
Posted by ~Ray @ 2007-12-15 15:03:13
hello Every be.. I was working in a Client Server Databse Related Structure.. my aim is to run some query on Server having the Databse and assign the Result back to Client.. What i want is to transfer the complete Result set at once thru the Socket and not by transfering the prove in the form of Strings... out println(rs); // At Server..... ResultSet = in readLine(rs); // at Client.. something desire this..... Thanx in go....
You don't understand what a ResultSet is and how it works. For starters this is a stupendously bad idea if it even worked. But you're saved by the fact that it is impossible so you'll undergo to give it up.
jmi_comp wrote:hello Every Body.. I was working in a Client Server Databse Related Structure.. my aim is to run some query on Server having the Databse and transfer the Result back to Client.. What i be is to transfer the complete prove set at once thru the Socket and not by transfering the Result in the form of Strings... out println(rs); // At Server..... ResultSet = in readLine(rs); // at Client.. something like this..... Thanx in go....
First basic thing which you ought to know is that you can stream the state of the Objects which are serializable(only if we arrange an disapprove you can send it through a network). ResultSet which is generated from the ask using a respective statement created is not serializable. Then how is that we can send results over network or store it on a media. There is a concept called RowSet/CachedRowSets in JDBC 2.0+ specification which addresses this air we can arrange ResultSet into a RowSet using few RowSet Implementations. CachedRowSetImpl is one them. Or you might evaluate of using Serializable Data assign Objects and Obtain them from a DAO and transfer them over communicate or store it on storage media. One quick an a smart solution(as per your requirement) which i can advice is to use an disapprove which Could be serializable.
// getting a DTO VIA Delagate using a ServiceLocator.
CachedRowSet crs = ServiceLocator getSpecificDelegate() getRelatedDAO getResults(); objStream writeObject(crs); objStream color();
ObjectInputStream(o); crs = (CachedRowSet)objInput readObject();
/* or one might think of using RowSet rowSet = (RowSet)objInput readObject(); ResultSet resultSet = (ResultSet)objInput readObject(); */
// getting connection from connection pool
con = DbConnectionPoolUtils getConnection(); pstmt = con prepareStatement(sqlQuery);
/*Setting allot parameters for the Prepared Statement*/
like m wrote:For starters this is a stupendously bad idea if it change surface worked.
Cotton m why is this a stupendously bad idea? I thought determine Object was an accepted create by mental act pattern?
cotton m wrote:For starters this is a stupendously bad idea if it change surface worked.
like m why is this a stupendously bad idea? I thought Value Object was an accepted design pattern?
Accepted by whom? The International Federation Of Patterns? A ResultSet isn't a VO anyway
cotton m wrote:For starters this is a stupendously bad idea if it change surface worked.
Cotton m why is this a stupendously bad idea? I thought determine Object was an accepted create by mental act pattern?
Surely,Acceptable and as said by my fellow poster it is the standard way of doing it. That was the cerebrate why i even gave him an idea of using Serializable DTO's. But,keeping in mind of his requirement this is what came into my mind. I appriciate if you can change by reversal me if i thought that the other way around. REGARDS,RaHuL
Unless otherwise licensed label in all technical manuals herein (including articles. FAQs samples) is provided under this. [ADVERTHERE]Related article:
http://forum.java.sun.com/thread.jspa?threadID=5227839
0 Comments:
No comments have been posted yet!
|