[英]ResultSet Error java.rmi.UnmarshalException
I am trying to execute the query on server side and send the result to the client but at the time of returning the value to the client the error occurs Am trying to achieve this using RPC Protocol but i could not find out how to send back the resultset from server to client and am using sqlite database 我正在尝试在服务器端执行查询并将结果发送给客户端,但是在将值返回给客户端时发生错误我正在尝试使用RPC协议实现此目的,但是我找不到如何发回从服务器到客户端的结果集,并且正在使用sqlite数据库
Client: 客户:
public class client {
public static void main(String[] args) {
ResultSet rs;
try {
inter Inter = (inter) Naming.lookup("rmi://localhost/collegeDBImpl");
System.out.println("Handle to Server Object Acquired");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("username");
String username=br.readLine();
System.out.println("pass");
String password=br.readLine();
rs=Inter.loginDB(username, password);
} catch (NotBoundException ex) {
Logger.getLogger(client.class.getName()).log(Level.SEVERE, null, ex);
} catch (MalformedURLException ex) {
Logger.getLogger(client.class.getName()).log(Level.SEVERE, null, ex);
} catch (RemoteException ex) {
Logger.getLogger(client.class.getName()).log(Level.SEVERE, null, ex);
}catch(Exception e){
System.out.println(e);
}
}
}
Server: 服务器:
public class server {
public static void main(String[] args) throws Exception {
impl li=new impl();
System.out.println("Server Started");
Naming.rebind("collegeDBImpl",li);
System.out.println("Server Object Registered");
}
}
inter.java 跨java
public interface inter extends Remote{
public ResultSet loginDB(String username, String password)throws RemoteException;
}
impl.java: impl.java:
public class impl extends UnicastRemoteObject implements inter{
Connection conn=null;
ResultSet rs=null;
PreparedStatement pst = null;
impl()throws RemoteException{
conn=javaConnect.ConnecrDb();
}
@Override
public ResultSet loginDB(String username, String password) throws RemoteException {
String sql="Select * from studentDetails where username=? and password=?";
try{
pst=conn.prepareStatement(sql);
pst.setString(1, username);
pst.setString(2, password);
rs=pst.executeQuery();
if(rs.next()){
JOptionPane.showMessageDialog(null, "Username and password is correct");
}else{
JOptionPane.showMessageDialog(null, "Username and password is not correct");
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
return rs;
}
}
ResultSet isn't serializable right? ResultSet不可以序列化吗? So add your results to a serializable DTO and pass that back instead 因此,将结果添加到可序列化的DTO并将其传递回去
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.