Mysql Connector在JDK 1.7上不适用于Eclipse Juno

时间:2012-08-04 11:57:31

标签: java eclipse mysql-connector

我有一个Java程序在MySQL数据库上执行CRUD。

为此,我一直在使用:

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


我尝试在 new 机器上执行相同的代码:

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

我已将MySql连接器添加到Eclipse Juno中项目的Build Path。

然而,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

任何人都可以帮我吗?

1 个答案:

答案 0 :(得分:0)

this 问题中获取提示:

假设你的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并检查由此生成的build.xml。这可以通过转到文件 - &gt;来完成。导出,键入“ant”进行过滤,然后选择“Ant Buildfiles”,如下所示:

Export as Ant BuildFiles