有关SQLException和RemoteException

时间:2016-05-18 20:52:35

标签: java compiler-errors

我正在使用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;
    } 
}

Screenshot

1 个答案:

答案 0 :(得分:1)

您的代码中有2个拼写错误:

  1. 不是RemoteExeptionRemoteException确实缺少c
  2. 不是preparedStatement而是prepareStatement确实没有d