-1
파일 : SelectServerIntf.java :클래스를 찾을 수 없습니다 예외 : com.mysql.jdbc.Driver (RMI 프로그램이 작동하지 않는)
import java.rmi.*;
import java.util.*;
public interface SelectServerIntf extends Remote{
HashMap executeSelect() throws RemoteException;
}
파일 : SelectServerImpl.java :
import java.rmi.*;
import java.sql.*;
import java.rmi.server.*;
import java.util.*;
public class SelectServerImpl extends UnicastRemoteObject implements SelectServerIntf {
public SelectServerImpl() throws RemoteException
{
}
public HashMap executeSelect() throws RemoteException
{
String DRIVER = "com.mysql.jdbc.Driver";
String url ="jdbc:mysql://localhost:3306/abc2";
String Query="select * from student";
Connection con=null;
Statement stat=null;
HashMap hm=null;
try
{
Class.forName(DRIVER);
}
catch(ClassNotFoundException cn)
{
System.out.println("ClassNotFound"+cn);
}
try
{
con= DriverManager.getConnection(url,"root","root");
stat=con.createStatement();
ResultSet rs=stat.executeQuery(Query);
hm=new HashMap();
while(rs.next())
{
int rno=rs.getInt(1);
String name=rs.getString(2);
hm.put(new Integer(rno),name);
}
con.close();
}
catch(SQLException se)
{
System.out.println("SQLException"+se);
}
return(hm);
}
}
파일 : SelectServer.java :
import java.rmi.*;
import java.net.*;
public class SelectServer {
public static void main(String args[])
{
try
{
SelectServerImpl sip=new SelectServerImpl();
Naming.rebind("SELECT-SERVER", sip);
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
}
}
파일 : SelectClient.java : 실행에
import java.rmi.*;
import java.util.*;
import java.net.*;
public class SelectClient {
public static void main(String args[])
{
String rmiurl="rmi://"+args[0]+"/SELECT-SERVER";
try
{
SelectServerIntf sit=(SelectServerIntf)Naming.lookup(rmiurl);
HashMap hm2=sit.executeSelect();
int sz=hm2.size();
for(int i=1;i<sz;i++)
{
if(hm2.containsKey(new Integer(i)))
System.out.println(i+":"+hm2.get(new Integer(i)));
}
}
catch(Exception e)
{
System.out.println("Exception"+e);
}
}
}
RMI의 위의 프로그램이 제공
"Class not found Exception:com.mysql.jdbc.Driver"
SQLException:No Suitable Driver found for jdbc:mysql://localhost:3306/abc2
abc2가 각각의 테이블을 포함하는 내 데이터베이스입니다.
위의 연결 URL과 드라이버는 모든 코드에 대해 올바르게 작동하지만이 rmi를 인식합니다.
전문가가 수정 사항을 찾으십니까 ??
응용 프로그램의 클래스 경로에 mysql jdbc 드라이버 jar 파일이 있습니까? – Thihara
드라이버 jar 파일이 classpath 또는 application/lib에 추가 되었습니까? – VinayVeluri
yess 나는 그것을 추가했다 – user3219417