简体   繁体   中英

how to send an object JdbcRowSet from server to the client?

//This is server:

public class Server {

public static void main(String[] args) {

ServerSocket ser = new ServerSocket(99999);
ObjectOutputStream outToClient = new ObjectOutputStream(sock.getOutputStream());

Socket sock = ser.accept();

JdbcRowSet rowSet = new JdbcRowSetImpl();

rowSet.setUrl("jdbc:mysql://localhost/dbname"); 
rowSet.setUsername(userName); 
rowSet.setPassword(password);
rowSet.setCommand("SELECT * FROM tablename"); 
rowSet.execute(); 
System.out.println("nome \tcognome"); 

while (rowSet.next()) {
System.out.println(rowSet.getString("nome") + "\t" + rowSet.getString("cognome")); }

outToClient.writeObject(rowSet); 

//--------------------------------------------------------------------------------

//This is client:

public class Client{

sock = new Socket("localhost",99999);

inFromServer = new ObjectInputStream(sock.getInputStream());

while(true){

giocatore = (Giocatore)inFromServer.readObject();
System.out.println("nome: " + giocatore.getNome());
System.out.println("cognome: " + giocatore.getCognome());}

//-----------------------------------------------------------------------------------

The table is fine printed in the server, but the client can't received the object.

我不确定RowSet实现是否可序列化,但最大套接字不能高于65535。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM