0

MySQL データベースで CRUD を実行する Java プログラムがあります。

このために、私は使用していました:

Eclipse Indigo
Java 1.6
MySql-Connector-java-5.1.19-bin.jar


新しいマシンで 同じコードを実行しようとしました:

Eclipse Juno
Java 1.7
MySql-Connector-java-5.1.19-bin.jar. 

Eclipse Juno のプロジェクトのビルド パスに MySql コネクタを追加しました。

ただし、ant ビルドは、コネクタから取得する必要がある欠落しているクラスとパッケージに関するエラーで失敗します。

Buildfile: /home/rudra/Softwares/openfire/openfire_src/build/build.xml
init:
compile:
[javac] Compiling 14 source files to /home/rudra/Softwares/openfire/openfire_src/work/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.5
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:3: error: package com.mysql.jdbc does not exist
[javac] import com.mysql.jdbc.Connection;
[javac]                      ^
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:4: error: package com.mysql.jdbc does not exist
[javac] import com.mysql.jdbc.PreparedStatement;
[javac]                      ^
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:5: error: package com.mysql.jdbc does not exist
[javac] import com.mysql.jdbc.ResultSet;
[javac]                      ^
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:21: error: cannot find symbol
[javac]             PreparedStatement stat = (PreparedStatement)connect.prepareStatement(query2);
[javac]             ^
[javac]   symbol:   class PreparedStatement
[javac]   location: class UserDB
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:21: error: cannot find symbol
[javac]             PreparedStatement stat = (PreparedStatement)connect.prepareStatement(query2);
[javac]                                       ^
[javac]   symbol:   class PreparedStatement
[javac]   location: class UserDB
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:21: error: cannot find symbol
[javac]             PreparedStatement stat = (PreparedStatement)connect.prepareStatement(query2);
[javac]                                                                ^
[javac]   symbol:   method prepareStatement(String)
[javac]   location: variable connect of type Connection
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:23: error: cannot find symbol
[javac]             ResultSet result = (ResultSet) stat.executeQuery();
[javac]             ^
[javac]   symbol:   class ResultSet
[javac]   location: class UserDB
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:23: error: cannot find symbol
[javac]             ResultSet result = (ResultSet) stat.executeQuery();
[javac]                                 ^
[javac]   symbol:   class ResultSet
[javac]   location: class UserDB
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:28: error: cannot find symbol
[javac]                 PreparedStatement preparedStmt = (PreparedStatement) connect.prepareStatement(query);
[javac]                 ^
[javac]   symbol:   class PreparedStatement
[javac]   location: class UserDB
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:28: error: cannot find symbol
[javac]                 PreparedStatement preparedStmt = (PreparedStatement) connect.prepareStatement(query);
[javac]                                                   ^
[javac]   symbol:   class PreparedStatement
[javac]   location: class UserDB
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:28: error: cannot find symbol
[javac]                 PreparedStatement preparedStmt = (PreparedStatement) connect.prepareStatement(query);
[javac]                                                                             ^
[javac]   symbol:   method prepareStatement(String)
[javac]   location: variable connect of type Connection
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:41: error: cannot find symbol
[javac]                 PreparedStatement statement = (PreparedStatement) connect.prepareStatement("Insert into user values (?,?,?);");
[javac]                 ^
[javac]   symbol:   class PreparedStatement
[javac]   location: class UserDB
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:41: error: cannot find symbol
[javac]                 PreparedStatement statement = (PreparedStatement) connect.prepareStatement("Insert into user values (?,?,?);");
[javac]                                                ^
[javac]   symbol:   class PreparedStatement
[javac]   location: class UserDB
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:41: error: cannot find symbol
[javac]                 PreparedStatement statement = (PreparedStatement) connect.prepareStatement("Insert into user values (?,?,?);");
[javac]                                                                          ^
[javac]   symbol:   method prepareStatement(String)
[javac]   location: variable connect of type Connection
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:73: error: cannot find symbol
[javac]             PreparedStatement statement = (PreparedStatement) connect.prepareStatement(query);
[javac]             ^
[javac]   symbol:   class PreparedStatement
[javac]   location: class UserDB
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:73: error: cannot find symbol
[javac]             PreparedStatement statement = (PreparedStatement) connect.prepareStatement(query);
[javac]                                            ^
[javac]   symbol:   class PreparedStatement
[javac]   location: class UserDB
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:73: error: cannot find symbol
[javac]             PreparedStatement statement = (PreparedStatement) connect.prepareStatement(query);
[javac]                                                                      ^
[javac]   symbol:   method prepareStatement(String)
[javac]   location: variable connect of type Connection
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:75: error: cannot find symbol
[javac]             ResultSet result = (ResultSet) statement.executeQuery();
[javac]             ^
[javac]   symbol:   class ResultSet
[javac]   location: class UserDB
[javac] /home/rudra/Softwares/openfire/openfire_src/src/java/org/jivesoftware/openfire/UserDB.java:75: error: cannot find symbol
[javac]             ResultSet result = (ResultSet) statement.executeQuery();
[javac]                                 ^
[javac]   symbol:   class ResultSet
[javac]   location: class UserDB

誰でもこれで私を助けることができますか?

4

1 に答える 1

0

この質問からヒントを得て:

build.xml に次のようなコンパイル ターゲットがあるとします。

<!-- Compile application -->
  <target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${src.dir}" destdir="${classes.dir}" debug="yes" includeantruntime="false">
      <classpath refid="classpath" />
    </javac>
  </target>

コンパイルを成功させるために必要なのは、次のように、プロジェクトの lib ディレクトリにすべての jar が含まれるようにクラスパスを定義することだけです。

  <path id="classpath">
    <fileset dir="${lib.dir}" includes="*.jar"/>
  </path>

あなたの質問から、Eclipse プロジェクト内のコネクタ jar への参照を追加したことがわかりました。Eclipse プロジェクトの lib フォルダー内にコネクター jar をコピーした、上記の提案を試すことができます。

または、私の意見では素晴らしい提案ではありませんが、プロジェクトを Ant ビルドとしてエクスポートし、生​​成された build.xml を確認することもできます。これを行うには、[ファイル] -> [エクスポート] に移動し、「ant」と入力してフィルター処理し、[Ant Buildfiles] を選択します。次のようにします。

Ant BuildFiles としてエクスポート

于 2012-08-04T13:01:14.340 に答える