简体   繁体   English

将 jdbc 驱动程序添加到类路径

[英]Adding jdbc driver to classpath

Ok I am on Win Vista and correctly set my MAVEN_HOME, JAVA_HOME stuff.好的,我在 Win Vista 上并正确设置了我的 MAVEN_HOME、JAVA_HOME 内容。 but I do not have a class path yet.但我还没有课程路径。 I have also installed MySQL.我也安装了 MySQL。 now I have opened a Hibernate book and at the very first pages it says "make sure the jdbc driver is in your classpath" .现在我打开了一本 Hibernate 书,在第一页上写着“确保 jdbc 驱动程序在您的类路径中”。 I have also downloaded some Zip file that is ConnectorJ or some name like that which is basically the mySql driver for java... but my problem for now is this sentence that I have no clue how to do it: "make sure the jdbc driver is in your classpath" would you please help me about this classpath thing?我还下载了一些 Zip 文件,它是 ConnectorJ 或类似的名称,它基本上是 java 的 mySql 驱动程序......但我现在的问题是这句话,我不知道如何去做:“确保 jdbc 驱动程序在你的类路径中”你能帮我解决这个类路径的问题吗?

thanks谢谢

Here is a good tutorial regarding, setting the class path .这是一个关于设置类路径的好教程。 Further you might like to read Managing the Java classpath (Windows) .此外,您可能还想阅读 管理 Java 类路径 (Windows)

Having said that, you should not set the classpath for your driver in Windows environment variable.话虽如此,您不应在 Windows 环境变量中为驱动程序设置类路径。 Instead, you should include that driver jar inside your IDE under project properties.相反,您应该在项目属性下的 IDE 中包含该驱动程序jar But I noticed that you are actually using Maven.但我注意到您实际上正在使用 Maven。 In this case you should look for the driver under Maven in order to fulfil that dependency.在这种情况下,您应该在 Maven 下查找驱动程序以实现该依赖项。 Maven will download the driver jar, if doesn't exist, and make it local. Maven 将下载驱动程序 jar,如果不存在,并将其设为本地。

In case, you are not using any IDE, then you can create a lib directory and tell the compiler that all required jar s are in there, at the time of compilation/execution.如果您没有使用任何 IDE,那么您可以创建一个lib目录并在编译/执行时告诉编译器所有必需的jar都在那里。 You can find HOW, in the former link given above.您可以在上面给出的前一个链接中找到 HOW。

Since you are using Maven, you just need to put the JDBC driver as a dependency in your pom.xml file.由于您使用的是 Maven,您只需要将 JDBC 驱动程序作为依赖项放在 pom.xml 文件中。 Maven will add it to the classpath whenever it compiles/runs your application. Maven 会在编译/运行您的应用程序时将其添加到类路径中。

What you do when deploying your application is dependent on the technologies in use.您在部署应用程序时所做的工作取决于所使用的技术。

  • If it's a command line application create a %CLASSPATH% variable or add the path to the jdbc.jar file using the java -cp {path\\to\\jdbc.jar} option.如果是命令行应用程序,请创建%CLASSPATH%变量或使用java -cp {path\\to\\jdbc.jar}选项将路径添加到 jdbc.jar 文件。

  • If it's a web application, you'll need to package the driver jar in your .war/.ear/.sar (the maven assembly plugin can do this) or include it in the ./lib folder of the application container and declare it as scope=provided in maven.如果是web应用,你需要将驱动jar打包在你的.war/.ear/.sar中(maven程序集插件可以做到这一点)或者将它包含在应用容器的./lib文件夹中并声明它作为范围=在maven中提供。

you can directly connect database by following steps: 1) download mysql-connector-java 5.0.8 and extract the files.您可以通过以下步骤直接连接数据库: 1)下载mysql-connector-java 5.0.8并解压文件。 2) then place the folder in program files. 2)然后将文件夹放在程序文件中。 3) then simply add this library on your project by right clicking on it. 3)然后只需通过右键单击该库将其添加到您的项目中。 4) and here you go. 4) 给你。 Run your app with db connectivity.使用数据库连接运行您的应用程序。

Steps to setup JDBC for Eclipse projects为 Eclipse 项目设置 JDBC 的步骤

  1. Download JDBC zip archive from https://dev.mysql.com/downloads/connector/j/5.0.htmlhttps://dev.mysql.com/downloads/connector/j/5.0.html下载 JDBC zip 存档
  2. Extract the file and copy the executable jar file to program files->Java->jdk->bin解压文件,将可执行jar文件复制到程序文件program files->Java->jdk->bin
  3. Right click on the project and select Buildpath->Add external archives->(Jar file)右键单击项目并选择Buildpath->Add external archives->(Jar file)
  4. Compile the program编译程序

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

相关问题 在Raspberry Pi上的类路径中添加JDBC驱动程序 - Adding JDBC driver to classpath on Raspberry pi JDBC 驱动程序和终端类路径 - JDBC driver and terminal classpath 如何设置JDBC驱动程序类路径 - How to set jdbc driver classpath ClassNotFoundException:com.mysql.jdbc.Driver但它在类路径中 - ClassNotFoundException : com.mysql.jdbc.Driver but it's in the classpath 试图添加数据库驱动程序(JDBC):RmiJdbc.RJDriver - 错误,不在CLASSPATH中? - Trying to add database driver (JDBC): RmiJdbc.RJDriver - Error, not in CLASSPATH? MySQL连接器到JDBC的类路径 - 无法加载驱动程序 - Classpath for MySQL connector to JDBC-can't load the driver java jdbc:sqlite没有合适的驱动程序。 我认为类路径问题 - java jdbc:sqlite no suitable driver. classpath issues i think 通过Maven添加DB2 JDBC驱动程序 - Adding DB2 JDBC Driver via Maven 关于MySQL驱动程序如何使用CLASSPATH? “找不到具有类名com.mysql.jdbc.Driver的驱动程序” - How to use CLASSPATH regarding to mysql drivers? “Could not find driver with class name: com.mysql.jdbc.Driver” 在运行时添加 JDBC 驱动程序 - 引起:java.lang.ClassNotFoundException:com.mysql.jdbc.Driver - Adding JDBC driver at runtime - Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM