Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaRMI数据库连接?_Java_Mysql_Rmi - Fatal编程技术网

JavaRMI数据库连接?

JavaRMI数据库连接?,java,mysql,rmi,Java,Mysql,Rmi,我正试图通过rmi从mysql数据库获取数据, 当客户端从服务器请求服务并尝试连接到数据库以获取数据时 没有合适的司机例外上升! 或 (实现类)imp.java: public class imp extends java.rmi.server.UnicastRemoteObject implements inter { ... connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "

我正试图通过
rmi
mysql
数据库获取数据, 当客户端从服务器请求服务并尝试连接到数据库以获取数据时 没有合适的司机例外上升! 或

(实现类)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;
   }
}
public interface inter extends java.rmi.Remote {
    public String getName() throws java.rmi.RemoteException, SQLException;
}
 myobject = (inter) Naming.lookup("rmi://localhost:1099/myserv");
 myobject.getName();
(接口)inter.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;
   }
}
public interface inter extends java.rmi.Remote {
    public String getName() throws java.rmi.RemoteException, SQLException;
}
 myobject = (inter) Naming.lookup("rmi://localhost:1099/myserv");
 myobject.getName();
(服务器)Server.java:

public Server() throws RemoteException, MalformedURLException {
    server_object = new imp();
    Naming.rebind("rmi://localhost:1099/myserv", server_object);
}
(客户端)Client.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;
   }
}
public interface inter extends java.rmi.Remote {
    public String getName() throws java.rmi.RemoteException, SQLException;
}
 myobject = (inter) Naming.lookup("rmi://localhost:1099/myserv");
 myobject.getName();
我将
mysqlconnector
库放在classes文件夹中
有什么帮助吗?

每当我们忘记为mysql连接器添加jar文件时,就会出现异常:java.lang.ClassNotFoundException:com.mysql.jdbc.Driver。请将mysql连接器jar文件添加到您的项目类路径中,并运行它

编辑:


您可以从这里下载:或者从这里下载:

将mysql\u连接器jar文件解压缩到classes文件夹中的三个文件夹中。
如下所示:com文件夹、META-INF文件夹和org文件夹。

您的类路径中是否包含驱动程序?你为什么不使用
Class.forName(你的驱动程序)
看看这个,还有这个为什么?JDBC接口已经存在。为什么还要写另一个呢?亲爱的,谢谢你们,你们不必在mysql_连接器5中使用Class.forName,只需使用DriverManager.getConnection(url、un、ps)