I am trying to get data from mysql
database by rmi
,
When the client request the service from the server and trying to connect to db to get data
NO Suitable driver Exception rise !
or
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
(Implementation Class)imp.java:
public class imp extends java.rmi.server.UnicastRemoteObject implements inter {
...
connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "root");
public String getName() throws java.rmi.RemoteException {
String name = "none";
try {
PreparedStatement ps = con.prepareStatement("select ....");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
name = rs.getString("f_name");
}
} catch (SQLException ex) {
ex.printStackTrace();
}
return name;
}
}
(Interface)inter.java:
public interface inter extends java.rmi.Remote {
public String getName() throws java.rmi.RemoteException, SQLException;
}
(Server)Server.java:
public Server() throws RemoteException, MalformedURLException {
server_object = new imp();
Naming.rebind("rmi://localhost:1099/myserv", server_object);
}
(Client) client.java:
myobject = (inter) Naming.lookup("rmi://localhost:1099/myserv");
myobject.getName();
I Put the mysqlconnector
library in the folder of classes
Any Help?