0

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?

Mohammad Ashfaq
  • 1,333
  • 2
  • 14
  • 38
Ibrahim
  • 13
  • 2
  • 5
  • have u included driver in your classpath? and why dont you use `Class.forName(your_driver)` – maxx777 Apr 10 '14 at 07:42
  • check this out http://stackoverflow.com/questions/3182282/how-to-install-jdbc-and-how-to-use-it-to-connect-to-mysql and this as well http://stackoverflow.com/questions/2839321/java-connectivity-with-mysql/2840358#2840358 – maxx777 Apr 10 '14 at 07:47
  • Why? The JDBC interface already exists. Why write another one? – user207421 Apr 10 '14 at 10:23
  • Thank you dears, You have not to use Class.forName in mysql_connector 5, Just use DriverManager.getConnection(url,un,ps) – Ibrahim Apr 10 '14 at 16:50

2 Answers2

0

The exception :java.lang.ClassNotFoundException: com.mysql.jdbc.Driver,causes whenever we forget to add jar file for mysql connector. pls add mysql connector jar file to your projects classpath, and run it.

Edited:

you can download it from here : http://code.google.com/p/find-ur-pal/downloads/detail?name=mysql-connector-java-5.1.18-bin.jar& or from here : http://dev.mysql.com/downloads/connector/j/5.0.html

Raju Sharma
  • 2,496
  • 3
  • 23
  • 41
0

Extract mysql_connector jar file into three folders in the classes folder. Like this : com folder, META-INF folder, and org folder.

Ibrahim
  • 13
  • 2
  • 5