Malek Ben el ouafi Malek Ben el ouafi - 6 months ago 29
SQL Question

Java RMI SQLException

I'm working on RMI and SQL programming using ubuntu 15.04. I'm coding the following 3 files: ServerIntf.java , ServerImpl.java, and Server.java

When I compile the ServerImpl file, I get following exceptions: SQLEXception and RemoteException.

How can I compile and execute server please?

error:
Screenshot

This is my code :

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

Answer

There are 2 typos in your code:

  1. It is not RemoteExeption but RemoteException indeed a c is missing
  2. It is not preparedStatement but prepareStatement indeed there is no d