//这是服务器:
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);
// --------------------------------------------- -----------------------------------
//这是客户:
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());}
// --------------------------------------------- --------------------------------------
表格在服务器中打印得很好,但客户端无法接收到该对象。
答案 0 :(得分:0)
我不确定RowSet实现是否可序列化,但最大套接字不能高于65535。