[英]how to send an object JdbcRowSet from server to the client?
//這是服務器:
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());}
// ------------------------------------------------ -----------------------------------
該表可以在服務器中很好地打印,但是客戶端無法接收該對象。
我不確定RowSet實現是否可序列化,但最大套接字不能高於65535。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.