简体   繁体   English

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

[英]Mysql Connector not working for Eclipse Juno on JDK 1.7

I have a Java program which does CRUD on a MySQL database. 我有一个Java程序,可以在MySQL数据库上执行CRUD。

For this, I had been using : 为此,我一直在使用:

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


I tried executing the same code on a new machine with : 我尝试在机器上执行以下代码:

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

I've added the MySql connector to the Build Path of the project in Eclipse Juno. 我已经将MySql连接器添加到Eclipse Juno中的项目的Build Path中。

However, the ant build fails with errors about about missing classes and packages which should be picked up from the connector : 但是,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

Can anyone help me with this? 谁能帮我这个?

Taking a cue from this question : 这个问题中得到启示:

Assuming that you have a compile target in your build.xml which looks similar to 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>

All we need for successful compilation is to define the classpath so that it includes all the jars in the lib directory of the project, like so : 成功编译所需的所有条件是定义类路径,以使其包含项目的lib目录中的所有jar,例如:

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

I understand from your question that you have added a reference to the connector jar inside the Eclipse project. 我从您的问题中了解到,您已经在Eclipse项目中添加了对连接器jar的引用。 You could try the above suggestion after copying the connector jar inside the Eclipse project's lib folder. 将连接器jar复制到Eclipse项目的lib文件夹后,您可以尝试上述建议。

Alternatively, though not a great suggestion in my opinion, you could export the project as an Ant Build and check the build.xml thus generated. 另外,尽管我认为这不是一个很好的建议,但是您可以将项目导出为Ant Build并检查由此生成的build.xml。 This can be done by going to File -> Export, typing 'ant' to filter and then choosing 'Ant Buildfiles', like so : 可以通过转到文件->导出,键入'ant'进行过滤,然后选择'Ant Buildfiles'来完成,如下所示:

导出为Ant BuildFiles

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM