mysql
데이터베이스에서 데이터를 가져 오려고합니다. rmi
, 클라이언트가 서버에서 서비스를 요청하고 데이터를 얻기 위해 db에 연결하려고하면 아니오 적합한 드라이버 예외 발생! 또는자바 Rmi 데이터베이스 연결?
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
(구현 클래스) 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;
}
}
(인터페이스) inter.java :
public interface inter extends java.rmi.Remote {
public String getName() throws java.rmi.RemoteException, SQLException;
}
(서버) Server.java :
public Server() throws RemoteException, MalformedURLException {
server_object = new imp();
Naming.rebind("rmi://localhost:1099/myserv", server_object);
}
(클라이언트) client.java :
myobject = (inter) Naming.lookup("rmi://localhost:1099/myserv");
myobject.getName();
내가 클래스 도움의 폴더에 mysqlconnector
라이브러리를 넣어?
'Class.forname'을 사용하십시오. – rpax
클래스 패스에 u가 포함되어 있습니까? 그리고 왜'Class.forName (your_driver) '을 사용하지 않습니까? – maxx777
http://stackoverflow.com/questions/3182282/how-to-install-jdbc-and-how-to-use-it- to-connect-to-mysql 도 이것도 http://stackoverflow.com/questions/2839321/java-connectivity-with-mysql/2840358#2840358 – maxx777