2016-05-18 2 views
0

私は、ubuntu 15.04を使用してRMIとSQLプログラミングを行っています。私は次の3つのファイルをコーディングしています。ServerIntf.java、ServerImpl.java、Server.javaSQLExceptionとRemoteExceptionに関する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

+0

ありませんが、preparedStatementprepareStatementではありません。 – buczek

+0

例外は発生していません。コンパイルエラーが発生しています。 – EJP

答えて

1

あなたのコード内の2つのタイプミスがあります

  1. はそれはではありませんしかしRemoteException確かc
  2. が不足していることは確か代わりに、あなたの質問にテキストをコピーしてくださいのスクリーンショットを含むのないd
+0

応答していただきありがとうございます、私はコードを修正しましたが、まだエラーが残っています。私はスクリーンショットを変更しました。あなたが望めばロックを取ることができます –

+2

@Malek Ben el ouafi IDEを使ってみてください。 –

+0

私は問題を修正しました 'Connection cnx = Connect(); \t \t \tステートメントstmt = cnx.createStatement();\t \t \t文字列sql = "クライアントに値( '+ Integer.toString(cin)+"'、+ "Float.toString(solde)+" ') "を挿入します。 \t \t stmt.executeUpdate(sql); ' –

関連する問題