我正在使用ubuntu 15.04进行RMI和SQL编程。我编写了以下3个文件:ServerIntf.java,ServerImpl.java和Server.java
当我编译ServerImpl文件时,我得到以下异常:SQLEXception和RemoteException。
我该如何编译和执行服务器?
错误: Screenshot
这是我的代码:
import java.rmi.*;
import java.rmi.server.*;
import java.sql.*;
public class ServerImpl extends UnicastRemoteObject implements ServerIntf {
public ServerImpl() throws RemoteExeption{ }
public Connection Connect () throws RemoteExeption{
String url = "jdbc:mysql://localhost/banque";
String name = "root";
String pass = "root";
String driver = "com.mysql.jdbc.Driver";
try {
Class.forName(driver).newInstance();
Connection cn = DriverManager.getConnection(url,name,pass);
return cn;
}catch(SQLException ex){
System.out.println(ex.getMessage());
return null;
}
catch(Exception e){
return null;
}
}
public String AddC(int cin , float solde) throws RemoteExeption{
String res = " Ajout avec succse";
try{
Connection cnx = Connect();
PreparedStatement ins = cnx.preparedStatement("insert into clients values(?,?)");
ins.setString(1,Integer.toString(cin));
ins.setString(2,Float.toString(solde));
ins.executeUpdate();
}catch(SQLException ex){
System.out.println(ex.getMessage());
return null;
}
catch(Exception e){
return null;
}
return res;
}
}
答案 0 :(得分:1)
您的代码中有2个拼写错误:
RemoteExeption
,RemoteException
确实缺少c
preparedStatement
而是prepareStatement
确实没有d