2014-04-10 2 views
0

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 라이브러리를 넣어?

+0

'Class.forname'을 사용하십시오. – rpax

+0

클래스 패스에 u가 포함되어 있습니까? 그리고 왜'Class.forName (your_driver) '을 사용하지 않습니까? – maxx777

+0

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

답변

0

예외 : java.lang.ClassNotFoundException : com.mysql.jdbc.Driver, mysql 커넥터 용 jar 파일을 추가하지 않을 때마다 발생합니다. pls는 당신의 프로젝트 classpath에 mysql connector jar 파일을 추가하고 그것을 실행한다.

편집 : http://code.google.com/p/find-ur-pal/downloads/detail?name=mysql-connector-java-5.1.18-bin.jar& 또는 여기에서 :

당신이 여기에서 다운로드 할 수 있습니다 http://dev.mysql.com/downloads/connector/j/5.0.html

0

추출 mysql_connector jar 파일을 클래스 폴더에있는 세 개의 폴더로. com 폴더, META-INF 폴더 및 org 폴더.