0

サーバーにアクセスするためにeclipse、オブジェクト関連マッピング(ORMLite)を使用してアプリケーションを開発していmysqlます。データレイヤーは、私のjavaAndroid アプリケーションへの参照としてコンパイルおよびバインドされた別のプロジェクトです。

ormlite で使用されるすべての *.jar ファイルを datalayer プロジェクトで参照しました。しかし、アプリケーションを実行すると、次のエラー メッセージが表示されます。

"Could not find class 'com.j256.ormlite.jdbc.JdbcConnectionSource',
     referenced from method
     com.pos.datalayer.querybuilder.DatabaseWorker.connectionSetup"

DatabaseWorker クラスの私のコードは次のとおりです。

public class DatabaseWorker implements DatalayerWorkable {

  private Type tableMapping = null;
  private String actionOnDatabase = null;
  private UserBO persistedUser = null;
  private Type retVal = null;

  public static String hostString = "jdbc:mysql://lucid.selfhost.me/pos";
  private static JdbcConnectionSource connection = null;

  public DatabaseWorker () { };

  public Type loadData(  String databaseAction, final Type tableMap ) {
      actionOnDatabase = databaseAction;
      tableMapping = tableMap;

        Thread workerThread = new Thread(new Runnable(){
            public void run() {
                try {
                    connection = connectionSetup();

                    if(actionOnDatabase == "GetLogin"){
                        retVal = loadUserData(tableMap); 

                  }else if (actionOnDatabase == "loadHotDealz"){

                  }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }finally{
                    if(connection != null){
                        //closeConnection(connection);
                        connection = null;
                    }
                }
            }  
          });
         workerThread.start();

    return retVal;
  }

  public boolean persistData( String databaseAction, Type tableMap ) {
      Thread workerThread = new Thread(new Runnable(){
          public void run(){
          }
      }); 
      return false;
  }

  private JdbcConnectionSource connectionSetup() throws SQLException{
        //set up sql-connection
        JdbcConnectionSource connection = new JdbcConnectionSource(hostString);
        ((JdbcConnectionSource) connection).setUsername("guest");
        ((JdbcConnectionSource) connection).setPassword("ObivanK3nobi");

        return connection;
  }

    private void closeConnection(JdbcConnectionSource openedConnection){
        try{
            if(openedConnection != null){
                openedConnection.close();
            }
        }catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private Type loadUserData(Type tableMapping) throws SQLException{
        Dao<UserBO, String> accountDao = null;

        if(connection != null){
            accountDao = DaoManager.createDao(connection, tableMapping.getClass());
            String currentUser = ((UserBO) tableMapping).getUser();
            //execute query
            persistedUser = accountDao.queryForId(currentUser);

            if(persistedUser != null){
               persistedUser.setIsLoggedin(1);
               accountDao.update(persistedUser);
            }
        }
        return persistedUser;
    }

    public Type getDatabaseResult(){
        return retVal;
    }

    public void databaseObjCallback(Type databaseResult) {
        throw new UnsupportedOperationException("Not implemented yet");
    }

}

私の問題を解決するための助けをいただければ幸いです。

4

1 に答える 1

2

主要なORMLiteクラスが見つからない場合、これはどういうわけかクラスパスの問題だと思います。同じバージョン番号のormlite-coreおよびjar をダウンロードしているはずです。ormlite-jdbc最新バージョンは 4.45 です。

Eclipse では、プロジェクトの下に「参照ライブラリ」フォルダーが表示されるか、Maven を使用している場合は「Maven Dependencies」フォルダーが表示されます。両方の ORMLite jar は、ビルド パスにあることを示すこれら 2 つのフォルダーのいずれかにある必要があります。

プロジェクトを右クリックし、メニューを [ビルド パス] までプルダウンしてから、[ビルド パスの構成] までプルダウンする必要がある場合があります。次に、「ライブラリ」タブをクリックして、両方の ORMLite jar があることを確認します。そうでない場合は、そこに追加する必要があります。

MySQL JDBC コネクタのバージョンに関しては、私はバージョン 5.1.18 を使用していますが、新しいバージョンでも機能すると思います。互換性のないバージョンがそのエラーを引き起こすとは思いません。

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.18</version>
</dependency>

お役に立てれば。

于 2013-04-29T18:40:39.603 に答える